Skip to content

Commit

Permalink
Merge pull request #1061 from dirac-institute/CLI
Browse files Browse the repository at this point in the history
add in extra message to tell the user how to get help when trying to use the CLI
  • Loading branch information
mschwamb authored Dec 4, 2024
2 parents dc89303 + 6841f1c commit e14fc7f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/sorcha_cmdline/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#
# The `sorcha run` subcommand implementation
#
import argparse
import pooch
from sorcha_cmdline.sorchaargumentparser import SorchaArgumentParser


def main(): # pragma: no cover
# parse the input arguments
parser = argparse.ArgumentParser(
description="Fetch the NAIF high precision EOP kernel file store its checksum."
parser = SorchaArgumentParser(
prog="sorcha bootstrap",
description="Fetch the NAIF high precision EOP kernel file store its checksum.",
)

parser.add_argument(
"--cache",
type=str,
Expand Down
11 changes: 7 additions & 4 deletions src/sorcha_cmdline/demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse
from sorcha_cmdline.sorchaargumentparser import SorchaArgumentParser

#
# sorcha demo prepare
Expand Down Expand Up @@ -47,11 +47,14 @@ def cmd_demo_howto(args): # pragma: no cover

def main():
# Create the top-level parser
parser = argparse.ArgumentParser(
prog="sorcha-demo", description="Prepare and explain how to run sorcha demos"
parser = SorchaArgumentParser(
prog="sorcha demo", description="Prepare and explain how to run sorcha demos"
)
subparsers = parser.add_subparsers(
title="commands", description="Available commands", help="Command to execute", dest="command"
title="commands",
description="Available commands",
help="Command to execute",
dest="command",
)

# Add the `prepare` subcommand
Expand Down
6 changes: 3 additions & 3 deletions src/sorcha_cmdline/init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse
from sorcha_cmdline.sorchaargumentparser import SorchaArgumentParser
import sys

#
Expand Down Expand Up @@ -72,8 +72,8 @@ def execute(args): # pragma: no cover

def main():
# Create the top-level parser
parser = argparse.ArgumentParser(
prog="sorcha-init", description="Initialize configuration files for a new simulation."
parser = SorchaArgumentParser(
prog="sorcha init", description="Initialize configuration files for a new simulation."
)
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose output")
parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions src/sorcha_cmdline/outputs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse
from sorcha_cmdline.sorchaargumentparser import SorchaArgumentParser

#
# sorcha outputs create-sqlite
Expand Down Expand Up @@ -69,7 +69,7 @@ def cmd_outputs_check_logs(args): # pragma: no cover

def main():
# Create the top-level parser
parser = argparse.ArgumentParser(prog="sorcha-outputs", description="Sorcha outputs manipulation utility")
parser = SorchaArgumentParser(prog="sorcha outputs", description="Sorcha outputs manipulation utility")
subparsers = parser.add_subparsers(
title="commands", description="Available commands", help="Command to execute", dest="command"
)
Expand Down
10 changes: 8 additions & 2 deletions src/sorcha_cmdline/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
# The `sorcha run` subcommand implementation
#
import argparse
from sorcha_cmdline.sorchaargumentparser import SorchaArgumentParser


def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter, description="Run a simulation."
parser = SorchaArgumentParser(
prog="sorcha run",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Run a simulation.",
)

# parser = SorchaArgparse(parser)

required = parser.add_argument_group("Required arguments")
required.add_argument(
"-c",
Expand Down
37 changes: 37 additions & 0 deletions src/sorcha_cmdline/sorchaargumentparser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from argparse import ArgumentParser


class SorchaArgumentParser(ArgumentParser):
"""A subclass of the argparse.ArgumentParser that adds in a print statement
to make it clearer how to get detailed help for new users who may not be
as familiar with linux/unix"""

def __init__(self, *args, **kwargs):
"""A subclass of the argparse.ArgumentParser that adds in a print statement
to make it clearer how to get detailed help for new users who may not be
as familiar with linux/unix
Parameters
-----------
*args: Variable length argument list.
**kwargs: Arbitrary keyword arguments.
"""
super().__init__(*args, **kwargs)

def print_usage(self, file=None):
"""Print a brief description of how the ArgumentParser should be invoked
on the command line. If file is None, sys.stdout is assumed.
Parameters
-----------
file: str or None
Variable length argument list.
Returns
-----------
None.
"""
super().print_usage(file)
print(f"For more detailed help try: {self.prog} -h ", file=file)

0 comments on commit e14fc7f

Please sign in to comment.