GithubHelp home page GithubHelp logo

argc's Introduction

Argc

CI Crates

A handy way to handle sh/bash cli parameters.

demo

Install

With cargo

cargo install argc

Binaries on macOS, Linux, Windows

Download from Github Releases, unzip and add argc to your $PATH.

How Argc works:

To write a command line program with Argc, we only need to do two things:

  1. Describe the options, parameters, and subcommands in comments
  2. Call the following command to entrust Argc to process command line parameters for us
eval "$(argc -e $0 "$@")"

Argc will do the following for us:

  1. Extract parameter definitions from comments
  2. Parse command line arguments
  3. If the parameter is abnormal, output error text or help information
  4. If everything is normal, output the parsed parameter variable
  5. If there is a subcommand, call the subcommand function

We can easily access the corresponding option or parameter through the variable $argc_<name>.

Try examples/demo.sh your self.

Tag

Argc generates parsing rules and help documentation based on tags (fields marked with @ in comments).

@describe

@describe [string]

# @describe A demo cli

Define description

@version

@version [string]

# @version 2.17.1 

Define version

@author

@author [string]

# @author nobody <[email protected]>

Define author

@cmd

@cmd [string]

# @cmd Upload a file
upload() {
}

# @cmd Download a file
download() {
}

Define subcommand

@alias

@alias name(,name)+

# @cmd
# @alias t,tst
test() {
}

Define alias for a subcommand

@option

 @option [short] [long][modifer] [notation] [string]

 ## @option    --foo                A option
 ## @option -f --foo                A option with short alias
 ## @option    --foo <PATH>         A option with notation
 ## @option    --foo!               A required option
 ## @option    --foo*               A option with multiple values
 ## @option    --foo+               A required option with multiple values
 ## @option    --foo=a              A option with default value
 ## @option    --foo[a|b]           A option with choices
 ## @option    --foo[=a|b]          A option with choices and default value
 ## @option    --foo![a|b]          A required option with choices
 ## @option -f --foo <PATH>         A option with short alias and notation

Define value option

modifier

The symbol after the long option name is the modifier

  • *: occur multiple times, optional
  • +: occur multiple times, required
  • !: required
  • =value: default value
  • [a|b|c]: choices
  • [=a|b|c]: choices, first is default.
  • ![a|b|c]: choices, required

notation

Used to indicate that the option is a value option, other than a flag option.

If not provided, the option name is used as a placeholder by default.

You can use placeholder hint option value types <NUM>, <PATH>, <PATTERN>, <DATE>

@flag

@flag [short] [long] [help string]

# @flag     --foo       A flag
# @flag  -f --foo       A flag with short alias

Define flag option

@arg

@arg <name>[modifier] [help string]

# @arg value            A positional argument
# @arg value!           A required positional argument
# @arg value*           A positional argument support multiple values
# @arg value+           A required positional argument support multiple values
# @arg value=a          A positional argument with default value
# @arg value[a|b]       A positional argument with choices
# @arg value[=a|b]      A positional argument with choices and default value
# @arg value![a|b]      A required positional argument with choices

Define positional argument

arg's modifier is same to option's modifier

License

Copyright (c) 2022 argc-developers.

argc is made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See the LICENSE-APACHE and LICENSE-MIT files for license details.

argc's People

Contributors

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