Git Product home page Git Product logo

commandargsparser's Introduction

CommandArgsParser

this project provide a code template for parsing command line arguments, it eases the process to create a python command line application, developer can create a python application with complex and flexible command line arguments rapidly and focus on the coding of business logic.

1. usage

1.1 adding user-defined options

download this project, use the script cmd_arg_parser.py as a base and add some arguments used in your application to the cmd_args_map dictionary in the cmd_arg_parse class in the sript, this dictionary represents all valid command line options, developer can add user-defined options here to add the options to the application.
adding a switch-styled option refer to the following format.

    <option_name_cmd>:(self.process_bool_option,"<option_name_internal>")

adding a option of key-value pair refer to the following format.

    <option_name_cmd>:(self.process_keyvalue_option,"<option_name_internal>")

option_name_cmd is the name of the option used in command line, type string.
option_name_internal is the name of the option as a key to stored in the self.real_cmd_options dictionary, type string.

1.2 using the cmd_arg_parser module in your project.

import the cmd_arg_parser module in your project and add the following code in your main function to parse the command line arguments.

    cmd_parser=cmd_arg_parser.cmd_arg_parser(sys.argv)
    cmd_parser.parse_cmd_args()
    # all command line options and argumetns are stored 
    # in cmd_parser.real_cmd_options dictionary. 
    # do some business logic based on the options stored in the 
    # md_parser.real_cmd_options dictionary.

the cmd_parser.real_cmd_options dictionary field is used to store all command line options and arguments after parsing the command line string successfully, it stores switch-styled options, key-value pair options, list of positional arguments. you can refer to all the command line options by referring to this variable as follows:

    cmd_parser.real_cmd_options[option1]  
    cmd_parser.real_cmd_options["position_arg_list"]

the option1 key is defined by developers in self.cmd_args_list, refer to self.cmd_args_list in section 1.1 for more information. the value for position_arg_list key is a list of all positional arguments. switch-styled options have the value True or False.

developers can focus on the coding of business logic based on the content of cmd_parser.real_cmd_options dictionary.

commandargsparser's People

Watchers

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