You're reading an old version of this documentation. For up-to-date information, please have a look at v0.6.
pymetacode.cli module¶
Command-line interface (CLI) module of the pymetacode package.
While the actual code creating code is contained in the
pymetacode.coding
module, for most day-to-day business, programmers
need a simple interface they can use without need to write code that writes
code. Therefore, a key concept of the pymetacode package is an intuitive
command-line interface (CLI) that gets used from within a terminal - the
natural habitat of most programmers.
General usage¶
The package provides a command pymeta
(by means of a console-script
entry point) available from the command line given the pymetacode package is
installed. This command comes with built-in help and follows a rather simple
scheme:
pymeta <command> <option1> ...
The number of options available and required depends on the type of command
used. The design goal is an intuitive and robust user interface with
feedback and help built-in and a “grammar” that feels natural. For more
details, see the “Examples” section of the pymetacode.cli.Cli
class
documentation.
A bit of background¶
The first (and necessary) step for using the CLI is to create a configuration file, typically by issuing the following command on the terminal:
pymeta write config to mypackage_config.yaml
After having changed all values within this configuration file according to
the specific needs, one can continue to create a package, or alternatively,
if the package should exist already, move the configuration file to the root
directory of this existing package and rename it to .package_config.yaml
(note the leading “.”). This is the (only) way the CLI has access to
necessary information, such as the package name, and this is as well the
reason why each of the commands for adding modules, classes, and functions
need to be issued from the root directory of your package.
Module documentation¶
- class pymetacode.cli.Cli¶
Bases:
object
The actual command-line interface (CLI) of the pymetacode package.
More description comes here…
- command¶
The actual command to be executed.
In case of using the CLI from the terminal, the first argument.
- Type
- options¶
A list of options for the command.
In case of using the CLI from the terminal, all arguments from the second argument on.
- Type
- conf_file¶
The name the config file gets written to using the
write
command.Default: “package_config.yaml”
- Type
Examples
The following examples demonstrate how to use the CLI from the terminal, rather than how to use this class programmatically.
The first step when creating a new package is to write a config file that can be filled with sensible content afterwards:
pymeta write config to mypackage_config.yaml
This would write the default configuration to “mypackage_config.yaml”. Change all values in this file according to your needs. Afterwards, you can create the basic structure of your new project:
pymeta create package from mypackage_config.yaml
Now, you have a complete package that is installable and deployable. Next is to add some modules to your newly created package. All following commands need to be issued from within the root directory of your new package.
pymeta add module mymodule
will add a module “mymodule” to your package, together with a “test_mymodule” module in the “tests” subdirectory. And even better, the API documentation will be updated as well for you.
Time to add a class to your new module:
pymeta add class MyClass to mymodule
Here, again, the class will be added to “mymodule” and a test class added to “test_mymodule”. Similarly, you can add a function:
pymeta add function my_function to mymodule
Again, function and test class will be added to your package.
And if you are in doubt how to use the
pymeta
command, we’ve got you covered:pymeta pymeta help
are two equivalent commands that display some general help. Furthermore, you can get help for particular commands, too:
pymeta help create
would provide you with help specifically for the “create” command. Furthermore, if you make a mistake, usually, the context-specific help will be displayed for you as well.
- call(command='', options=None)¶
Execute a given command with the given options (if any).
- pymetacode.cli.cli()¶
Console entry point for the command-line interface.
The actual handling of the commands is entirely done within the
pymetacode.cli.Cli
class, but this function serves as entry point for the console script, providing thepymeta
command on the command line.