{"id":15761726,"url":"https://github.com/oz123/mach","last_synced_at":"2025-10-25T12:37:58.442Z","repository":{"id":46008404,"uuid":"134235019","full_name":"oz123/mach","owner":"oz123","description":"create awesome command line applications in a blaze","archived":false,"fork":false,"pushed_at":"2022-12-26T20:37:02.000Z","size":89,"stargazers_count":13,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T11:20:10.654Z","etag":null,"topics":["command-line","decorators","library","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oz123.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-21T07:37:21.000Z","updated_at":"2024-03-17T13:42:19.000Z","dependencies_parsed_at":"2023-01-31T01:31:01.761Z","dependency_job_id":null,"html_url":"https://github.com/oz123/mach","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oz123%2Fmach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oz123%2Fmach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oz123%2Fmach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oz123%2Fmach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oz123","download_url":"https://codeload.github.com/oz123/mach/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253750303,"owners_count":21958281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line","decorators","library","python3"],"created_at":"2024-10-04T11:03:51.362Z","updated_at":"2025-10-25T12:37:58.354Z","avatar_url":"https://github.com/oz123.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"========\nM.A.C.H\n========\n.. image:: https://readthedocs.org/projects/mach/badge/?version=latest\n   :target: http://mach.readthedocs.io/en/latest/?badge=latest\n.. image:: https://travis-ci.org/oz123/mach.svg?branch=master\n   :target: https://travis-ci.org/oz123/mach\n.. image:: https://coveralls.io/repos/github/oz123/mach/badge.svg?branch=master\n   :target: https://coveralls.io/github/oz123/mach?branch=master\n\nMagical Argparse Command Helper\n\n.. image:: https://raw.githubusercontent.com/oz123/mach/master/imgs/mach-logo.jpg\n\n\nFeatures\n--------\n\n * Get your CLI interfaces quickly\n * Turn a simple class to a CLI application or an interactive interpreter.\n\n\nGiven:\n\n.. code:: python\n\n  class Calculator:\n\n      def add(self, a, b):\n          \"\"\"adds two numbers and prints the result\"\"\"\n          return a + b\n\n      def div(self, a, b):\n          \"\"\"divide one number by the other\"\"\"\n          return a / b\n\nYou can make command line application using the decorator ``mach1``:\n\n.. code:: python\n\n   from mach import mach1\n\n   @mach1()\n   class Calculator:\n\n       def add(self, int: a, int: b):\n           \"\"\"adds two numbers and prints the result\"\"\"\n          print(a + b)\n\n       def div(self, int: a, int: b):\n           \"\"\"divide one number by the other\"\"\"\n          print(a / b)\n\n\n   calc = Calculator()\n\n   calc.run()\n\nNow if you run the module, you will get a program that you can invoke with\nthe flag ``-h`` or ``--help``:\n\n.. code:: shell\n\n   $ python calc.py -h\n   usage: calc.py [-h] {add,div} ...\n\n   positional arguments:\n   {add,div}   commands\n\n      add       adds two numbers and prints the result\n      div       divide one number by the other\n\n   optional arguments:\n     -h, --help  show this help message and exit\n\n\neach method is a subcommand, with type checking and it's own very help.\nHench, this won't work:\n\n.. code:: shell\n\n   $ python calc.py add foo bar\n   usage: calc.py add [-h] b a\n   calc.py add: error: argument b: invalid int value: 'foo'\n\nAnd this will:\n\n.. code:: shell\n\n   $ python calc.py add 4 9\n   13\n\nTo see the help of the subcommand use ``-h``:\n\n.. code:: shell\n\n   $ python calc.py add -h\n   usage: calc.py add [-h] b a\n\n   positional arguments:\n    b\n    a\n\n   optional arguments:\n     -h, --help  show this help message and exit\n\nWith the help of the decorator ``mach2`` you can turn your class to CLI\napplication and have also an iteractive shell which invoke when no\nparameters are given:\n\n.. code:: shell\n\n   $ ./examples/calc2.py\n   Welcome to the calc shell. Type help or ? to list commands.\n\n   calc2 \u003e ?\n\n   Documented commands (type help \u003ctopic\u003e):\n   ========================================\n   add  div  exit  help\n\n   calc2 \u003e help add\n   adds two numbers and prints the result\n   calc2 \u003e add 2 4\n   6\n   calc2 \u003e div 6 2\n   3.0\n   calc2 \u003e exit\n   Come back soon ...\n   $\n\nInstallation\n------------\n\nYou can get mach from PyPI using pip::\n\n   $ pip install mach.py\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foz123%2Fmach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foz123%2Fmach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foz123%2Fmach/lists"}