Change customCommand fields to pointers

This allows us to tell whether they appear in the user's config file, which we
will need later in this branch.
This commit is contained in:
Stefan Haller 2025-02-24 08:46:55 +01:00
parent 0df5e08828
commit f93948cb23
4 changed files with 16 additions and 11 deletions

View file

@ -619,7 +619,8 @@ type CustomCommand struct {
// The command to run (using Go template syntax for placeholder values)
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
// If true, run the command in a subprocess (e.g. if the command requires user input)
Subprocess bool `yaml:"subprocess"`
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
Subprocess *bool `yaml:"subprocess"`
// A list of prompts that will request user input before running the final command
Prompts []CustomCommandPrompt `yaml:"prompts"`
// Text to display while waiting for command to finish
@ -627,13 +628,16 @@ type CustomCommand struct {
// Label for the custom command when displayed in the keybindings menu
Description string `yaml:"description"`
// If true, stream the command's output to the Command Log panel
Stream bool `yaml:"stream"`
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
Stream *bool `yaml:"stream"`
// If true, show the command's output in a popup within Lazygit
ShowOutput bool `yaml:"showOutput"`
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
ShowOutput *bool `yaml:"showOutput"`
// The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title.
OutputTitle string `yaml:"outputTitle"`
// Actions to take after the command has completed
After CustomCommandAfterHook `yaml:"after"`
// [dev] Pointer so that we can tell whether it appears in the config file
After *CustomCommandAfterHook `yaml:"after"`
}
type CustomCommandPrompt struct {

View file

@ -261,7 +261,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
cmdObj := self.c.OS().Cmd.NewShell(cmdStr)
if customCommand.Subprocess {
if customCommand.Subprocess != nil && *customCommand.Subprocess {
return self.c.RunSubprocessAndRefresh(cmdObj)
}
@ -273,7 +273,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
return self.c.WithWaitingStatus(loadingText, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.CustomCommand)
if customCommand.Stream {
if customCommand.Stream != nil && *customCommand.Stream {
cmdObj.StreamOutput()
}
output, err := cmdObj.RunWithOutput()
@ -283,14 +283,14 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
}
if err != nil {
if customCommand.After.CheckForConflicts {
if customCommand.After != nil && customCommand.After.CheckForConflicts {
return self.mergeAndRebaseHelper.CheckForConflicts(err)
}
return err
}
if customCommand.ShowOutput {
if customCommand.ShowOutput != nil && *customCommand.ShowOutput {
if strings.TrimSpace(output) == "" {
output = self.c.Tr.EmptyOutput
}

View file

@ -19,7 +19,7 @@ var CheckForConflicts = NewIntegrationTest(NewIntegrationTestArgs{
Key: "m",
Context: "localBranches",
Command: "git merge {{ .SelectedLocalBranch.Name | quote }}",
After: config.CustomCommandAfterHook{
After: &config.CustomCommandAfterHook{
CheckForConflicts: true,
},
},

View file

@ -15,18 +15,19 @@ var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{
shell.EmptyCommit("my change")
},
SetupConfig: func(cfg *config.AppConfig) {
trueVal := true
cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
{
Key: "X",
Context: "commits",
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
ShowOutput: true,
ShowOutput: &trueVal,
},
{
Key: "Y",
Context: "commits",
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
ShowOutput: true,
ShowOutput: &trueVal,
OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}",
},
}