Merge pull request #9906 from spesmilo/maybe_complete_wallet_path
CLI: complete wallet_path
This commit is contained in:
@@ -163,14 +163,13 @@ def command(s):
|
||||
password = kwargs.get('password')
|
||||
daemon = cmd_runner.daemon
|
||||
if daemon:
|
||||
if 'wallet_path' in cmd.options and kwargs.get('wallet_path') is None:
|
||||
kwargs['wallet_path'] = daemon.config.get_wallet_path()
|
||||
if cmd.requires_wallet and kwargs.get('wallet') is None:
|
||||
kwargs['wallet'] = daemon.config.get_wallet_path()
|
||||
if 'wallet_path' in cmd.options or cmd.requires_wallet:
|
||||
kwargs['wallet_path'] = daemon.config.maybe_complete_wallet_path(kwargs.get('wallet_path'))
|
||||
if 'wallet' in cmd.options:
|
||||
wallet = kwargs.get('wallet', None)
|
||||
if isinstance(wallet, str):
|
||||
wallet = daemon.get_wallet(wallet)
|
||||
wallet_path = kwargs.pop('wallet_path', None) # unit tests may set wallet and not wallet_path
|
||||
wallet = kwargs.get('wallet', None) # run_offline_command sets both
|
||||
if wallet is None:
|
||||
wallet = daemon.get_wallet(wallet_path)
|
||||
if wallet is None:
|
||||
raise UserFacingException('wallet not loaded')
|
||||
kwargs['wallet'] = wallet
|
||||
|
||||
@@ -367,10 +367,7 @@ class CommandsServer(AuthenticatedServer):
|
||||
wallet_path = config_options.get('wallet_path')
|
||||
if len(self.daemon._wallets) > 1 and wallet_path is None:
|
||||
raise UserFacingException("error: wallet not specified")
|
||||
if 'wallet_path' in cmd.options:
|
||||
kwargs['wallet_path'] = wallet_path
|
||||
else:
|
||||
kwargs['wallet'] = wallet_path
|
||||
kwargs['wallet_path'] = wallet_path
|
||||
func = getattr(self.cmd_runner, cmd.name)
|
||||
# execute requested command now. note: cmd can raise, the caller (self.handle) will wrap it.
|
||||
result = await func(*args, **kwargs)
|
||||
|
||||
@@ -458,11 +458,20 @@ class SimpleConfig(Logger):
|
||||
else:
|
||||
return self.WALLET_BACKUP_DIRECTORY
|
||||
|
||||
def maybe_complete_wallet_path(self, path: Optional[str]) -> str:
|
||||
return self._complete_wallet_path(path) if path is not None else self.get_wallet_path()
|
||||
|
||||
def _complete_wallet_path(self, path: str) -> str:
|
||||
""" add user wallets directory if needed """
|
||||
if os.path.split(path)[0] == '':
|
||||
path = os.path.join(self.get_datadir_wallet_path(), path)
|
||||
return path
|
||||
|
||||
def get_wallet_path(self) -> str:
|
||||
"""Returns the wallet path."""
|
||||
# command line -w option
|
||||
if self.get('wallet_path'):
|
||||
return os.path.join(self.get('cwd', ''), self.get('wallet_path'))
|
||||
if path:= self.get('wallet_path'):
|
||||
return self._complete_wallet_path(path)
|
||||
# current wallet
|
||||
path = self.CURRENT_WALLET
|
||||
if path and os.path.exists(path):
|
||||
|
||||
Reference in New Issue
Block a user