Skip to main content

ArgChooser

ArgChooser is Python module which allows for fast and easy creation of function chooser.

  • Gives end-user an option to choose which functions to execute by cmdline args or cmdline menu
  • Just add flag names and functions
  • Execute and watch magic!

Table of Contents

  1. Documentation
    1. Installation
    2. Quick Start
    3. Examples
  2. License

Documentation

Installation

Simply use pip to install the ArgChooser package

pip install argchoose

Quick Start

Using ArgChooser is as simple as possible. Simple three steps:

  • Create object of ArgChooser
  • Bind methods with flags using add_argument
  • Execute ArgChooser!
from argchoose import ArgChooser


def foo():
    print('bar')


ac = ArgChooser()
ac.add_argument('-f', '--foo', method=foo)
ac.execute()

Now You are able to run your program from cmdline like that to execute method:

python example.py -f

Or without flags to see this:

Quickstart menu example

Examples

  1. Adding arguments
  2. Changing default ArgChooser parameters

Adding arguments

add_argument - allows to bind flag (or flags) with chosen method. It is possible to also specify category and help prompt.

Takes *flags: str, method: Callable [, help: str, category: str]

Returns nothing.

Example is based on This.

Categories allows to make menu clearer.

Default menu example

As You can see, help also makes it more descriptive, but also could be printed using -h flag like cmdline tools usually do!

python default_usage.py -h

Default help

To execute chosen methods, end-user has to choose, if they want to use it straight from cmdline or menu:

Default menu results

Default cmdline

Changing default ArgChooser parameters

ArgChooser could be initialized without any parameters, but gives possibility to change a few little things as shown Here.

Takes [category_style: str, default_category_name: str, style: Dict[Token, str], validation_func: Callable(List) -> bool, validation_error: str].

category_style is string on which is used format method with category name.
{} must be included in string.
Default is == {} ==.

default_category_name is string which will be used as category name for every uncategorized methods. Default is Other.

style is dictionary made from Tokens and strings which represents hex colors with textformatting keywords (like bold).

validation_func is function used for validating answers at the end of parsing (for example for checking if amount of answers is bigger than two).
This function must take one argument which is List and must return bool value.
Default functions checks if any answer is chosen.

validation_error is string which will be printed if validation_func returned False.
Default is You must choose at least one module..

Example

When validation_func return False, validation_error is printed like that:

Error

This is going to be changed to this, after releasing new version of PyInquirer with fixed validation parameter:

Correct error

License

Copyright (c) 2020 Paweł Kusiński
Distributed under the MIT License. See LICENSE for more information.

Metadata

Release files for argchoose 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for argchoose 0.1
File Interpreter ABI Platform
argchoose-0.1-py3-none-any.whl Python 3 none any Details

Release files / argchoose-0.1-py3-none-any.whl

Download URL argchoose-0.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee55656542d54bd5deb57f93712efd2d7dee6456db6ce8871b0bc3ccbfa1e9ab
BLAKE2b-256 checksum
How to use checksums
167e2c139990ab216d69e4245e9c4b8d1cc22b103e2165ca36a5cea01ecbd57b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.1.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page