Merge pull request #1086 from lbryio/add-conf-flag-to-cli

fixes for the --conf flag
This commit is contained in:
Alex Grin 2018-02-12 17:01:43 -05:00 committed by GitHub
commit d6819d8091
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 9 deletions

View file

@ -59,6 +59,7 @@ at anytime.
* Added abandon information (claim name, id, address, amount, balance_delta and nout) about claims, supports, and updates to `transaction_list` results under `abandon_info` key * Added abandon information (claim name, id, address, amount, balance_delta and nout) about claims, supports, and updates to `transaction_list` results under `abandon_info` key
* Added `permanent_url` attribute to `channel_list_mine`, `claim_list`, `claim_show`, `resolve` and `resolve_name` API calls through lbryio/lbryum#203 * Added `permanent_url` attribute to `channel_list_mine`, `claim_list`, `claim_show`, `resolve` and `resolve_name` API calls through lbryio/lbryum#203
* *
* Added `--conf` CLI flag to lbrynet-cli tool to specify an alternative config file
### Changed ### Changed
* claim_show API command no longer takes name as argument * claim_show API command no longer takes name as argument

View file

@ -509,6 +509,10 @@ class Config(object):
converted[k] = v converted[k] = v
return converted return converted
def initialize_post_conf_load(self):
settings.installation_id = settings.get_installation_id()
settings.node_id = settings.get_node_id()
def load_conf_file_settings(self): def load_conf_file_settings(self):
if conf_file: if conf_file:
path = conf_file path = conf_file
@ -528,6 +532,9 @@ class Config(object):
except (IOError, OSError) as err: except (IOError, OSError) as err:
log.info('%s: Failed to update settings from %s', err, path) log.info('%s: Failed to update settings from %s', err, path)
#initialize members depending on config file
self.initialize_post_conf_load()
def _fix_old_conf_file_settings(self, settings_dict): def _fix_old_conf_file_settings(self, settings_dict):
if 'API_INTERFACE' in settings_dict: if 'API_INTERFACE' in settings_dict:
settings_dict['api_host'] = settings_dict['API_INTERFACE'] settings_dict['api_host'] = settings_dict['API_INTERFACE']
@ -628,7 +635,5 @@ def initialize_settings(load_conf_file=True):
if settings is None: if settings is None:
settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS, settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS,
environment=get_default_env()) environment=get_default_env())
settings.installation_id = settings.get_installation_id()
settings.node_id = settings.get_node_id()
if load_conf_file: if load_conf_file:
settings.load_conf_file_settings() settings.load_conf_file_settings()

View file

@ -38,8 +38,22 @@ def set_flag_vals(flag_names, parsed_args):
def main(): def main():
if len(sys.argv[1:]): argv = sys.argv[1:]
method, args = sys.argv[1], sys.argv[2:]
# check if a config file has been specified. If so, shift
# all the arguments so that the parsing can continue without
# noticing
if len(argv) and argv[0] == "--conf":
if len(argv) < 2:
print_error("No config file specified for --conf option")
print_help()
return
conf.conf_file = argv[1]
argv = argv[2:]
if len(argv):
method, args = argv[0], argv[1:]
else: else:
print_help() print_help()
return return
@ -176,13 +190,14 @@ def print_help():
" lbrynet-cli - LBRY command line client.", " lbrynet-cli - LBRY command line client.",
"", "",
"USAGE", "USAGE",
" lbrynet-cli <command> [<args>]", " lbrynet-cli [--conf <config file>] <command> [<args>]",
"", "",
"EXAMPLES", "EXAMPLES",
" lbrynet-cli commands # list available commands", " lbrynet-cli commands # list available commands",
" lbrynet-cli status # get daemon status", " lbrynet-cli status # get daemon status",
" lbrynet-cli resolve_name what # resolve a name", " lbrynet-cli --conf ~/l1.conf status # like above but using ~/l1.conf as config file",
" lbrynet-cli help resolve_name # get help for a command", " lbrynet-cli resolve_name what # resolve a name",
" lbrynet-cli help resolve_name # get help for a command",
]) ])