2022-08-09 19:52:19 +03:00
|
|
|
package custom_commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/config"
|
|
|
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
|
|
|
)
|
|
|
|
|
|
|
|
var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
|
|
|
|
Description: "Using a custom command reffering prompt responses by name",
|
|
|
|
ExtraCmdArgs: "",
|
|
|
|
Skip: false,
|
|
|
|
SetupRepo: func(shell *Shell) {
|
|
|
|
shell.EmptyCommit("blah")
|
|
|
|
},
|
|
|
|
SetupConfig: func(cfg *config.AppConfig) {
|
|
|
|
cfg.UserConfig.CustomCommands = []config.CustomCommand{
|
|
|
|
{
|
|
|
|
Key: "a",
|
|
|
|
Context: "files",
|
2022-10-02 18:42:51 -07:00
|
|
|
Command: `echo {{.Form.FileContent | quote}} > {{.Form.FileName | quote}}`,
|
2022-08-09 19:52:19 +03:00
|
|
|
Prompts: []config.CustomCommandPrompt{
|
|
|
|
{
|
|
|
|
Key: "FileName",
|
|
|
|
Type: "input",
|
|
|
|
Title: "Enter a file name",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "FileContent",
|
|
|
|
Type: "menu",
|
|
|
|
Title: "Choose file content",
|
|
|
|
Options: []config.CustomCommandMenuOption{
|
|
|
|
{
|
|
|
|
Name: "foo",
|
|
|
|
Description: "Foo",
|
|
|
|
Value: "FOO",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "bar",
|
|
|
|
Description: "Bar",
|
2022-10-01 20:51:44 +09:00
|
|
|
Value: `"BAR"`,
|
2022-08-09 19:52:19 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "baz",
|
|
|
|
Description: "Baz",
|
|
|
|
Value: "BAZ",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Type: "confirm",
|
|
|
|
Title: "Are you sure?",
|
|
|
|
Body: "Are you REALLY sure you want to make this file? Up to you buddy.",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Run: func(
|
|
|
|
shell *Shell,
|
|
|
|
input *Input,
|
|
|
|
assert *Assert,
|
|
|
|
keys config.KeybindingConfig,
|
|
|
|
) {
|
2022-12-27 15:22:31 +11:00
|
|
|
assert.Model().WorkingTreeFileCount(0)
|
2022-08-09 19:52:19 +03:00
|
|
|
|
2022-12-24 17:48:57 +11:00
|
|
|
input.Press("a")
|
2022-08-09 19:52:19 +03:00
|
|
|
|
2022-12-27 11:21:44 +11:00
|
|
|
input.Prompt().Title(Equals("Enter a file name")).Type("my file").Confirm()
|
2022-08-09 19:52:19 +03:00
|
|
|
|
2022-12-27 11:34:41 +11:00
|
|
|
input.Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm()
|
2022-08-09 19:52:19 +03:00
|
|
|
|
2022-12-27 11:21:44 +11:00
|
|
|
input.Confirmation().
|
2022-12-27 10:50:00 +11:00
|
|
|
Title(Equals("Are you sure?")).
|
|
|
|
Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
|
|
|
|
Confirm()
|
2022-08-09 19:52:19 +03:00
|
|
|
|
2022-12-27 15:22:31 +11:00
|
|
|
assert.Model().WorkingTreeFileCount(1)
|
2022-12-27 15:07:11 +11:00
|
|
|
assert.Views().Current().SelectedLine(Contains("my file"))
|
|
|
|
assert.Views().Main().Content(Contains(`"BAR"`))
|
2022-08-09 19:52:19 +03:00
|
|
|
},
|
|
|
|
})
|