Skip to main content

A small cli command helper package

Project description

Climmands

Climmands is a small package that provides a convenient abstraction for cli subcommands.

Each command is described by different class. These classes should inherit from Command class. The CommandLoader class is responsible for collecting all commands in module scope. CommandExecutor execute a proper command and pass it the rest of command line arguments.

Warning: it's a toy and untested package. Use only for your own responsibility!

Installation

$ pip install climmands

Example

#!/usr/bin/env python

import argparse
import climmands

class HelloWorldCommand(climmands.Command):
	name = 'hello'
	description = 'Print Hello World message'

	def execute(self, parsed_arguments):
		print('Hello world')

class AddTwoNumbersCommand(climmands.Command):
	name = 'add'
	description = 'Add two numbers and print result'

	def initialize_arguments_parser(self, parser):
		parser.add_argument('first', help='First number')
		parser.add_argument('second', help='Second number')

	def execute(self, parsed_arguments):
		first = int(parsed_arguments.first)
		second = int(parsed_arguments.second)
		result = first + second

		print(f'{first} + {second} = {result}')

def main():
	parser = argparse.ArgumentParser(description='My great command')
	commands = climmands.CommandLoader(parser).load_commands()
	executor = climmands.CommandExecutor(commands)

	parsed_arguments = parser.parse_args()
	if not executor.execute(parsed_arguments):
		parser.print_help()

if __name__ == '__main__':
	main()

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

climmands-0.0.3.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

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

climmands-0.0.3-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file climmands-0.0.3.tar.gz.

File metadata

  • Download URL: climmands-0.0.3.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for climmands-0.0.3.tar.gz
Algorithm Hash digest
SHA256 44f6b4f55a84a684057220752eb9a79fcb75821e12035d20aafd371ae1837a56
MD5 07fe5e090ac70aa8358170506c815f37
BLAKE2b-256 94df27bc7d6f80855d286740d10eb4b096065f374fc24ccfc380e00524d019ea

See more details on using hashes here.

File details

Details for the file climmands-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: climmands-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9

File hashes

Hashes for climmands-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 31f4a66c1a1b4301a0690246200c9fd9f84fabaf2a4815423b3a476851decc0e
MD5 2a97d32d646da1ae58bdacffa9fad53d
BLAKE2b-256 93d881a407b71b13658f52afc484199296974b8926387e87dbcd16e3c9be9b1c

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