-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial plugin implementation. * Code tuning. * Doc linting and directory management. * README linting. * Renamed argument_parsers to parsers * Documentation linting.
- Loading branch information
Peter Nardi
authored
Mar 15, 2024
1 parent
6d67559
commit 1ef9d29
Showing
21 changed files
with
514 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,4 +157,6 @@ cython_debug/ | |
|
||
# Custom exclusions | ||
data/ | ||
src/plugins/ | ||
scratch/ | ||
.init/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Rules for writing custom commands. | ||
1. Start with this sample command file and modify it. | ||
2. Make sure to give your file the same name as your command (e.g. | ||
foo.py for the "foo" command). | ||
3. The entry point for your command will be "task_runner(args)", which | ||
is defined below. Do not change this function signature. Most of your | ||
code will go there, but you may add additional functions/modules as | ||
needed. The only rule here is that you must use this pre-defined | ||
entry point. | ||
4. "args" will be a argparse.Namespace variable that contains all the | ||
inputs captured on the command line, which are defined by foo_args.py | ||
5. Your code should return None. | ||
5. Each newly defined function must have an associated argument parser, | ||
defined in {function name}_args.py. See "foo_args.py" in | ||
banip/samples/plugins as an example. | ||
6. Make sure to put this file in banip/src/plugins/code | ||
""" | ||
|
||
import argparse | ||
|
||
|
||
def task_runner(args: argparse.Namespace) -> None: | ||
"""Do something wonderful. | ||
This is foo, so by definition it's wonderful! | ||
Parameters | ||
---------- | ||
args : argparse.Namespace | ||
Arguments passed on the command line. | ||
""" | ||
total = args.first + args.second | ||
print(f"The sum of {args.first} and {args.second} is {total}.") | ||
print("Cool! Right?") | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Rules for writing custom argument parsers. | ||
1. Start with this sample argument parser and modify it. | ||
2. Make the filename for this parser the same as the filename of your | ||
command, but with the '_args' suffix (e.g. foo_args.py for the | ||
command defined by foo.py). | ||
3. Do not change the function signature of the "load_command_args" | ||
function below. | ||
4. The variable COMMAND_NAME below is required. It must contain the name | ||
of your command. | ||
5. The sp.add_parser() function call is required. You can add additional | ||
arguments to the function call, but the "name", "help", and | ||
"description" arguments are required. Modify the "msg" variable to | ||
tailor your help and description messages. | ||
6. Add as many parser.add_argument() calls as you need. | ||
7. You may add additional functions/modules as needed. For example, | ||
adding something like "from argparse import FileType" if one of your | ||
command line arguments is a file type. | ||
8. Your code should return None. | ||
9. Make sure to put this file in banip/src/plugins/parsers | ||
""" | ||
|
||
from argparse import _SubParsersAction | ||
|
||
COMMAND_NAME = "foo" | ||
|
||
|
||
def load_command_args(sp: _SubParsersAction) -> None: | ||
"""Assemble the argument parser.""" | ||
msg = """This command takes two intergers on the command line, adds | ||
them together, then prints the result. Isn't that wonderful!""" | ||
parser = sp.add_parser( | ||
name=COMMAND_NAME, | ||
help=msg, | ||
description=msg, | ||
) | ||
|
||
# Add an argument to the parser | ||
msg = """The first variable to be added.""" | ||
parser.add_argument( | ||
"first", | ||
type=int, | ||
help=msg, | ||
) | ||
|
||
# Add another argument to the parser | ||
msg = """This is the second.""" | ||
parser.add_argument( | ||
"second", | ||
type=int, | ||
help=msg, | ||
) | ||
|
||
return |
File renamed without changes.
Oops, something went wrong.