GithubHelp home page GithubHelp logo

argparse_gen's Introduction

Argparse Code Generator

A simple utility meant to generate the skeleton for the argparse interface of your CLI scripts.

Content

  1. Intro
  2. Installation
  3. Usage
  4. CLI arguments

Intro

This package provides a simple utility to generate basic argparse interface for CLI scripts. It works by analysing the callable that you wish your script to call based on CLI arguments.

More precisely, it gets:

  1. the list of arguments from callable's signature;

  2. help hints from the callable's docstring;

  3. types, if possible, from callable's type annotation.

In some cases, it can do a bit more. For example, if the type of an argument is bool, the script will add action to its add_argument call, and if it is a Literal or an enum.Enum, it will create choices.

Installation

Just install it from PyPI:

$ pip install argparse_gen

This'll make argparse_gen script and package available to you.

Usage

If you run

$ argparse_gen -h

you'll get the full help for it, but essentially, it's used by calling

$ argparse_gen path/to/your/package/ name_of_callable_in_that_package

or

$ argparse_gen path/to/your/module.py name_of_callable_in_that_module

The output of the script is Python code that you can copy paste to your script's main file, and then adjust to your needs (the autogenerated version is unlikely to be perfect, except maybe for really trivial stuff).

If you wish to create your own custom scripts to prepare this code, use the package argparse_gen which exposes ArgparseGen class (which implements the whole thing), ParamDef (which implements one parameter), and main function (which wraps the class for convenient calls).

CLI arguments

The script recognizes the following CLI arguments:

  • -p PARAM_REGEX, --param_regex PARAM_REGEX: A regular expression to recognise parameters in the callable's docstring. The default recognizes rST (reStructuredText) format.
  • -i INDENT, --indent INDENT: Additional indentation for the generated code.
  • -s, --skip_private: Skip private (those with names starting with an underscore) arguments.
  • -c, --call_args: Instead of generating a call with all of the available arguments, use call_args (from the call-args package). This loses some transparency, but it's quite convenient if you frequently change the arguments.

argparse_gen's People

Contributors

vsego avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.