Better custom commands interface
Is your feature request related to a problem? Please describe. If you go to the custom commands compendium you'll see examples like this:
- key : 'N'
description: 'create annotated tag'
command: "git tag -a {{index .PromptResponses 0}} -m \"{{index .PromptResponses 1}}\""
context: 'tags'
prompts:
- type: 'input'
title: 'Annotated tag name:'
- type: 'input'
title: 'Annotated tag message:'
Referring to prompt responses by index isn't great for a few reasons:
- it's not obvious what prompts are referred to until you read them
- it introduces an order dependence which makes it harder to insert new prompts or shuffle prompts around
- it prevents us from having more complex custom command flows with branching logic
Describe the solution you'd like Allow a name to be specified in the prompt so that you can refer to the prompt by name:
- key : 'N'
description: 'create annotated tag'
command: "git tag -a {{ .Form.tagName }} -m \"{{ .Form.tagMessage }}\""
context: 'tags'
prompts:
- type: 'input'
title: 'Annotated tag name:'
key: 'tagName'
- type: 'input'
title: 'Annotated tag message:'
key: 'tagMessage'
For an example of what this might look like see this playground link
Then we'd remove all mention of the PromptResponses approach from documentation, except for the sake of saying it's deprecated. We'll keep it in the code though for backwards compatibility
Describe alternatives you've considered It would be good if we could keep using the name PromptResponses. I'm not sure if I actually like 'Form'. But I'm pretty sure trying to re-use PromptResponses will be more trouble than it's worth.
Additional context
Relevant files:
pkg/gui/services/custom_commands/handler_creator.go:44. In the call method we write to promptResponses each time the user responds to a prompt (specifically in the wrappedF function). We can have a separate variable called form which is a map[string]string which we also write to, using the key of the prompt.
This file also defines CustomCommandObjects which we'll need to add the Form field to, alongside PromptResponses.
Hello @jesseduffield, can I help on this?
@Mihai22125 you certainly can. Let me know if you need any guidance. The only file that needs to change (as far as I can tell) is pkg/gui/services/custom_commands/handler_creator.go so I'd have a look at that.
Sure, I'll ping you if I get stuck on something. Thanks!