Metadata-Version: 2.1
Name: python-tools-scripts
Version: 0.9.0
Summary: Python Tools Scripts
Home-page: https://github.com/s0undt3ch/python-tools-scripts
Author: Pedro Algarvio
Author-email: pedro@algarvio.me
License: Apache Software License 2.0
Project-URL: Source, https://github.com/s0undt3ch/python-tools-scripts
Project-URL: Tracker, https://github.com/s0undt3ch/python-tools-scripts/issues
Project-URL: Documentation, https://python-tools-scripts.readthedocs.io
Platform: unix
Platform: linux
Platform: osx
Platform: cygwin
Platform: win32
Classifier: Programming Language :: Python
Classifier: Programming Language :: Cython
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: attrs
Requires-Dist: rich
Provides-Extra: changelog
Requires-Dist: towncrier (==22.8.0) ; extra == 'changelog'
Provides-Extra: docs
Requires-Dist: furo ; extra == 'docs'
Requires-Dist: sphinx ; extra == 'docs'
Requires-Dist: sphinx-copybutton ; extra == 'docs'
Requires-Dist: sphinx-prompt ; extra == 'docs'
Requires-Dist: sphinxcontrib-spelling ; extra == 'docs'
Requires-Dist: sphinxcontrib-towncrier (>=0.3.0a0) ; extra == 'docs'
Provides-Extra: lint
Requires-Dist: black ; extra == 'lint'
Requires-Dist: reorder-python-imports ; extra == 'lint'
Requires-Dist: flake8 (>=5.0.4) ; extra == 'lint'
Requires-Dist: flake8-mypy-fork ; extra == 'lint'
Requires-Dist: flake8-docstrings ; extra == 'lint'
Requires-Dist: flake8-typing-imports ; extra == 'lint'
Provides-Extra: tests
Requires-Dist: pytest ; extra == 'tests'

# Python Tools Scripts

This is a tool, similar to [invoke](https://www.pyinvoke.org).
It's more recent and uses [argparse](https://docs.python.org/3/library/argparse.html) under the hood
and some additional magic to define the CLI arguments.

To use it, you must have a `tools` package in your repository root.
On your `tools/__init__.py` import your scripts and *Python Tools Scripts* will add them to it's CLI.

## An Example Script `tools/vm.py`

```python
"""
These commands are used to create/destroy VMs, sync the local checkout
to the VM and to run commands on the VM.
"""

from ptscripts import Context, command_group

# Define the command group
vm = command_group(name="vm", help="VM Related Commands", description=__doc__)


@vm.command(
    arguments={
        "name": {
            "help": "The VM Name",
            "metavar": "VM_NAME",
            "choices": list(AMIS),
        },
        "key_name": {
            "help": "The SSH key name.",
        },
        "instance_type": {
            "help": "The instance type to use.",
        },
        "region": {
            "help": "The AWS regsion.",
        },
    }
)
def create(
    ctx: Context,
    name: str,
    key_name: str = None,
    instance_type: str = None,
    region: str = "eu-central-1",
):
    """
    Create VM.
    """
    vm = VM(ctx=ctx, name=name)
    vm.create(region_name=region, key_name=key_name, instance_type=instance_type)


@vm.command(
    arguments={
        "name": {
            "help": "The VM Name",
            "metavar": "VM_NAME",
        },
    }
)
def destroy(ctx: Context, name: str):
    """
    Destroy VM.
    """
    vm = VM(ctx=ctx, name=name)
    vm.destroy()
```

The, on your repository root, run:

```
❯ tools -h
usage: tools [-h] [--debug] {vm} ...

Python Tools Scripts

optional arguments:
  -h, --help   show this help message and exit
  --debug, -d  Show debug messages

Commands:
  {vm}
    vm         VM Related Commands

These tools are discovered under `<repo-root>/tools`.
```

```
❯ tools vm -h
usage: tools vm [-h] {create,destroy} ...

These commands are used to create/destroy VMs, sync the local checkout to the VM and to run commands on the VM.

optional arguments:
  -h, --help            show this help message and exit

Commands:
  {create,destroy}
    create              Create VM.
    destroy             Destroy VM.
```
