Giter Club home page Giter Club logo

javaargs's Introduction

JavaArgs

command line args parse

Quick Start
src/test/java/QuickStart.java

import com.xiyuan.args.Args;
import com.xiyuan.args.ArgsExp;

public class QuickStart extends Args{

    //ArgExp fromat:
    //commandName [optionName<defaultValue><optionValueRegex>] [optionName] (optionName<optionValueRegex>) <optionName<optionValueRegex>>
    //commandName can be empty str
    //[optionName<defaultValue><optionValueRegex>] is a optional arg
    //[optionName] is a optional arg, if exist, value is true, else false
    //(optionName<optionValueRegex>) is a required arg matched by optionName
    //<optionName<optionValueRegex>> is a required arg matched by the index of args which are not matched by others
    @ArgsExp(exp = "start" +
            " [-t<10><\\d+>]" +
            " [-p]" +
            " (-n<\\d+>)" +
            " <time<\\d+>>",
            usage = "start tasks;" +
            " -t: num of threads, optional arg, default value is 10;" +
            " -p: should print logs during task;" +
            " -n: num of tasks, required arg;" +
            " time: execution time(millisecond), index arg")
    public void startTask(int _t, boolean _p, int _n, long time) {
        System.out.println("_t = [" + _t + "], _p = [" + _p + "], _n = [" + _n + "], time = [" + time + "]");
    }

    public static void main(String[] args) {
        QuickStart quickStart = new QuickStart();
        quickStart.execute("start -t 20 -n 1000 60000");
        quickStart.execute("start 80000 -p -n 1000");
    }

}

output

_t = [20], _p = [false], _n = [1000], time = [60000]
_t = [10], _p = [true], _n = [1000], time = [80000]

More example
src/test/java/Test.java

javaargs's People

Contributors

xiyuan-fengyu avatar xiyuan0918 avatar

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.