Skip to main content

A simple, extensible git like CLI framework.

Project description

monxcli

Getting started

an arg parser decorator to simplify argument parsing

Name

monxcli

Description

"A lightweight and extensible CLI framework for building modular, Git-like command-line tools. Simplify command grouping, subcommand handling, and argument parsing with a decorator-based approach."

Usage

the following structure should be use. Scripts are group according to modules

<folder>/
        + <folder>/
            - yourscript.py
        main.py

example
monxcli
├── monxcli/
├── main.py
├── mc <-- example scripts are in this module 
│   ├── __init__.py
│   └── math_commands.py

using the decorator example:

Import the commands module and use the @commands.command decorator to define your CLI commands. The decorator automatically registers your functions with the argument parser.

For example, the code below creates two commands for your CLI under the mc group and the math_command subgroup. The functions will be registered as subcommands, and their arguments will be mapped to CLI options.

from monxcli.commands import commands  # Shared LazyCommandParser

@commands.command()
@staticmethod
def add(x: int, y: int):
    """Adds two numbers."""
    print(f"The result of {x} + {y} is {x + y}")

@commands.command()
@staticmethod
def subtract(x: int, y: int):
    """Subtracts two numbers."""
    print(f"The result of {x} - {y} is {x - y}")

To activate the CLI, your main function should just import the modules where the commands are defined. Monxcli will take of the rest.

from mc import math_commands  # just import your module/script here

from monxcli.commands import commands  # Shared LazyCommandParser


if __name__ == "__main__":
    # Execute commands only if the script is run as the main module
    commands()

running the main script example:

> python3 main.py mc math_commands add --x 3 --y 3

mc is the folder or module and math_commands is the submodule, 'add' is the function you want to call then --x and --y are the arguments passed to your functions.

result:

$ python3 main.py mc math_commands add --x 3 --y 3
The result of 3 + 3 is 33

Support

contact author https://gitlab.com/mongkoy/

Project status

on-going

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

monxcli-1.0.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monxcli-1.0.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file monxcli-1.0.1.tar.gz.

File metadata

  • Download URL: monxcli-1.0.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for monxcli-1.0.1.tar.gz
Algorithm Hash digest
SHA256 68d5263c1da4bc77df6a974b0b4f311ceaf17e8362fbe536091e69b3cae598fc
MD5 f555826d33a52fea7f99ea1f5b979ce0
BLAKE2b-256 663984e352f3e932b73c6ccaa86d481dacccd75ee48805d244b6d5408789f2df

See more details on using hashes here.

File details

Details for the file monxcli-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: monxcli-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for monxcli-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 845662435db162644fc08061c8ec205a2340d186426944d92420c94b85c968f9
MD5 5b4e275136e3d894004e031c2d9a0286
BLAKE2b-256 9eb9cf9ca1b59f6bec79028b6f362e6a2c43392e1500404f7b79f28d5e86865c

See more details on using hashes here.

Supported by

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