public abstract class TextBuiltin extends Object
Commands are configured with a single "current" repository and then the
execute(String[])
method is invoked with the arguments that appear
on the command line after the command name.
Command constructors should perform as little work as possible as they may be invoked very early during process loading, and the command may not execute even though it was constructed.
Modifier and Type | Class and Description |
---|---|
static class |
TextBuiltin.TerminatedByHelpException
Exception thrown by
TextBuiltin if it proceeds 'help' option |
Modifier and Type | Field and Description |
---|---|
protected RevWalk |
argWalk
RevWalk used during command line parsing, if it was required.
|
protected Repository |
db
Git repository the command was invoked within.
|
protected OutputStream |
errs
Error output stream, typically this is standard error.
|
protected ThrowingPrintWriter |
errw
Error writer, typically this is standard error.
|
protected String |
gitdir
Directory supplied via --git-dir command line option.
|
protected InputStream |
ins
Input stream, typically this is standard input.
|
protected OutputStream |
outs
Stream to output to, typically this is standard output.
|
protected ThrowingPrintWriter |
outw
Writer to output to, typically this is standard output.
|
Constructor and Description |
---|
TextBuiltin() |
Modifier and Type | Method and Description |
---|---|
static boolean |
containsHelp(String[] args) |
protected static Die |
die(boolean aborted) |
protected static Die |
die(boolean aborted,
Throwable cause) |
protected static Die |
die(String why) |
protected static Die |
die(String why,
Throwable cause) |
void |
execute(String[] args)
Parse arguments and run this command.
|
ThrowingPrintWriter |
getErrorWriter() |
Repository |
getRepository() |
protected ResourceBundle |
getResourceBundle() |
protected void |
init(Repository repository,
String gitDir)
Initialize the command to work with a repository.
|
protected void |
parseArguments(String[] args)
Parses the command line arguments prior to running.
|
protected void |
printUsage(String message,
CmdLineParser clp) |
void |
printUsageAndExit(CmdLineParser clp)
Print the usage line
|
void |
printUsageAndExit(String message,
CmdLineParser clp)
Print an error message and the usage line
|
protected boolean |
requiresRepository() |
protected abstract void |
run()
Perform the actions of this command.
|
protected InputStream ins
protected ThrowingPrintWriter outw
protected OutputStream outs
protected ThrowingPrintWriter errw
protected OutputStream errs
protected Repository db
protected String gitdir
protected RevWalk argWalk
protected boolean requiresRepository()
db
/getRepository()
is required.protected void init(Repository repository, String gitDir)
repository
- the opened repository that the command should work on.gitDir
- value of the --git-dir
command line option, if
repository
is null.public final void execute(String[] args) throws Exception
args
- command line arguments passed after the command name.Exception
- an error occurred while processing the command. The main
framework will catch the exception and print a message on
standard error.protected void parseArguments(String[] args) throws IOException
This method should only be invoked by execute(String[])
, prior
to calling run()
. The default implementation parses all
arguments into this object's instance fields.
args
- the arguments supplied on the command line, if any.IOException
public void printUsageAndExit(CmdLineParser clp) throws IOException
clp
- IOException
public void printUsageAndExit(String message, CmdLineParser clp) throws IOException
message
- clp
- IOException
protected void printUsage(String message, CmdLineParser clp) throws IOException
message
- non nullclp
- parser used to print optionsIOException
public ThrowingPrintWriter getErrorWriter()
protected ResourceBundle getResourceBundle()
protected abstract void run() throws Exception
This method should only be invoked by execute(String[])
.
Exception
- an error occurred while processing the command. The main
framework will catch the exception and print a message on
standard error.public Repository getRepository()
protected static Die die(String why)
why
- textual explanationprotected static Die die(String why, Throwable cause)
why
- textual explanationcause
- why the command has failed.protected static Die die(boolean aborted)
aborted
- boolean indicating that the execution has been aborted before runningprotected static Die die(boolean aborted, Throwable cause)
aborted
- boolean indicating that the execution has been aborted before
runningcause
- why the command has failed.public static boolean containsHelp(String[] args)
args
- non nullCopyright © 2016 Eclipse JGit Project. All rights reserved.