Create simple commands in Python with ease!
Project description
cmdplug
cmdplug is a lightweight Python package that makes it easy to build command-line interfaces using argparse.
Usage
Create a command class by inheriting from Command provided by cmdplug.
# example: calculator.py
from argparse import ArgumentParser, Namespace
from cmdplug import Command
class Calculator(Command):
NAME="calculator"
HELP="for example"
@classmethod
def add_arguments(cls, parser: ArgumentParser):
parser.add_argument("-x", "--x", help="x variable", type=int)
parser.add_argument("-y", "--y", help="y variable", type=int)
def run(self, args: Namespace) -> int:
x, y = args.x, args.y
print(f"x({x}) + y({y}) = {args.x + args.y}")
return 0
Then, in your main entry point, simply import the command class and call command_init().
from exmaple import Calculator
from cmdplug import __command_init__
if __name__ == "__main__":
__command_init__()
Developer’s Note
I hope you enjoy building your own CLI tools with cmdplug and have fun coding!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmdplug-1.0.0.tar.gz.
File metadata
- Download URL: cmdplug-1.0.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c0a33b8d92ae12b7858320e385433af5d5f81c1bcdc87cc7362f7f0fc2cd108
|
|
| MD5 |
c1555c32fdadab2823d48a241895029b
|
|
| BLAKE2b-256 |
8aac52ed34aa933012e7cf6aafff265bc9eae926f63ac36aa041785c27ca9160
|
File details
Details for the file cmdplug-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cmdplug-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e21d052f4380e47ba180def0b2cc3bf75de7f9279f4c73055c12dae2e32ae682
|
|
| MD5 |
85081f6c67a57f0d303add7d72651546
|
|
| BLAKE2b-256 |
4cb1ca7c2aaa52a4547947e4f359cdaa2d269a61e03588dd03465f05e7a7e778
|