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 class
Exception thrown byTextBuiltin
if it proceeds 'help' option -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RevWalk
RevWalk used during command line parsing, if it was required.private String
protected Repository
Git repository the command was invoked within.protected OutputStream
Error output stream, typically this is standard error.protected ThrowingPrintWriter
Error writer, typically this is standard error.protected String
Directory supplied via --git-dir command line option.private boolean
protected InputStream
Input stream, typically this is standard input.protected OutputStream
Stream to output to, typically this is standard output.protected ThrowingPrintWriter
Writer to output to, typically this is standard output.private SshDriver
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) String
abbreviateRef
(String dst, boolean abbreviateRemote) static boolean
containsHelp
(String[] args) Check if the arguments contain a help optionprotected static Die
die
(boolean aborted) Exit the commandprotected static Die
Exit the commandprotected static Die
Exit the command with an error messageprotected static Die
Exit the command with an error message and an exceptionfinal void
Parse arguments and run this command.Get error writerprivate Charset
getLogOutputEncodingCharset
(Repository repository) Get the log output encoding specified in the repository'si18n.logOutputEncoding
configuration.Get output writerGet the repositoryprotected ResourceBundle
Get resource bundle with localized textsprotected void
init
(Repository repository, String gitDir) Initialize the command to work with a repository.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.protected void
parseArguments
(String[] args) Parses the command line arguments prior to running.protected void
printUsage
(String message, CmdLineParser clp) Print usage help text.void
printUsageAndExit
(String message, CmdLineParser clp) Print an error message and the usage linevoid
Print the usage lineprotected boolean
If this command requires a repository.(package private) ObjectId
protected abstract void
run()
Perform the actions of this command.(package private) final void
setCommandName
(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-dir
command line option, ifrepository
is 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.logOutputEncoding
configuration.- 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-dir
command line option, ifrepository
is 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
- aCmdLineParser
object.- Throws:
IOException
-
printUsageAndExit
Print an error message and the usage line- Parameters:
message
- aString
object.clp
- aCmdLineParser
object.- 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
-