Skip to main content

Call function directly in command line and a well help tips generately automatically

Project description

Call function directly in cmd line

Features

  1. Allow user call functions directly in command line.
  2. Generate help tips automatically.
  3. Add default called functions if not function was specific.

Notice

  1. It's better to add argument type for each autocall functions.
  2. str type argument must be defined explicitly.
  3. @cmdline_default is a subset of @cmdline, which means function with @cmdline_default will have @cmdline implicitly.
  4. Arguments of function with @cmdline_default should be optional or no argument.

TODO

  1. Support class's function with self as the first argument.

Code example

#!/bin/python3.8
from autocall import *

# The tar @cmdline is used to register the function.
@cmdline
def test1():
    print(f'test1()')
    pass

@cmdline
@cmdline_default
def test2(arg: int = 0):
    print(f'test2({arg})')
    pass

@cmdline
def test3(arg1, arg2: str = 'this is a string'):
    print(f'test3({arg1}, {arg2})')
    
@cmdline
def test4(arg1, arg2: int):
    'You can add some extra information here.'
    print(f'test4({arg1}, {arg2})')
    pass

@cmdline_default
def test5(arg1: int = 1, arg2: str = 'good'):
    print(f'test5({arg1}, {arg2})')

# main function
parse_and_run()

Run the code

~/autocall/src $ ./test.py --help
Help Tips Provided by Autocall.
  option:
    --test1     

    --test2     [arg = 0]  
                The function will be called directly if not specific.

    --test3     arg1  [arg2 = this is a string]  

    --test4     arg1  arg2  
                You can add some extra information here.

    --test5     [arg1 = 1]  [arg2 = good]  
                The function will be called directly if not specific.

    --help      [verbose = notverbose]  
                Give the argument "verbose" instead of "notverbose" to print detail information.

~/autocall/src $ ./test.py --test5 10 'hello'
test5(10, hello)
~/autocall/src $ ./test.py
test2(0)
test5(1, good)

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

autocall-1.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

autocall-1.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file autocall-1.1.1.tar.gz.

File metadata

  • Download URL: autocall-1.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for autocall-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7fe9711e971df4044276fb7cb1915f1d02aaabdff4f9adce3994f6c3cd140771
MD5 4f0cc9be29be0ad69041e4279cb3fc6c
BLAKE2b-256 aafc4ef2cff8e9ab5d08a796ac6d4dcd6fe77cf10cf2639ad4b0d333a17a0660

See more details on using hashes here.

File details

Details for the file autocall-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: autocall-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.12

File hashes

Hashes for autocall-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36d24c1d2cbc7732e7b3e2effcd6c2d2765ab1d25554414961c9f161aa31f724
MD5 fb73487095b8b19ef1421d185e747fc9
BLAKE2b-256 c80b057024859ff1e4456a20821125b912cf4af33db4bd150630d0b029a3010f

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