mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-10 20:05:50 +02:00
feat: add executeCommand Prompt
This commit is contained in:
parent
c03b892270
commit
f7b8b428ae
3 changed files with 25 additions and 3 deletions
|
@ -634,7 +634,7 @@ type CustomCommand struct {
|
|||
}
|
||||
|
||||
type CustomCommandPrompt struct {
|
||||
// One of: 'input' | 'menu' | 'confirm' | 'menuFromCommand'
|
||||
// One of: 'input' | 'menu' | 'confirm' | 'menuFromCommand' | 'executeCommand'
|
||||
Type string `yaml:"type"`
|
||||
// Used to reference the entered value from within the custom command. E.g. a prompt with `key: 'Branch'` can be referred to as `{{.Form.Branch}}` in the command
|
||||
Key string `yaml:"key"`
|
||||
|
@ -657,7 +657,8 @@ type CustomCommandPrompt struct {
|
|||
Options []CustomCommandMenuOption `yaml:"options"`
|
||||
|
||||
// The command to run to generate menu options
|
||||
// Only for menuFromCommand prompts.
|
||||
// or run by executeCommand
|
||||
// Only for menuFromCommand prompts and executeCommand prompts.
|
||||
Command string `yaml:"command" jsonschema:"example=git fetch {{.Form.Remote}} {{.Form.Branch}} && git checkout FETCH_HEAD"`
|
||||
// The regexp to run specifying groups which are going to be kept from the command's output.
|
||||
// Only for menuFromCommand prompts.
|
||||
|
|
|
@ -103,8 +103,16 @@ func (self *HandlerCreator) call(customCommand config.CustomCommand) func() erro
|
|||
}
|
||||
return self.confirmPrompt(resolvedPrompt, g)
|
||||
}
|
||||
case "executeCommand":
|
||||
f = func() error {
|
||||
resolvedPrompt, err := self.resolver.resolvePrompt(&prompt, resolveTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return self.executeCommand(resolvedPrompt, wrappedF)
|
||||
}
|
||||
default:
|
||||
return errors.New("custom command prompt must have a type of 'input', 'menu', 'menuFromCommand', or 'confirm'")
|
||||
return errors.New("custom command prompt must have a type of 'input', 'menu', 'menuFromCommand', 'executeCommand' or 'confirm'")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,6 +120,15 @@ func (self *HandlerCreator) call(customCommand config.CustomCommand) func() erro
|
|||
}
|
||||
}
|
||||
|
||||
func (self *HandlerCreator) executeCommand(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
|
||||
output, err := self.c.OS().Cmd.NewShell(prompt.Command).RunWithOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return wrappedF(output)
|
||||
}
|
||||
|
||||
func (self *HandlerCreator) inputPrompt(prompt *config.CustomCommandPrompt, wrappedF func(string) error) error {
|
||||
findSuggestionsFn, err := self.generateFindSuggestionsFunc(prompt)
|
||||
if err != nil {
|
||||
|
|
|
@ -186,6 +186,10 @@ type PromptOpts struct {
|
|||
Mask bool
|
||||
}
|
||||
|
||||
type ExecuteCommandOpts struct {
|
||||
Command string
|
||||
}
|
||||
|
||||
type MenuSection struct {
|
||||
Title string
|
||||
Column int // The column that this section title should be aligned with
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue