Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 342: print help with no args, and reorder subcommands in help p… #343

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion documentation/flit-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,25 @@ 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
* [flit update](#flit-update): Updates the Makefile based on `flit-config.toml`
* [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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions scripts/flitcli/flit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions scripts/flitcli/flit_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading