Skip to content

Commit

Permalink
Merge pull request #4 from qtc-de/dev
Browse files Browse the repository at this point in the history
Prepare v1.0.1 Release
  • Loading branch information
qtc-de authored Jan 9, 2024
2 parents 043cafa + 9d7f2c6 commit e5fc03c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## v1.0.1 - Jan 09, 2024

### Changed

* Resolved several bugs


## v1.0.0 - Jan 07, 2024

Initial Release :)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>eu.tneitzel</groupId>
<artifactId>argparse4j</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/eu/tneitzel/argparse4j/global/GlobalOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static void parseOptions(Namespace args, Properties config, IOption... op

for (IOption option : options)
{
String configValue = config.getProperty(option.getName().toLowerCase());
String configValue = config.getProperty(option.getPlainName());

if (configValue != null && !configValue.isEmpty())
{
Class<?> optionType = option.getClass();
Class<?> optionType = option.getType();

if (optionType == Integer.class)
{
Expand Down Expand Up @@ -74,11 +74,10 @@ else if (optionType == Boolean.class)
*
* @param parser the parser to add the options to
* @param action the associated action (can be null)
* @param options the options to add to the parser
*/
public static void addOptions(ArgumentParser parser, IAction action, IOption... options)
public static void addOptions(ArgumentParser parser, IAction action)
{
for (IOption option : options)
for (IOption option : action.getOptions())
{
option.addOption(parser, action);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/tneitzel/argparse4j/global/IAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface IAction
default void addSuparser(Subparsers argumentParser)
{
Subparser parser = argumentParser.addParser(getName()).help(getDescription());
GlobalOption.addOptions(parser, this, getOptions());
GlobalOption.addOptions(parser, this);
}
}
31 changes: 28 additions & 3 deletions src/main/java/eu/tneitzel/argparse4j/global/IOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ public interface IOption
*/
public <T> T getValue();

/**
* Returns the option name with all leading dashes being removed. Other dashes are
* replaced by underscores.
*
* @return plain option name
*/
default String getPlainName()
{
String name = getName();

while (name.startsWith("-"))
{
name = name.replaceFirst("-", "");
}

return name.replace("-", "_");
}

/**
* Get the group associated with an option. By default, options do not have groups
* assigned and the functions returns zero. IOptionGroups are intended to be stored
Expand Down Expand Up @@ -115,9 +133,16 @@ default boolean notNull()
*
* @return true if boolean option is true
*/
default boolean getBool()
default <T> boolean getBool()
{
return (boolean)getValue();
T value = getValue();

if (value == null)
{
return false;
}

return Boolean.parseBoolean(value.toString());
}

/**
Expand Down Expand Up @@ -149,7 +174,7 @@ default <T> void setValue(T value, T def)
*/
default <T> void setValue(Namespace args, T def)
{
T value = args.get(this.getName().replaceFirst("--", "").replace("-", "_"));
T value = args.get(getPlainName());
this.setValue(value, def);
}

Expand Down

0 comments on commit e5fc03c

Please sign in to comment.