Plugins call with cmd_only:
- pass temporary config to Plugins - load only enabled plugins - parse the command line again after plugins are loaded
This commit is contained in:
25
run_electrum
25
run_electrum
@@ -103,7 +103,7 @@ from electrum.storage import WalletStorage
|
||||
from electrum.util import print_msg, print_stderr, json_encode, json_decode, UserCancelled
|
||||
from electrum.util import InvalidPassword
|
||||
from electrum.plugin import Plugins
|
||||
from electrum.commands import get_parser, known_commands, Commands, config_variables, remove_disabled_plugin_commands
|
||||
from electrum.commands import get_parser, known_commands, Commands, config_variables
|
||||
from electrum import daemon
|
||||
from electrum import keystore
|
||||
from electrum.util import create_and_start_event_loop, UserFacingException, JsonRPCError
|
||||
@@ -340,8 +340,6 @@ def main():
|
||||
sys.argv[i] = input("Enter argument:")
|
||||
elif arg == ':':
|
||||
sys.argv[i] = prompt_password('Enter argument (will not echo):', confirm=False)
|
||||
# load (only) the commands modules of plugins so their commands are registered
|
||||
plugin_commands = Plugins(cmd_only=True)
|
||||
|
||||
# config is an object passed to the various constructors (wallet, interface, gui)
|
||||
if is_android:
|
||||
@@ -360,15 +358,23 @@ def main():
|
||||
# ~hack for easier regtest builds. pkgname subject to change.
|
||||
config_options['regtest'] = True
|
||||
else:
|
||||
# save sys args for next parser
|
||||
saved_sys_argv = sys.argv[:]
|
||||
# disable help, the next parser will display it
|
||||
if '-h' in sys.argv:
|
||||
sys.argv.remove('-h')
|
||||
# parse first without plugins
|
||||
config_options = parse_command_line()
|
||||
tmp_config = SimpleConfig(config_options)
|
||||
# load (only) the commands modules of plugins so their commands are registered
|
||||
plugin_commands = Plugins(tmp_config, cmd_only=True)
|
||||
# re-parse command line
|
||||
sys.argv = saved_sys_argv[:]
|
||||
config_options = parse_command_line()
|
||||
|
||||
config = SimpleConfig(config_options)
|
||||
cmdname = config.get('cmd')
|
||||
|
||||
# now that we know which plugins are enabled we can remove commands of disabled plugins again
|
||||
# enabled plugins depend on the datadir which is parsed by argparse, so they can only be unloaded afterwards
|
||||
remove_disabled_plugin_commands(config, plugin_commands.loaded_command_modules)
|
||||
|
||||
# set language as early as possible
|
||||
# Note: we are already too late for strings that are declared in the global scope
|
||||
# of an already imported module. However, the GUI and the plugins at least have
|
||||
@@ -500,10 +506,7 @@ def handle_cmd(*, cmdname: str, config: 'SimpleConfig', config_options: dict):
|
||||
else:
|
||||
# command line
|
||||
configure_logging(config, log_to_file=False) # don't spam logfiles for each client-side RPC, but support "-v"
|
||||
cmd = known_commands.get(cmdname)
|
||||
if not cmd:
|
||||
print_stderr("unknown command:", cmdname)
|
||||
sys_exit(1)
|
||||
cmd = known_commands[cmdname]
|
||||
wallet_path = config.get_wallet_path()
|
||||
if not config.NETWORK_OFFLINE:
|
||||
init_cmdline(config_options, wallet_path, rpcserver=True, config=config)
|
||||
|
||||
Reference in New Issue
Block a user