Giter Club home page Giter Club logo

argparse's Introduction

A Java Argument Parser

Parse command line arguments easily.

Usage example

import argparse.*;
import argparse.arguments.*;

public class Main {
    public static void main(String[] args) {
        ArgumentParser parser = new ArgumentParser("Test program", args);

        PositionalArgument arg1 = new PositionalArgument("file", "Enter the output filename");
        FlagInputArgument arg2 = new FlagInputArgument("--file", "-f", "The input file path");
        FlagArgument arg3 = new FlagArgument("--verbose", "-v", "Display verbose options");
        
        parser.addArgument(arg1);
        parser.addArgument(arg2);
        parser.addArgument(arg3);

        parser.parseArguments();
        
        // Prints true if arg1 is specified in args (PositionalArguments are required, this will always be true)
        System.out.println(arg1.isPassed());
        
        // Prints arg1's input
        System.out.println(arg1.getInput());
        
        // Prints true if arg2 is specified in args 
        System.out.println(arg2.isPassed());
        
        // Prints text arg2's input. Example: {"-f", "hello"} -> hello
        System.out.println(arg2.getInput());
        
        // Prints if arg3 is specified in args. Arg 3 is a FlagArgument and has no input. If getInput method is called, null is returned.
        System.out.println(arg3.isPassed());
    }
}

argparse's People

Contributors

djcopley avatar zetamap avatar

Stargazers

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