Coder Social home page Coder Social logo

joshiayush / argparse Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 76 KB

A light-weight argument parsing library with no external dependency.

License: BSD 3-Clause "New" or "Revised" License

Java 100.00%
argparse command-line google java java-google-style junit linux maven parser

argparse's People

Contributors

joshiayush avatar

Watchers

 avatar

argparse's Issues

Is it really necessary to add support for `Solaris` operating system?

/**
* Returns true if the Operating System is Solaris.
*/
public static boolean isSolaris() {
return getOsName().toLowerCase().indexOf("sunos") >= 0;
}

I think adding support for Solaris is a bit out-of-scope for me as a developer right now, because I don't have experience using Solaris. I can add support for Mac although that's another operating system that I didn't use but it's a bit similar to Linux which is my primary operating system. And because of the platform independence of Java project argparse will have no issue on Windows. But adding support for Solaris is a bit weird right now. Either remove the function completely or add support for Solaris too.

Remove the duplicate code by refactoring it in a single function call.

if (this.optionsMap
.get(argumentWithoutPrefix.hashCode()).optionType == ArgparseOptionType.ARGPARSE_OPT_GROUP) {
if (isGroupArgumentEncountered) {
this.error(String.format("%s and %s is a part of group, hence can be used only one at a time.",
groupArgument, argumentWithoutPrefix));
}
groupArgument = argumentWithoutPrefix;
}

if (this.optionsMap
.get(argumentWithoutPrefix.hashCode()).optionType == ArgparseOptionType.ARGPARSE_OPT_GROUP) {
if (isGroupArgumentEncountered) {
this.error(String.format("%s and %s is a part of group, hence can be used only one at a time.",
groupArgument, argumentWithoutPrefix));
}
groupArgument = argumentWithoutPrefix;
}

As you can see the above conditional check is repeating itself at line 302 and at line 334 which can easily be refactored into a single function call.

if (this.optionsMap
.get(this.longToShortOptionsMap.get(argumentWithoutPrefix)
.hashCode()).optionType == ArgparseOptionType.ARGPARSE_OPT_GROUP) {
if (isGroupArgumentEncountered) {
this.error(String.format("%s and %s is a part of group, hence can be used only one at a time.",
groupArgument, argumentWithoutPrefix));
}
groupArgument = argumentWithoutPrefix;
}

if (this.optionsMap
.get(this.longToShortOptionsMap.get(argumentWithoutPrefix)
.hashCode()).optionType == ArgparseOptionType.ARGPARSE_OPT_GROUP) {
if (isGroupArgumentEncountered) {
this.error(String.format("%s and %s is a part of group, hence can be used only one at a time.",
groupArgument, argumentWithoutPrefix));
}
groupArgument = argumentWithoutPrefix;
}

As you can see the above conditional check is also repeating itself at line 312 and at line 348 which can easily be refactored into a single function call.

We need to refactor these into separate function calls because as the complexity of our program will increase it will become harder to maintain the program and modify it.

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.