Skip to content

Commit f93948c

Browse files
committed
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.
1 parent 0df5e08 commit f93948c

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

pkg/config/user_config.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,21 +619,25 @@ type CustomCommand struct {
619619
// The command to run (using Go template syntax for placeholder values)
620620
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
621621
// If true, run the command in a subprocess (e.g. if the command requires user input)
622-
Subprocess bool `yaml:"subprocess"`
622+
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
623+
Subprocess *bool `yaml:"subprocess"`
623624
// A list of prompts that will request user input before running the final command
624625
Prompts []CustomCommandPrompt `yaml:"prompts"`
625626
// Text to display while waiting for command to finish
626627
LoadingText string `yaml:"loadingText" jsonschema:"example=Loading..."`
627628
// Label for the custom command when displayed in the keybindings menu
628629
Description string `yaml:"description"`
629630
// If true, stream the command's output to the Command Log panel
630-
Stream bool `yaml:"stream"`
631+
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
632+
Stream *bool `yaml:"stream"`
631633
// If true, show the command's output in a popup within Lazygit
632-
ShowOutput bool `yaml:"showOutput"`
634+
// [dev] Pointer to bool so that we can distinguish unset (nil) from false.
635+
ShowOutput *bool `yaml:"showOutput"`
633636
// The title to display in the popup panel if showOutput is true. If left unset, the command will be used as the title.
634637
OutputTitle string `yaml:"outputTitle"`
635638
// Actions to take after the command has completed
636-
After CustomCommandAfterHook `yaml:"after"`
639+
// [dev] Pointer so that we can tell whether it appears in the config file
640+
After *CustomCommandAfterHook `yaml:"after"`
637641
}
638642

639643
type CustomCommandPrompt struct {

pkg/gui/services/custom_commands/handler_creator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
261261

262262
cmdObj := self.c.OS().Cmd.NewShell(cmdStr)
263263

264-
if customCommand.Subprocess {
264+
if customCommand.Subprocess != nil && *customCommand.Subprocess {
265265
return self.c.RunSubprocessAndRefresh(cmdObj)
266266
}
267267

@@ -273,7 +273,7 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
273273
return self.c.WithWaitingStatus(loadingText, func(gocui.Task) error {
274274
self.c.LogAction(self.c.Tr.Actions.CustomCommand)
275275

276-
if customCommand.Stream {
276+
if customCommand.Stream != nil && *customCommand.Stream {
277277
cmdObj.StreamOutput()
278278
}
279279
output, err := cmdObj.RunWithOutput()
@@ -283,14 +283,14 @@ func (self *HandlerCreator) finalHandler(customCommand config.CustomCommand, ses
283283
}
284284

285285
if err != nil {
286-
if customCommand.After.CheckForConflicts {
286+
if customCommand.After != nil && customCommand.After.CheckForConflicts {
287287
return self.mergeAndRebaseHelper.CheckForConflicts(err)
288288
}
289289

290290
return err
291291
}
292292

293-
if customCommand.ShowOutput {
293+
if customCommand.ShowOutput != nil && *customCommand.ShowOutput {
294294
if strings.TrimSpace(output) == "" {
295295
output = self.c.Tr.EmptyOutput
296296
}

pkg/integration/tests/custom_commands/check_for_conflicts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var CheckForConflicts = NewIntegrationTest(NewIntegrationTestArgs{
1919
Key: "m",
2020
Context: "localBranches",
2121
Command: "git merge {{ .SelectedLocalBranch.Name | quote }}",
22-
After: config.CustomCommandAfterHook{
22+
After: &config.CustomCommandAfterHook{
2323
CheckForConflicts: true,
2424
},
2525
},

pkg/integration/tests/custom_commands/show_output_in_panel.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ var ShowOutputInPanel = NewIntegrationTest(NewIntegrationTestArgs{
1515
shell.EmptyCommit("my change")
1616
},
1717
SetupConfig: func(cfg *config.AppConfig) {
18+
trueVal := true
1819
cfg.GetUserConfig().CustomCommands = []config.CustomCommand{
1920
{
2021
Key: "X",
2122
Context: "commits",
2223
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
23-
ShowOutput: true,
24+
ShowOutput: &trueVal,
2425
},
2526
{
2627
Key: "Y",
2728
Context: "commits",
2829
Command: "printf '%s' '{{ .SelectedLocalCommit.Name }}'",
29-
ShowOutput: true,
30+
ShowOutput: &trueVal,
3031
OutputTitle: "Subject of commit {{ .SelectedLocalCommit.Hash }}",
3132
},
3233
}

0 commit comments

Comments
 (0)