From 7309bd2282445f6daef0b1491ff60b8104500abb Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 19 Jan 2022 18:47:44 -0800 Subject: [PATCH] add get_help --- jc/lib.py | 15 ++++++++++++--- jc/parsers/csv.py | 4 ++-- jc/parsers/universal.py | 10 +++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/jc/lib.py b/jc/lib.py index e34c8248..24e6cece 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -100,6 +100,7 @@ parsers = [ # Create the local_parsers list. This is a list of custom or # override parsers from /jc/jcparsers/*.py. +# Once this list is created, extend the parsers list with it. local_parsers = [] data_dir = appdirs.user_data_dir('jc', 'jc') local_parsers_dir = os.path.join(data_dir, 'jcparsers') @@ -122,6 +123,12 @@ def _modname_to_cliname(parser_mod_name): """Return module's cli name (underscores converted to dashes)""" return parser_mod_name.replace('_', '-') +def _get_parser(parser_mod_name): + """Return the parser module object""" + parser_cli_name = _modname_to_cliname(parser_mod_name) + modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.' + return importlib.import_module(f'{modpath}{parser_mod_name}') + def parse(parser_mod_name, data, quiet=False, raw=False, ignore_exceptions=None, **kwargs): """ @@ -177,9 +184,7 @@ def parse(parser_mod_name, data, Standard Parsers: Dictionary or List of Dictionaries Streaming Parsers: Generator Object """ - parser_cli_name = _modname_to_cliname(parser_mod_name) - modpath = 'jcparsers.' if parser_cli_name in local_parsers else 'jc.parsers.' - jc_parser = importlib.import_module(f'{modpath}{parser_mod_name}') + jc_parser = _get_parser(parser_mod_name) if ignore_exceptions is not None: return jc_parser.parse(data, quiet=quiet, raw=raw, @@ -194,3 +199,7 @@ def parser_mod_list(): def plugin_parser_mod_list(): """Returns a list of plugin parser module names.""" return [_cliname_to_modname(p) for p in local_parsers] + +def get_help(parser_mod_name): + """Show help screen for the selected parser""" + help(_get_parser(parser_mod_name)) diff --git a/jc/parsers/csv.py b/jc/parsers/csv.py index 154d6b45..cd98d6fb 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -1,8 +1,8 @@ """jc - JSON CLI output utility `csv` file parser The `csv` parser will attempt to automatically detect the delimiter -character. If the delimiter cannot be detected it will default to comma. The -first row of the file must be a header row. +character. If the delimiter cannot be detected it will default to comma. +The first row of the file must be a header row. Usage (cli): diff --git a/jc/parsers/universal.py b/jc/parsers/universal.py index a5a4df4e..3b5a0199 100644 --- a/jc/parsers/universal.py +++ b/jc/parsers/universal.py @@ -50,11 +50,11 @@ def sparse_table_parse(data, delim='\u2063'): Also, ensure there are no blank lines (list items) in the data. - delim: (string) Delimiter to use. By default 'u\2063' (invisible - separator) is used since this is unlikely to ever - be seen in terminal output. You can change this for - troubleshooting purposes or if there is a delimiter - conflict with your data. + delim: (string) Delimiter to use. By default `u\\2063` + (invisible separator) is used since this is + to ever be seen in terminal output. You can change + this for troubleshooting purposes or if there is a + delimiter conflict with your data. Returns: