Top Description Inners Fields Constructors Methods
org.eclipse.jgit.pgm.opt

public Class CmdLineParser

extends CmdLineParser
Class Inheritance
Known Direct Subclasses
org.eclipse.jgit.pgm.Main.SubcommandLineParser
Imports
java.io.IOException, .Writer, java.lang.reflect.Field, java.time.Instant, java.util.ArrayList, .Iterator, .List, .ResourceBundle, org.eclipse.jgit.lib.ObjectId, .Repository, org.eclipse.jgit.pgm.Die, .TextBuiltin, org.eclipse.jgit.pgm.internal.CLIText, org.eclipse.jgit.revwalk.RevCommit, .RevTree, .RevWalk, org.eclipse.jgit.transport.RefSpec, org.eclipse.jgit.treewalk.AbstractTreeIterator, org.kohsuke.args4j.CmdLineException, .IllegalAnnotationError, .NamedOptionDef, .OptionDef, .OptionHandlerRegistry, org.kohsuke.args4j.spi.OptionHandler, .RestOfArgumentsHandler, .Setter

Extended command line parser which handles --foo=value arguments.

The args4j package does not natively handle --foo=value and instead prefers to see --foo value on the command line. Many users are used to the GNU style --foo=value long option, so we convert from the GNU style format to the args4j style format prior to invoking args4j for parsing.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private TextBuiltin
private final Repository
private boolean
private RevWalk

Constructor Summary

AccessConstructor and Description
public
CmdLineParser(Object
instance of a class annotated by org.kohsuke.args4j.Option and org.kohsuke.args4j.Argument. this object will receive values.
bean
)

Creates a new command line owner that parses arguments/options and set them into the given object.

public
CmdLineParser(Object
instance of a class annotated by org.kohsuke.args4j.Option and org.kohsuke.args4j.Argument. this object will receive values.
bean
,
Repository
repository this parser can translate options through.
repo
)

Creates a new command line owner that parses arguments/options and set them into the given object.

Method Summary

Modifier and TypeMethod and Description
protected boolean

Returns:

true if the given array contains help option
containsHelp
(String...
non null
args
)

Check if array contains help option

protected OptionHandler<T>
createOptionHandler(OptionDef o, Setter<T> setter)

Overrides org.kohsuke.args4j.CmdLineParser.createOptionHandler.

Creates an OptionHandler that handles the given Option annotation and the Setter instance.

public Repository

Returns:

the repository, if specified during construction.
getRepository
()

Get the repository this parser translates values through.

public RevWalk

Returns:

the revision walk used by this option parser.
getRevWalk
()

Get the revision walker used to support option parsing.

public RevWalk

Returns:

the revision walk used by this option parser, or null.
getRevWalkGently
()

Get the revision walker used to support option parsing.

public void
parseArgument(String...
arguments to parse
args
)

Overrides org.kohsuke.args4j.CmdLineParser.parseArgument.

Parses the command line arguments and set them to the option bean given in the constructor.

public void
printSingleLineUsage(Writer w, ResourceBundle
if this is non-null, Option#usage() is treated as a key to obtain the actual message from this resource bundle.
rb
)

Overrides org.kohsuke.args4j.CmdLineParser.printSingleLineUsage.

Prints a single-line usage to the screen.

private void
private void
private boolean
private List<OptionHandler<T>>
Inherited from org.kohsuke.args4j.CmdLineParser:
addArgumentaddOptiongetArgumentsgetOptionsgetPropertiesisOptionparseArgumentprintExampleprintExampleprintExampleprintExampleprintOptionprintSingleLineUsageprintUsageprintUsageprintUsageregisterHandlersetUsageWidthstopOptionParsing

Field Detail

cmdback to summary
private TextBuiltin cmd
dbback to summary
private final Repository db
seenHelpback to summary
private boolean seenHelp
walkback to summary
private RevWalk walk

Constructor Detail

CmdLineParserback to summary
public CmdLineParser(Object bean)

Creates a new command line owner that parses arguments/options and set them into the given object.

Parameters
bean:Object

instance of a class annotated by org.kohsuke.args4j.Option and org.kohsuke.args4j.Argument. this object will receive values.

Exceptions
IllegalAnnotationError:
if the option bean class is using args4j annotations incorrectly.
CmdLineParserback to summary
public CmdLineParser(Object bean, Repository repo)

Creates a new command line owner that parses arguments/options and set them into the given object.

Parameters
bean:Object

instance of a class annotated by org.kohsuke.args4j.Option and org.kohsuke.args4j.Argument. this object will receive values.

repo:Repository

repository this parser can translate options through.

Exceptions
IllegalAnnotationError:
if the option bean class is using args4j annotations incorrectly.

Method Detail

containsHelpback to summary
protected boolean containsHelp(String... args)

Check if array contains help option

Parameters
args:String[]

non null

Returns:boolean

true if the given array contains help option

Since
4.2
createOptionHandlerback to summary
protected OptionHandler<T> createOptionHandler(OptionDef o, Setter<T> setter)

Overrides org.kohsuke.args4j.CmdLineParser.createOptionHandler.

Doc from org.kohsuke.args4j.CmdLineParser.createOptionHandler.

Creates an OptionHandler that handles the given Option annotation and the Setter instance.

Annotations
@Override
getRepositoryback to summary
public Repository getRepository()

Get the repository this parser translates values through.

Returns:Repository

the repository, if specified during construction.

getRevWalkback to summary
public RevWalk getRevWalk()

Get the revision walker used to support option parsing.

Returns:RevWalk

the revision walk used by this option parser.

getRevWalkGentlyback to summary
public RevWalk getRevWalkGently()

Get the revision walker used to support option parsing.

This method does not initialize the RevWalk and may return null.

Returns:RevWalk

the revision walk used by this option parser, or null.

parseArgumentback to summary
public void parseArgument(String... args) throws CmdLineException

Overrides org.kohsuke.args4j.CmdLineParser.parseArgument.

Doc from org.kohsuke.args4j.CmdLineParser.parseArgument.

Parses the command line arguments and set them to the option bean given in the constructor.

Parameters
args:String[]

arguments to parse

Annotations
@Override
Exceptions
CmdLineException:
if there's any error parsing arguments, or if required option was not given.
printSingleLineUsageback to summary
public void printSingleLineUsage(Writer w, ResourceBundle rb)

Overrides org.kohsuke.args4j.CmdLineParser.printSingleLineUsage.

Doc from org.kohsuke.args4j.CmdLineParser.printSingleLineUsage.

Prints a single-line usage to the screen.

Parameters
rb:ResourceBundle

if this is non-null, Option#usage() is treated as a key to obtain the actual message from this resource bundle.

Annotations
@Override
printToErrorWriterback to summary
private void printToErrorWriter(String error)
restoreRequiredOptionsback to summary
private void restoreRequiredOptions(List<OptionHandler<T>> backup)
sortRestOfArgumentsHandlerToTheEndback to summary
private boolean sortRestOfArgumentsHandlerToTheEnd(List<OptionHandler<T>> options)
unsetRequiredOptionsback to summary
private List<OptionHandler<T>> unsetRequiredOptions()
org.eclipse.jgit.pgm.opt back to summary

pack-priv Class CmdLineParser.MyOptionDef

extends OptionDef
Class Inheritance

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
public String
toString()

Overrides org.kohsuke.args4j.OptionDef.toString.

Returns a string representation of the object.

Inherited from org.kohsuke.args4j.OptionDef:
handlerhelphiddenisArgumentisMultiValuedmetaVarusage

Constructor Detail

MyOptionDefback to summary
public MyOptionDef(OptionDef o)

Method Detail

requiredback to summary
public boolean required()

Overrides org.kohsuke.args4j.OptionDef.required.

Annotations
@Override
toStringback to summary
public String toString()

Overrides org.kohsuke.args4j.OptionDef.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override