org.cyclopsgroup.jcli.impl.AnnotationParsingContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jcli Show documentation
Show all versions of jcli Show documentation
Annotation based command line arguments parser
package org.cyclopsgroup.jcli.impl;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.cyclopsgroup.jcli.spi.Argument;
import org.cyclopsgroup.jcli.spi.Cli;
import org.cyclopsgroup.jcli.spi.Option;
import org.cyclopsgroup.jcli.spi.ParsingContext;
class AnnotationParsingContext implements ParsingContext {
private final AnnotationArgument argument;
private final AnnotationCli cli;
private final List options;
private final Map> referenceMap;
/**
* @param referenceMap Map of references
* @param options List options
* @param cli Command line model
* @param argument Argument definition
*/
AnnotationParsingContext(Map> referenceMap, List options,
AnnotationCli cli, AnnotationArgument argument) {
this.options = options;
this.referenceMap = referenceMap;
this.cli = cli;
this.argument = argument;
}
@Override
public Argument argument() {
return argument;
}
@Override
public Cli cli() {
return cli;
}
/**
* Find reference with given name of option or argument
*
* @param name Name of option or argument
* @param isLongName True if name is a long name
* @return Reference that matches name or NULL
*/
Reference lookupReference(String name, boolean isLongName) {
if (isLongName) {
for (Reference r : referenceMap.values()) {
if (r.longName.equals(name)) {
return r;
}
}
return null;
}
return referenceMap.get(name);
}
@Override
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy