Skip to main content

Gets options from the console command

Project description


Get options

Gets options from the console command, Format the options and return a dict. This is similar to the way non-GNU Unix systems work.


Install:

pip install GetOptions

System requirements

Python >= 3


Example

import GetOptions
params_config = {
        'host':     {'must': False,  'data': True,    'short': 'H',    'long': 'host',  'default': 'localhost'},
        'port':     {'must': False,  'data': True,    'short': 'O',    'long': 'port',  'default': 3306},
        'user':     {'must': True,   'data': True,    'short': 'U',    'long': 'user'},
        'passwd':   {'must': True,   'data': True,    'short': 'P',    'long': 'passwd'},
        'db':       {'must': True,   'data': True,    'short': 'D',    'long': 'db'},
        'init':     {'must': True,   'data': False,   'short': 'I',    'long': 'init'},
    }
print(GetOptions.get(params_config))
  • Shell command:
    • python3 test.py -H localhost -U root -P abc123 -D thinkvue -I abc 123
  • Print result:
    • {'data': {'host': 'localhost', 'port': 3306, 'user': 'root', 'passwd': 'abc123', 'db': 'thinkvue' , 'init': True}, 'args': ["abc", "123"]}

Parameter Description

GetOptions.get(params_config, params=None, is_show_help=True)

  • params_config:{type:dict} A dict used to describe parameters, each primary key has 5 fields:
    • key:{type:string} The primary key in the result returned
    • must:{type:bool} This is a required option?
    • data:{type:bool} Does it have member data?
    • short:{type:string} The short parameter, example:-s
    • long:{type:string} The long parameter, example:--longParam
    • default:{type:string} Default value
  • params:[optional]{type:list} Default sys.argv
  • is_show_help:[optional]{type:bool} Show help?

LICENSE

MIT

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

GetOptions-1.0.3.tar.gz (9.2 kB view details)

Uploaded Source

File details

Details for the file GetOptions-1.0.3.tar.gz.

File metadata

  • Download URL: GetOptions-1.0.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1

File hashes

Hashes for GetOptions-1.0.3.tar.gz
Algorithm Hash digest
SHA256 6148f99411f440a163d6151e235751392d2bd4040656fa3be90a3b97c46d388a
MD5 60ef3ef2316f5b70b1a0192100ac0a02
BLAKE2b-256 6d6134f73354b1cd0a710197e995e976596cdb7bb90bfd4d70b915c5cfeafc0e

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