Skip to main content

clifier

Clifier is a simple, tiny script to generate Argparse commands and subparsers from yaml config file.

All arguments and parameters names same like in Argparser module, so you do not need to know new lexic.

Whan you use clifier you don't need to create separate documentation for your users - you can just use config.yaml file as doc.

Install

To install clifier - use pip:

pip install clifier 

Examples

In folder clifier/examples you can find the example cli with config file. Just copy it to you local env and test.

Simple example of yaml config:

parser:
  prog: 'Clifier Example'
  description: Example for Clifier

commands:
   - keys: ['-v', '--version']
     help: "show Clifier Example version"
     action: show_version()
     default: True

subparsers:
  play:
    - keys: ['game']
      help: Write a name of the gave, what you want to play

    - keys: ['-c', '--count']
      help: Put number how much times you want to play
      default: 2

  sleep:
    - keys: ['-t', '--time']
      help: Put how much second you want to sleep

Sections in config file

"parser" section

Used to define args equal to args of argparse.ArgumentParser() init method, for example:

- prog
- description
- usage
- epilog and etc 

to know more, look at official Argparse documentation:
https://docs.python.org/3.6/library/argparse.html#argparse.ArgumentParser

"commands" section

commands properties equal to add_argument method
https://docs.python.org/3.6/library/argparse.html#argparse.ArgumentParser.add_argument 

"subparsers" section

name of subparser section element - it's a name, what equals to 
add_parser() argument "name" of object what returned by 
add_subparser_method

https://docs.python.org/3.6/library/argparse.html#argparse.ArgumentParser.add_subparsers

it's a Subparser name and it's not showed as argument in parser

To use Clifier in your code

Prepare variable with path to your config file with cli:

config_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "cli.yaml")

Initialise clifier

cli = clifier.Clifier(config_path, prog_version="0.0.1")

And get parser like standart Argparse parser

parser = cli.create_parser()
args = parser.parse_args()

That's it!

Adding custom actions

You can add to Clifier Custom Argparser Actions with method add_actions():

cli = clifier.Clifier(config_path)
cli.add_actions((your_custom_action_1, your_custom_action_2)

To use those actions in Cli, define them in command line config file with "action" property, for example:

Custom actions defined from box in Clifier

show_version

method to create command -v, --version to show program version for usage:

1. provide arg prog_version to Clifier() or define "version" param in config

    example in config.yaml:

    parser:
       prog: 'your prog name'
       version: "0.0.1"

    or 

    cli = clifier.Clifier(config_path, prog_version="0.0.1")

2. define -v, --version command in cli config:

    commands:
       - keys: ['-v', '--version']
         help: "show Clifier Example version"
         action: show_version()
         default: True
check_path_action

This action check exist or not file_path that was provided by user to command line.

Metadata

Release files for clifier 0.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 clifier 0.0.1
File Interpreter ABI Platform
clifier-0.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / clifier-0.0.1-py2.py3-none-any.whl

Download URL clifier-0.0.1-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
551fc2182b6a2e823cccf50a28e98a0ea98cf3c338fa8a83f3b27cda1df015e6
BLAKE2b-256 checksum
How to use checksums
ec3581c48fc2e5c79b4e14e58de113e9580c7a24c2bb06467a61c4db33584205
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release history Release notifications | RSS feed

0.0.3

2 release files

This release

0.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