Package org.eclipse.jgit.pgm
Class TextBuiltin
java.lang.Object
org.eclipse.jgit.pgm.TextBuiltin
- Direct Known Subclasses:
AbstractFetchCommand,Add,AmazonS3Client,Archive,BenchmarkReftable,Blame,Branch,Checkout,Clean,Commit,Config,ConvertRefStorage,Daemon,Describe,Diff,DiffAlgorithms,DiffTool,DiffTree,Gc,IndexPack,Init,LfsStore,LsFiles,LsRemote,LsTree,MakeCacheTree,Merge,MergeBase,Push,ReadDirCache,ReadReftable,RebuildCommitGraph,ReceivePack,Reflog,Remote,Repo,Reset,RevParse,RevWalkTextBuiltin,Rm,Show,ShowCacheTree,ShowCommands,ShowDirCache,ShowPackDelta,ShowRef,Status,Tag,TextHashFunctions,UploadPack,VerifyReftable,Version,WriteDirCache,WriteReftable
Abstract command which can be invoked from the command line.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown byTextBuiltinif it proceeds 'help' option -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RevWalkRevWalk used during command line parsing, if it was required.private Stringprotected RepositoryGit repository the command was invoked within.protected OutputStreamError output stream, typically this is standard error.protected ThrowingPrintWriterError writer, typically this is standard error.protected StringDirectory supplied via --git-dir command line option.private booleanprotected InputStreamInput stream, typically this is standard input.protected OutputStreamStream to output to, typically this is standard output.protected ThrowingPrintWriterWriter to output to, typically this is standard output.private SshDriver -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) StringabbreviateRef(String dst, boolean abbreviateRemote) static booleancontainsHelp(String[] args) Check if the arguments contain a help optionprotected static Diedie(boolean aborted) Exit the commandprotected static DieExit the commandprotected static DieExit the command with an error messageprotected static DieExit the command with an error message and an exceptionfinal voidParse arguments and run this command.Get error writerprivate CharsetgetLogOutputEncodingCharset(Repository repository) Get the log output encoding specified in the repository'si18n.logOutputEncodingconfiguration.Get output writerGet the repositoryprotected ResourceBundleGet resource bundle with localized textsprotected voidinit(Repository repository, String gitDir) Initialize the command to work with a repository.voidinitRaw(Repository repository, String gitDir, InputStream input, OutputStream output, OutputStream error) Initializes the command to work with a repository, including setting the output and error streams.protected voidparseArguments(String[] args) Parses the command line arguments prior to running.protected voidprintUsage(String message, CmdLineParser clp) Print usage help text.voidprintUsageAndExit(String message, CmdLineParser clp) Print an error message and the usage linevoidPrint the usage lineprotected booleanIf this command requires a repository.(package private) ObjectIdprotected abstract voidrun()Perform the actions of this command.(package private) final voidsetCommandName(String name)
-
Field Details
-
commandName
-
help
private boolean help -
sshDriver
-
ins
Input stream, typically this is standard input.- Since:
- 3.4
-
outw
Writer to output to, typically this is standard output.- Since:
- 2.2
-
outs
Stream to output to, typically this is standard output.- Since:
- 2.2
-
errw
Error writer, typically this is standard error.- Since:
- 3.4
-
errs
Error output stream, typically this is standard error.- Since:
- 3.4
-
db
Git repository the command was invoked within. -
gitdir
Directory supplied via --git-dir command line option. -
argWalk
RevWalk used during command line parsing, if it was required.
-
-
Constructor Details
-
TextBuiltin
public TextBuiltin()
-
-
Method Details
-
setCommandName
-
requiresRepository
protected boolean requiresRepository()If this command requires a repository.- Returns:
- true if
db/getRepository()is required
-
initRaw
public void initRaw(Repository repository, String gitDir, InputStream input, OutputStream output, OutputStream error) Initializes the command to work with a repository, including setting the output and error streams.- Parameters:
repository- the opened repository that the command should work on.gitDir- value of the--git-dircommand line option, ifrepositoryis null.input- input stream from which input will be readoutput- output stream to which output will be writtenerror- error stream to which errors will be written- Since:
- 4.9
-
getLogOutputEncodingCharset
Get the log output encoding specified in the repository'si18n.logOutputEncodingconfiguration.- Parameters:
repository- the repository.- Returns:
- Charset corresponding to
i18n.logOutputEncoding, orUTF_8.
-
init
Initialize the command to work with a repository.- Parameters:
repository- the opened repository that the command should work on.gitDir- value of the--git-dircommand line option, ifrepositoryis null.
-
execute
Parse arguments and run this command.- Parameters:
args- command line arguments passed after the command name.- Throws:
Exception- an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.
-
parseArguments
Parses the command line arguments prior to running.This method should only be invoked by
execute(String[]), prior to callingrun(). The default implementation parses all arguments into this object's instance fields.- Parameters:
args- the arguments supplied on the command line, if any.- Throws:
IOException
-
printUsageAndExit
Print the usage line- Parameters:
clp- aCmdLineParserobject.- Throws:
IOException
-
printUsageAndExit
Print an error message and the usage line- Parameters:
message- aStringobject.clp- aCmdLineParserobject.- Throws:
IOException
-
printUsage
Print usage help text.- Parameters:
message- non nullclp- parser used to print options- Throws:
IOException- Since:
- 4.2
-
getErrorWriter
Get error writer- Returns:
- error writer, typically this is standard error.
- Since:
- 4.2
-
getOutputWriter
Get output writer- Returns:
- output writer, typically this is standard output.
- Since:
- 4.9
-
getResourceBundle
Get resource bundle with localized texts- Returns:
- the resource bundle that will be passed to args4j for purpose of string localization
-
run
Perform the actions of this command.This method should only be invoked by
execute(String[]).- Throws:
Exception- an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.
-
getRepository
Get the repository- Returns:
- the repository this command accesses.
-
resolve
- Throws:
IOException
-
die
Exit the command with an error message- Parameters:
why- textual explanation- Returns:
- a runtime exception the caller is expected to throw
-
die
Exit the command with an error message and an exception- Parameters:
why- textual explanationcause- why the command has failed.- Returns:
- a runtime exception the caller is expected to throw
-
die
Exit the command- Parameters:
aborted- boolean indicating that the execution has been aborted before running- Returns:
- a runtime exception the caller is expected to throw
- Since:
- 3.4
-
die
Exit the command- Parameters:
aborted- boolean indicating that the execution has been aborted before runningcause- why the command has failed.- Returns:
- a runtime exception the caller is expected to throw
- Since:
- 4.2
-
abbreviateRef
-
containsHelp
Check if the arguments contain a help option- Parameters:
args- non null- Returns:
- true if the given array contains help option
- Since:
- 4.2
-