Documentation
¶
Index ¶
- Constants
- Variables
- func CommonCmdServEnvs() []string
- func CommonGitCmdEnvs() []string
- func ConcatenateError(err error, stderr string) error
- func HomeDir() string
- func IsErrorExitCode(err error, code int) bool
- func SetDefaultCommandExecutionTimeout(timeout time.Duration)
- func SetExecutablePath(path string) error
- type Command
- func (c *Command) AddArguments(args ...internal.CmdArg) *Command
- func (c *Command) AddConfig(key, value string) *Command
- func (c *Command) AddDashesAndList(list ...string) *Command
- func (c *Command) AddDynamicArguments(args ...string) *Command
- func (c *Command) AddOptionFormat(opt string, args ...any) *Command
- func (c *Command) AddOptionValues(opt internal.CmdArg, args ...string) *Command
- func (c *Command) LogString() string
- func (c *Command) ProcessState() string
- func (c *Command) Run(ctx context.Context) error
- func (c *Command) RunStdBytes(ctx context.Context) (stdout, stderr []byte, runErr RunStdError)
- func (c *Command) RunStdString(ctx context.Context) (stdout, stderr string, runErr RunStdError)
- func (c *Command) WithDir(dir string) *Command
- func (c *Command) WithEnv(env []string) *Command
- func (c *Command) WithParentCallerInfo(optInfo ...string) *Command
- func (c *Command) WithPipelineFunc(f func(context.Context, context.CancelFunc) error) *Command
- func (c *Command) WithStderr(stderr io.Writer) *Command
- func (c *Command) WithStdin(stdin io.Reader) *Command
- func (c *Command) WithStdout(stdout io.Writer) *Command
- func (c *Command) WithTimeout(timeout time.Duration) *Command
- func (c *Command) WithUseContextTimeout(useContextTimeout bool) *Command
- type RunStdError
- type TrustedCmdArgs
Constants ¶
const DefaultLocale = "C"
DefaultLocale is the default LC_ALL to run git commands in.
Variables ¶
var GitExecutable = "git" // the command name of git, will be updated to an absolute path during initialization
Functions ¶
func CommonCmdServEnvs ¶
func CommonCmdServEnvs() []string
CommonCmdServEnvs is like CommonGitCmdEnvs, but it only returns minimal required environment variables for the "gitea serv" command
func CommonGitCmdEnvs ¶
func CommonGitCmdEnvs() []string
CommonGitCmdEnvs returns the common environment variables for a "git" command.
func ConcatenateError ¶
ConcatenateError concatenats an error with stderr string
func HomeDir ¶
func HomeDir() string
HomeDir is the home dir for git to store the global config file used by Gitea internally
func SetDefaultCommandExecutionTimeout ¶
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a command with its subcommands or arguments.
func NewCommand ¶
NewCommand creates and returns a new Git Command based on given command and arguments. Each argument should be safe to be trusted. User-provided arguments should be passed to AddDynamicArguments instead.
func (*Command) AddArguments ¶
AddArguments adds new git arguments (option/value) to the command. It only accepts string literals, or trusted CmdArg. Type CmdArg is in the internal package, so it can not be used outside of this package directly, it makes sure that user-provided arguments won't cause RCE risks. User-provided arguments should be passed by other AddXxx functions
func (*Command) AddDashesAndList ¶
AddDashesAndList adds the "--" and then add the list as arguments, it's usually for adding file list At the moment, this function can be only called once, maybe in future it can be refactored to support multiple calls (if necessary)
func (*Command) AddDynamicArguments ¶
AddDynamicArguments adds new dynamic argument values to the command. The arguments may come from user input and can not be trusted, so no leading '-' is allowed to avoid passing options. TODO: in the future, this function can be renamed to AddArgumentValues
func (*Command) AddOptionFormat ¶
AddOptionFormat adds a new option with a format string and arguments For example: AddOptionFormat("--opt=%s %s", val1, val2) means 1 argument: {"--opt=val1 val2"}.
func (*Command) AddOptionValues ¶
AddOptionValues adds a new option with a list of non-option values For example: AddOptionValues("--opt", val) means 2 arguments: {"--opt", val}. The values are treated as dynamic argument values. It equals to: AddArguments("--opt") then AddDynamicArguments(val).
func (*Command) RunStdBytes ¶
func (c *Command) RunStdBytes(ctx context.Context) (stdout, stderr []byte, runErr RunStdError)
RunStdBytes runs the command and returns stdout/stderr as bytes. and store stderr to returned error (err combined with stderr).
func (*Command) RunStdString ¶
func (c *Command) RunStdString(ctx context.Context) (stdout, stderr string, runErr RunStdError)
RunStdString runs the command and returns stdout/stderr as string. and store stderr to returned error (err combined with stderr).
func (*Command) WithParentCallerInfo ¶
WithParentCallerInfo can be used to set the caller info (usually function name) of the parent function of the caller. For most cases, "Run" family functions can get its caller info automatically But if you need to call "Run" family functions in a wrapper function: "FeatureFunc -> GeneralWrapperFunc -> RunXxx", then you can to call this function in GeneralWrapperFunc to set the caller info of FeatureFunc. The caller info can only be set once.
func (*Command) WithPipelineFunc ¶
type TrustedCmdArgs ¶
TrustedCmdArgs returns the trusted arguments for git command. It's mainly for passing user-provided and trusted arguments to git command In most cases, it shouldn't be used. Use AddXxx function instead
func ToTrustedCmdArgs ¶
func ToTrustedCmdArgs(args []string) TrustedCmdArgs
ToTrustedCmdArgs converts a list of strings (trusted as argument) to TrustedCmdArgs In most cases, it shouldn't be used. Use NewCommand().AddXxx() function instead
Source Files
¶
- command.go
- env.go
- utils.go