Command line options¶
The logic which would parse the current command line and run something for it.
All codes belong to here section, they all are responsible for defining the command line and its options to let argpars understands how to parse the current command line.
UML¶
About the software architecture of this feature is already be introduced. Please refer to section Command line - UML.
Workflow¶
About the software workflow details of this feature is already be introduced. Please refer to section Command line - Workflow.
Extension¶
Here would demonstrate how to extend or add new sub-command feature.
You'll have 4 things:
Add new attribute of enum object SubCommandLine¶
Enum object SubCommandLine
is the standard for PyFake-API-Server to recognize which sub-command it has. So let's add
one new sub-command line here:
fake_api_server.command.subcommand | |
---|---|
Implement new class about subcommand new-ps
¶
Add new class extends base class BaseSubCommand
and set value at attribute sub_parser
.
fake_api_server.command.new_subcmd.options | |
---|---|
Instantiate class with metaclass for subcommand new-ps
¶
Instantiate a base class for adding options.
fake_api_server.command.options | |
---|---|
It would auto-register this sub-command line into SUBCOMMAND
. We have sub-command line new-ps
, let's add its options.
Extend the subcommand object to add its option(s)¶
Add new command option with extending BaseSubCmdNewProcessOption
and set needed attributes in it:
fake_api_server.command.options | |
---|---|
cli_option
: Define the option usage via command line.name
: The attribute to get the option value from argpars.help_description
: The description would be displayed if you run--help
.
Finally, don't forget to let command line process know which sub-command line is its responsibility by overriding the class
attribute responsible_subcommand
:
fake_api_server.command.process | |
---|---|
Now, let's try to run the PyFake-API-Server with new sub-command:
Congratulation! It works finely as out expect.