Skip to main content

Base class for creating modules that are bindings for command line tools.

Project description

morbin

Base class for creating modules that are bindings for command line tools.

Installation

Install with:

pip install morbin

Usage

The easiest way to start is to use the bundled template generator.
The only argument it requires is the name of the program you want to create bindings for.

As an example we'll do Git.

Running morbin git in your terminal will produce a file named git.py in your current directory.
It should look like this: Additional functions should be built on top of this git function and return its output.

After adding functions for git add, git commit, and git log the class should look like this:

The Output object each function returns is a dataclass with three fields: return_code, stdout, and stderr.

@dataclass
class Output:
    """Dataclass representing the output of a terminal command.

    #### Fields:
    * `return_code: list[int]`
    * `stdout: str`
    * `stderr: str`"""

    return_code: list[int]
    stdout: str = ""
    stderr: str = ""

    def __add__(self, output: Self) -> Self:
        return Output(
            self.return_code + output.return_code,
            self.stdout + output.stdout,
            self.stderr + output.stderr,
        )

By default stdout and stderr are not captured.
They are sent to wherever they normally would be and the stdout and stderr fields of the Output object will be empty strings.
stdout and stderr can be captured by either setting the capture_output property of a class instance to True or by using the capturing_output context manager as demonstrated below:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

morbin-0.1.0.tar.gz (363.5 kB view hashes)

Uploaded Source

Built Distribution

morbin-0.1.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page