2. API Reference

2.1. Actions

class digger.base.action.Argument(name, flag, **kwargs)[source]

Class that stores arguments (argparse based) in BaseAction class

__init__(name, flag, **kwargs)[source]

Argument class constructor, should be used inside a class that inherits the BaseAction class.

Parameters:
  • name(str) – the optional argument name to be used with two slahes (–cmd)
  • flag(str) – a short flag for the argument (-c)
  • **kwargs – all keywords arguments supported for argparse actions.
class digger.base.action.BaseAction[source]

A class that should be subclassed to create a new action in the cli parser.

This action will become a subparser using its properties that subclass the class Argument as optional arguments for the subparser in context.

The subclass should define a _cmd_ and _help_ properties together with a instance handler method to receive the cli parameters.

_cmd_ becomes the subparser command and _help_ is the help/info text about the command itself.

It also implements the __call__ method to be used as a function to parse the command args.

Example:

1
2
3
4
5
6
7
8
class FooAction(BaseAction):
  _cmd_ = 'foo'
  _help_ = 'some foo random action'
  
  Argument('--say', '-s', default='hello', help='say something, default value is hello')

  def handler(self, say=None):
    print('Foo is saying: %s.' % say)
handler(**kwargs)[source]

Method to be overwrtten by the subclass to execute the actual command.

classmethod meta(name)[source]

Used to get the _cmd_ and _help_ class properties.

Parameters:name(str) – the property name to be retrieved.
Returns:
The class properties that starts and ends with one underscore char based on the provided name.
classmethod props()[source]

Class method that returns all defined arguments within the class.

Returns:
A dictionary containing all action defined arguments (if any).

Commandline tool for container builds

CLI tool to build mobile apps inside a container

2.2. Errors

class digger.errors.BaseError(message=None)[source]

Base exception class to be used whitin the module.

Every subclass error class should define an instance message property.

print_error()[source]

Prints the error into teh STDOUT

class digger.errors.InvalidPathError(path, **kwargs)[source]

Raised when an app folder path cannot be found.

class digger.errors.InvalidZipFileError(path, **kwargs)[source]

Raised when the module can’t unzip the app file (usually when the zipfile is corrupted).

class digger.errors.BaseError(message=None)[source]

Base exception class to be used whitin the module.

Every subclass error class should define an instance message property.

print_error()[source]

Prints the error into teh STDOUT

class digger.errors.InvalidCMDError(cmd, **kwargs)[source]

Raised when and invalid command is used in the CLI.

class digger.errors.MethodNotImplementedError(**kwargs)[source]

Raised when a handler from a BaseAction subclass was not implemented.

class digger.errors.DownloadError(**kwargs)[source]

Raised when the module can’t download the app source code from a given url.

class digger.errors.InvalidProjectStructure(**kwargs)[source]

Raised when the module can’t build the app due to an invalid project structure. Example: gradlew file is missing from the gradle project.

2.3. Parser

digger.parser.register_action(action)[source]

Adds an action to the parser cli.

Parameters:action(BaseAction) – a subclass of the BaseAction class
digger.parser.register_actions(*args)[source]

Accepts N arguments to be added as parser actions.

Parameters:*args – N number of actions that inherits from BaseAction.
digger.parser.run(*args, **kwargs)[source]

Runs the parser and it executes the action handler with the provided arguments from the CLI.

Also catches the BaseError interrupting the execution and showing the error message to the user.

Default arguments comes from the cli args (sys.argv array) but we can force those arguments when writing tests:

parser.run(['build', '--path', '/custom-app-path'].split())
parser.run('build --path /custom-app-path')

2.4. Builds