From b4575a3f780f9aa2751c8b4789f67aaca32dd1cb Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Wed, 19 Jan 2022 22:20:36 -0800 Subject: [PATCH] add lib docs --- docgen.sh | 4 +++ docs/lib.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++ jc/lib.py | 2 +- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 docs/lib.md diff --git a/docgen.sh b/docgen.sh index 3b100ae3..54f64aad 100755 --- a/docgen.sh +++ b/docgen.sh @@ -5,6 +5,10 @@ cd jc echo Building docs for: package pydocmd simple jc+ > ../docs/readme.md + +echo Building docs for: lib +pydocmd simple lib+ > ../docs/lib.md + echo Building docs for: utils pydocmd simple utils+ > ../docs/utils.md diff --git a/docs/lib.md b/docs/lib.md new file mode 100644 index 00000000..c7f9bbe3 --- /dev/null +++ b/docs/lib.md @@ -0,0 +1,86 @@ + +# lib +jc - JSON CLI output utility +JC lib module + + +## parse +```python +parse(parser_mod_name, + data, + quiet=False, + raw=False, + ignore_exceptions=None, + **kwargs) +``` + +Parse the string data using the supplied parser module. + +This function provides a high-level API to simplify parser use. This +function will call built-in parsers and custom plugin parsers. + +Example: + + >>> import jc + >>> jc.parse('date', 'Tue Jan 18 10:23:07 PST 2022') + {'year': 2022, 'month': 'Jan', 'month_num': 1, 'day'...} + +To get a list of available parser module names, use `parser_mod_list()` +or `plugin_parser_mod_list()`. `plugin_parser_mod_list()` is a subset +of `parser_mod_list()`. + +You can also use the lower-level parser modules directly: + + >>> import jc.parsers.date + >>> jc.parsers.date.parse('Tue Jan 18 10:23:07 PST 2022') + +Though, accessing plugin parsers directly is a bit more involved, so +this higher-level API is recommended. Here is how you can access plugin +parsers without this API: + + >>> import os + >>> import sys + >>> import jc.appdirs + >>> data_dir = jc.appdirs.user_data_dir('jc', 'jc') + >>> local_parsers_dir = os.path.join(data_dir, 'jcparsers') + >>> sys.path.append(local_parsers_dir) + >>> import my_custom_parser + >>> my_custom_parser.parse('command_data') + +Parameters: + + parser_mod_name: (string) Name of the parser module + + data: (string or Data to parse (string for normal + iterator) parsers, iterator of strings for + streaming parsers) + + raw: (boolean) output preprocessed JSON if True + quiet: (boolean) suppress warning messages if True + + ignore_exceptions: (boolean) ignore parsing exceptions if True + (streaming parsers only) + +Returns: + + Standard Parsers: Dictionary or List of Dictionaries + Streaming Parsers: Generator Object + + +## parser_mod_list +```python +parser_mod_list() +``` +Returns a list of all available parser module names. + +## plugin_parser_mod_list +```python +plugin_parser_mod_list() +``` +Returns a list of plugin parser module names. + +## get_help +```python +get_help(parser_mod_name) +``` +Show help screen for the selected parser diff --git a/jc/lib.py b/jc/lib.py index 24e6cece..09fc2d25 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -6,7 +6,7 @@ import sys import os import re import importlib -from . import appdirs +from jc import appdirs __version__ = '1.18.0'