Giter VIP home page Giter VIP logo

jargs's Introduction

JArgs command-line argument parsing library

  • Copyright (c) 2001-2019 Steve Purcell.
  • Copyright (c) 2002 Vidar Holen.
  • Copyright (c) 2002 Michal Ceresna.
  • Copyright (c) 2005 Ewan Mellor.
  • Copyright (c) 2010-2012 penSec.IT UG (haftungsbeschränkt).

All rights reserved.

Released under the terms of the BSD licence. See the file LICENCE for details.

Prerequisites

For each prerequisite, the version with which JArgs has been tested is given in parentheses. Any version equal to or later than this should work.

To build JArgs and run its tests you need on of

  • Apache Ant (1.8.2), by The Apache Software Foundation
  • Apache Maven (3.0.4), by The Apache Software Foundation

Moreover JUnit (4.3.1), by Eric Gamma, is used to run the unit tests, but is not needed to run the library itself.

Installation

To compile, package, and test the code, run either

ant

or

mvn clean package source:jar javadoc:jar jar:test-jar

Two jars are created, one called target/jargs-$VERSION$.jar, which contains the runtime library, and one called target/jargs-$VERSION$-tests.jar, which contains the unit tests and the examples. The Javadoc APIs are created in target/site/apidocs.

To use the library with your own code, simply ensure that target/jargs-$VERSION$.jar is on the CLASSPATH.

Pre-built packages are available via Sonatype's OSS Snapshots maven repository. Ensure you have the oss-public repository enabled in your pom.xml:

<repository>
  <id>sonatype-oss-public</id>
  <url>https://oss.sonatype.org/content/groups/public/</url>
  <releases>
    <enabled>true</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Then add JArgs to your dependencies list tag:

<dependency>
  <groupId>com.sanityinc</groupId>
  <artifactId>jargs</artifactId>
  <version>2.0-SNAPSHOT</version>
</dependency>

Documentation

The main documentation is the detailed worked example in src/examples/java/com/sanityinc/jargs/examples/OptionTest.java, plus the generated API documentation in target/site/apidocs.

Package contents

  • src/main/java/com/sanityinc/jargs -- The library itself.
  • src/examples/java/com/sanityinc/jargs/examples -- Examples showing how to use the library.
  • src/test/java/com/sanityinc/jargs -- JUnit tests.
  • target/site/apidocs -- API and other documentation.
  • target/classes -- Compiled classes, once built.
  • target/ -- JArgs jars, once built.

💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

🐦 @sanityinc

jargs's People

Contributors

dependabot[bot] avatar glensc avatar pensecit avatar purcell avatar white-gecko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jargs's Issues

Release 2.0

Hi,

since no development was done for a while I suggest we release 2.0 (without the SNAPSHOT) so other projects can rely on the artifact :-)

-- ooxi

Handling default true boolean options

This may not be a bug in the library. I don't remember what gnu getopt does with this and I'm not sure if you want to follow this by default or not.

The problem I ran into was that I wanted a default true boolean option. In my case the option was

CmdLineParser.Option pngOpt = parser.addBooleanOption('p', "png");

And to parse it I had:

pngOut = (Boolean) parser.getOptionValue(pngOpt, true);

Now what I wanted was for the user to be able to do something like one of the following:

--png=false
--png=no
--no-png
--not-png

None of these work. The last two are pretty speculative, but are supported by many programs. I ended up supporting the "--no-png" option in my code after I couldn't get this to work. I guessed that the first one would work out of the box and it is accepted by jargs without complaint.

So, I guess the bug would be that either jargs should actually do what is expected with the first form or it should spit out some kind of error.

The feature request would be to support more of the options above, or similar options, for cases where you have default true boolean options.

Thanks!

Intention of remove in getOptionValue

Although the activities around this project seem to have stopped, I am still using it and I have an issue with the code.

It would be a relief for me to know what you intended with line 472 of the in CmdLineParser.java, Steve. Why are you removing the entries from the values-Hashmap. It prevents to use getOptionValue more than once. Do I have to use parse again, if I want to query for the same option multiple times?

For now I have replaced .remove() with .get() in my local version of the project, but that results in an infinite while-loop in the unit-test testMultipleUses() in CmdLineParserTestCase.java. because the condition b == null is never true, which tells me you're doing the remove on purpose.

Is it safe for me to use .get() and @ignore the unit-test? Thx.

iterating over options and values

hi thanks for creating this cool jargs processing class

i'd like to suggest adding iterator access so that it would be possible to iterate over the options and values

e.g. on the apps side:

Iterator<Option<?>> options_iter = parser.iterator();
while(options_iter.hasnext()) {
    Option opt = iter.next();
    switch(opt.longForm()) {
    case "option1":
        values = parser.getOptionValues(opt)
        ...
        break;
    case "option2":
       ....
       break;

just a 2 cents suggestion :)

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.