Git Product home page Git Product logo

ezcli's Introduction

ezcli

Small and lightweight enough to be put into any CLI application quickly with no fuss. Just call a macro or two and it's up and running!

If you do want a more fleshed out CLI crate, you should check out clap.

how to use

ezcli is pretty easy to use and nothing too crazy is happening. Using flag! or option! will allow for them to be passed as CLI args and it even creates a nifty little variable for you to use once the macro has been called. Note that the macros will replace underscores (_) with hyphens (-) in the arguments name.

flag

Command line argument for a boolean state. The flag! macro only requires a variable name. Once invoked, it will check the command line arguments for a matching flag. Optionally, passing the keyword let will create a variable with the same name as the flag.

use ezcli::flag;

if flag!(--my_boolean) { // "--my-boolean" exists in arguments
    // do stuff because flag is given
}

// OR

flag!(let --my_boolean);

if my_boolean { // "--my-boolean" exists in arguments
    // do stuff because flag is given
}

option

Command line argument for an optional parameter. The option! macro requires a variable name, like flag!, and will create a variable if let is included. The value will be the next argument wrapped in a Some, unless it is not provided then it'll be None.

use ezcli::option;

match option!(--my_arg) {
    Some(x) => {}, // use x
    None => {}, // handle no value
}

// OR 

option!(let --my_arg);

match my_arg {
    Some(x) => {}, // use x
    None => {}, // handle no value
}

short- and long-name arguments

A command line argument can be in short-name (indicated by 1 hyphen: -a) or long-name (indicated by 2 hyphens: --arg). This applies to both flag! and option!.

use ezcli::{flag, option};

if flag!(-f, --flag) { 
    // "-f" or "--flag" exists in arguments
}

// "-a" or "--arg" exists in arguments
match option!(-a, --arg) {
    Some(x) => {},
    None => {},
}

// OR

let my_flag = flag!(-f, --flag);
...

See flag and option tests for more detailed examples.

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.