Skip to main content

A tool to create a command-line interface for your app using python

Project description

betterargs

A tool to create a command-line interface for your app using python

Installation

pip install betterargs
  • Requirements
    • python3.10
    • pip3

Releases

Packaging and releases are handled in the packaging branch. MAIN BRANCH IS RESERVED FOR MAINTAINING CODE ONLY!!!

Usage

  • Create a command string in YAML format in a:

    1. YAML file
    2. Python dictionary
    3. Python string
  • Convert the yaml file to command line namespace using appropriate function

  1. Using a YAML file

git:
    args:
        path:
            atype: flag
            help: Path of the repo
    subparsers:
        parsers:
            clone:
                args:
                    quiet-clone:
                        atype: flag
                        help: Operate quietly. Progress is not reported to the standard error stream.
                    no-checkout:
                        help: No checkout of HEAD is performed after the clone is complete
            init:
                args:
                    quiet-init:
                        atype: flag
                        help: Operate quietly. Progress is not reported to the standard error stream.
import betterargs

# Create command line namespace and get arguments
command_tree_PATH = 'command_tree.yaml'

args = betterargs.format_path_tree(command_tree_PATH)
  1. Using Python Dictionary in YAML Format

command_tree_DICT = {
    "git": {
        "args": {
            "path": {
                "atype": "flag",
                "help": "Path of the repo",
            },
        },
        "subparsers": {
            "parsers": {
                "clone": {
                    "args": {
                        "quiet-clone": {
                            "atype": "flag",
                            "help": "Operate quietly. Progress is not reported to the standard error stream.",
                        },
                        "no-checkout": {
                            "help": "No checkout of HEAD is performed after the clone is complete"
                        },
                    },
                },
                "init": {
                    "args": {
                        "quiet-init": {
                            "atype": "flag",
                            "help": "Operate quietly. Progress is not reported to the standard error stream.",
                        },
                    },
                },
            },
        },
    },
}
import betterargs

# Create command line namespace and get arguments
args = betterargs.format_dict_tree(command_tree_DICT)
  1. Using YAML Format string

# Define command tree in YAML string format
command_tree_STR = """
git:
    args:
        path:
            atype: flag
            help: Path of the repo
    subparsers:
        parsers:
            clone:
                args:
                    quiet-clone:
                        atype: flag
                        help: Operate quietly. Progress is not reported to the standard error stream.
                    no-checkout:
                        help: No checkout of HEAD is performed after the clone is complete
            init:
                args:
                    quiet-init:
                        atype: flag
                        help: Operate quietly. Progress is not reported to the standard error stream.
"""
import betterargs

# Create command line namespace and get arguments
args = betterargs.format_str_tree(command_tree_STR)

Contribution

You are more than welcome to contribute 😊 It doe

It's simple!!!

  • Fork the repo

  • Clone the repo

git clone https://github.com/danielmuringe/betterargs
  • Make your modifications in the dev

  • Merge into main branch respecting the .gitignore of the main branch. KEEP IT CLEAN !!!

  • Create pull request

  • Wait for confirmation

Tests

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

betterargs-0.0.2.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

betterargs-0.0.2-py3-none-any.whl (4.1 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