Skip to main content

A python library for creating a CLI with custom commands and parameters

Project description

Python-CLI

A Command Line Interface library for Python

Installation:

To use the library, just download the CLI.py file in custCLI and drop it in to you'r working folder
Or install the library using pip:

pip install custCLI

When using microPython, copy the CLI.py file from the microPython folder MicroPython files

How to use:

  1. Import the necessary classes and enums:

    from CLI import CLI, Command, Parameter, DataType
    
  2. Define your custom functions that will be executed when a command is called. For example:

    def testFunction(params):
      print("testFunction")     
      for param in params:
        print(f"\t{param}")
    
  3. Create instances of the Command class for each command you want to add. For example:

    command1 = Command("test1", 
                  "test1 description", 
                  testFunction, 
                  [Parameter("param1", "param1 description",DataType.STRING), 
                   Parameter("param2", "param2 description", DataType.INTEGER)]
                  )
    
    • To add a default value for a parameter, just add it to the end
      Parameter("param2", "param2 description", DataType.STRING, "TheDefaultValue")
      
  4. Optionally, define more custom functions and create additional Command instances.

  5. Create an instance of the CLI class, passing in the name, description, and a list of commands. For example:

    cli = CLI("Test CLI", "Test CLI description", [command1, command2])
    
  6. Print the header of the CLI using the printHeader() method:

    cli.printHeader()
    
  7. Enter a loop to continuously accept user commands using the newCommand() method:

    while True:
        cli.newCommand()
    

How to use:

from CLI import CLI, Command, Parameter, DataType

def testFunction(params):
 print("testFunction")     
 for param in params:
     print(f"\t{param}")

command1 = Command("test1", "test1 description", testFunction, [Parameter("param1", "param1 description", DataType.STRING), Parameter("param2", "param2 description", DataType.INTEGER)])

def testFunction2(params):
  print("testFunction2")
  for param in params:
      print(f"\t{param.name} - {param.dataType.value} - {param.value}")

command2 = Command("test2", "test2 description", testFunction2, [Parameter("param1", "param1 description", DataType.STRING), Parameter("param2", "param2 description", DataType.INTEGER)])

cli = CLI("Test CLI", "Test CLI description", [command1, command2])
cli.printHeader()

while True:
  cli.newCommand()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

custCLI-0.2.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file custCLI-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: custCLI-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.2

File hashes

Hashes for custCLI-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ea27ff9b31e9fac25d3de2eba129a113a99866c732455de7d63db1c9f2828d9
MD5 a33ffd120b35764b4f1df711972cd409
BLAKE2b-256 e4b32c300347f69ca319f68fcb5109be5be1767513eb4ddc4beef6c336c709a2

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