From dd241e829c935bcdb08deed140bf4468c96c8bf9 Mon Sep 17 00:00:00 2001 From: Michael Bentley Date: Wed, 13 Nov 2024 20:48:51 -0700 Subject: [PATCH] Issue 342: print help with no args, and reorder subcommands in help printout - Do the same with `flit experimental` - Add missing documentation for `flit disguise` and update docs a little --- documentation/flit-command-line.md | 19 ++++++++++++++++++- scripts/flitcli/flit.py | 10 +++++++--- scripts/flitcli/flit_experimental.py | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/documentation/flit-command-line.md b/documentation/flit-command-line.md index dbff00b4..65aa86bc 100644 --- a/documentation/flit-command-line.md +++ b/documentation/flit-command-line.md @@ -19,7 +19,7 @@ For more information, simply call: flit --help ``` -Possible subcommands: +Core functionality subcommands: * [flit help](#flit-help): Display help for a specific subcommand * [flit init](#flit-init): Initializes a flit test directory for use @@ -27,12 +27,17 @@ Possible subcommands: * [flit make](#flit-make): Run flit tests locally and add results to the database * [flit import](#flit-import): Imports test results into an SQLite3 database * [flit bisect](#flit-bisect): Assign variability blame to files and functions + +Extra functionality subcommands: + +* [flit disguise](#flit-disguise): Anonymizes project-specific data from text files * [flit experimental](#flit-experimental): Access to experimental features Possibly of interest: * [Adding More Subcommands](#adding-more-subcommands) + ## flit help This can display the help documentation for a specific subcommand. This is @@ -223,6 +228,18 @@ You may also read the documentation on [experimental features](experimental-features.md). +## flit disguise + +This command disguises (a.k.a., anonymizes) text or log files. Fields that can +be disguised are source file names, test names, and function names. To +accomplish this feat, a mapping csv file can either be provided by the user +(with --disguise-map) or will be autogenerated as "disguise.csv" (default +behavior) from the contents of the Makefile and the object files for the +baseline compilation. The mapping is applied as a very simple search and +replace. To undo the disguise, use the --undo flag either allowing the default +"disguise.csv" file to be used or specifying one with --disguise-map. + + ## Adding More Subcommands The FLiT command-line structure is extremely modular. If you create a file diff --git a/scripts/flitcli/flit.py b/scripts/flitcli/flit.py index 17ef124c..38203f85 100755 --- a/scripts/flitcli/flit.py +++ b/scripts/flitcli/flit.py @@ -115,7 +115,7 @@ def load_subcommands(directory): ''' if directory not in sys.path: sys.path.insert(0, directory) - subcommand_files = glob.glob(os.path.join(directory, 'flit_*.py')) + subcommand_files = sorted(glob.glob(os.path.join(directory, 'flit_*.py'))) subcommand_names = [os.path.basename(x)[5:-3] for x in subcommand_files] subcom_modules = [importlib.import_module(os.path.basename(x)[:-3]) for x in subcommand_files] @@ -165,7 +165,8 @@ def populate_parser(parser=None, subcommands=None, recursive=False): subparsers = parser.add_subparsers( title='Subcommands', dest='subcommand', - metavar='subcommand') + metavar='subcommand', + ) for subcommand in subcommands: subparser = subparsers.add_parser( subcommand.name, help=subcommand.brief_description, @@ -236,13 +237,16 @@ def help_main(arguments, prog=sys.argv[0]): def _main_impl(arguments, module_dir, prog=None): 'Implementation of main' subcommands = load_subcommands(module_dir) - subcommands.append(create_help_subcommand(subcommands)) + subcommands.insert(0, create_help_subcommand(subcommands)) parser = populate_parser(subcommands=subcommands) if prog: parser.prog = prog args, remaining = parser.parse_known_args(arguments) subcommand_map = {sub.name: sub for sub in subcommands} + if args.subcommand is None: + parser.print_help() + return 0 subcommand = subcommand_map[args.subcommand] return subcommand.main(remaining, prog=parser.prog + ' ' + args.subcommand) diff --git a/scripts/flitcli/flit_experimental.py b/scripts/flitcli/flit_experimental.py index f5c9ec15..db503b47 100644 --- a/scripts/flitcli/flit_experimental.py +++ b/scripts/flitcli/flit_experimental.py @@ -113,6 +113,9 @@ def main(arguments, prog=None): if prog: parser.prog = prog args, remaining = parser.parse_known_args(arguments) + if args.subcommand is None: + parser.print_help() + return 0 subcommand_map = {sub.name: sub for sub in subcommands} subcommand = subcommand_map[args.subcommand] return subcommand.main(remaining, prog=parser.prog + ' ' + args.subcommand)