custom_commands

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BasicCmdAtRuntime = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command provided at runtime to create a new file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press(keys.Universal.ExecuteCustomCommand)

		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			Type("touch file.txt").
			Confirm()

		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file.txt"),
			)
	},
})
View Source
var BasicCmdFromConfig = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command to create a new file",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: "touch myfile",
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a").
			Lines(
				Contains("myfile"),
			)
	},
})
View Source
var CheckForConflicts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Run a command and check for conflicts after",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shared.MergeConflictsSetup(shell)
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "m",
				Context: "localBranches",
				Command: "git merge {{ .SelectedLocalBranch.Name | quote }}",
				After: config.CustomCommandAfterHook{
					CheckForConflicts: true,
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			TopLines(
				Contains("first-change-branch"),
				Contains("second-change-branch"),
			).
			NavigateToLine(Contains("second-change-branch")).
			Press("m")

		t.Common().AcknowledgeConflicts()
	},
})
View Source
var ComplexCmdAtRuntime = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command provided at runtime to create a new file, via a shell command. We invoke custom commands through a shell already. This test proves that we can run a shell within a shell, which requires complex escaping.",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press(keys.Universal.ExecuteCustomCommand)

		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			Type("sh -c \"touch file.txt\"").
			Confirm()

		t.GlobalPress(keys.Files.RefreshFiles)

		t.Views().Files().
			IsFocused().
			Lines(
				Contains("file.txt"),
			)
	},
})
View Source
var FormPrompts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command reffering prompt responses by name",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo {{.Form.FileContent | quote}} > {{.Form.FileName | quote}}`,
				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",
								Value:       `"BAR"`,
							},
							{
								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(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a")

		t.ExpectPopup().Prompt().Title(Equals("Enter a file name")).Type("my file").Confirm()

		t.ExpectPopup().Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Are you sure?")).
			Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
			Confirm()

		t.Views().Files().
			Lines(
				Contains("my file").IsSelected(),
			)

		t.Views().Main().Content(Contains(`"BAR"`))
	},
})
View Source
var History = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Test that the custom commands history is saved correctly",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo:    func(shell *Shell) {},
	SetupConfig:  func(cfg *config.AppConfig) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			Type("echo 1").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(Contains("1")).
			Type("echo 2").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(

				Contains("2"),
				Contains("1"),
			).
			Type("echo 3").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(
				Contains("3"),
				Contains("2"),
				Contains("1"),
			).
			Type("echo 1").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(
				Contains("1"),
				Contains("3"),
				Contains("2"),
			)
	},
})
View Source
var MenuFromCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using menuFromCommand prompt type",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("foo").
			EmptyCommit("bar").
			EmptyCommit("baz").
			NewBranch("feature/foo")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `echo "{{index .PromptResponses 0}} {{index .PromptResponses 1}} {{ .SelectedLocalBranch.Name }}" > output.txt`,
				Prompts: []config.CustomCommandPrompt{
					{
						Type:        "menuFromCommand",
						Title:       "Choose commit message",
						Command:     `git log --oneline --pretty=%B`,
						Filter:      `(?P<commit_message>.*)`,
						ValueFormat: `{{ .commit_message }}`,
						LabelFormat: `{{ .commit_message | yellow }}`,
					},
					{
						Type:         "input",
						Title:        "Description",
						InitialValue: `{{ if .SelectedLocalBranch.Name }}Branch: #{{ .SelectedLocalBranch.Name }}{{end}}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty()

		t.Views().Branches().
			Focus().
			Press("a")

		t.ExpectPopup().Menu().Title(Equals("Choose commit message")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Prompt().Title(Equals("Description")).Type(" my branch").Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("output.txt").IsSelected(),
			)

		t.Views().Main().Content(Contains("bar Branch: #feature/foo my branch feature/foo"))
	},
})
View Source
var MenuFromCommandsOutput = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using prompt response in menuFromCommand entries",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.
			EmptyCommit("foo").
			NewBranch("feature/foo").
			EmptyCommit("bar").
			NewBranch("feature/bar").
			EmptyCommit("baz")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: "git checkout {{ index .PromptResponses 1 }}",
				Prompts: []config.CustomCommandPrompt{
					{
						Type:         "input",
						Title:        "Which git command do you want to run?",
						InitialValue: "branch",
					},
					{
						Type:        "menuFromCommand",
						Title:       "Branch:",
						Command:     `git {{ index .PromptResponses 0 }} --format='%(refname:short)'`,
						Filter:      "(?P<branch>.*)",
						ValueFormat: `{{ .branch }}`,
						LabelFormat: `{{ .branch | green }}`,
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Git().CurrentBranchName("feature/bar")

		t.Views().Branches().
			Focus().
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Which git command do you want to run?")).
			InitialText(Equals("branch")).
			Confirm()

		t.ExpectPopup().Menu().Title(Equals("Branch:")).Select(Equals("master")).Confirm()

		t.Git().CurrentBranchName("master")
	},
})
View Source
var MultiplePrompts = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command with multiple prompts",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "files",
				Command: `echo "{{index .PromptResponses 1}}" > {{index .PromptResponses 0}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Type:  "input",
						Title: "Enter a file name",
					},
					{
						Type:  "menu",
						Title: "Choose file content",
						Options: []config.CustomCommandMenuOption{
							{
								Name:        "foo",
								Description: "Foo",
								Value:       "FOO",
							},
							{
								Name:        "bar",
								Description: "Bar",
								Value:       "BAR",
							},
							{
								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(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Files().
			IsEmpty().
			IsFocused().
			Press("a")

		t.ExpectPopup().Prompt().Title(Equals("Enter a file name")).Type("myfile").Confirm()

		t.ExpectPopup().Menu().Title(Equals("Choose file content")).Select(Contains("bar")).Confirm()

		t.ExpectPopup().Confirmation().
			Title(Equals("Are you sure?")).
			Content(Equals("Are you REALLY sure you want to make this file? Up to you buddy.")).
			Confirm()

		t.Views().Files().
			Focus().
			Lines(
				Contains("myfile").IsSelected(),
			)

		t.Views().Main().Content(Contains("BAR"))
	},
})
View Source
var OmitFromHistory = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Omitting a runtime custom command from history if it begins with space",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			Type("echo aubergine").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(Contains("aubergine")).
			SuggestionLines(DoesNotContain("tangerine")).
			Type(" echo tangerine").
			Confirm()

		t.GlobalPress(keys.Universal.ExecuteCustomCommand)
		t.ExpectPopup().Prompt().
			Title(Equals("Custom command:")).
			SuggestionLines(Contains("aubergine")).
			SuggestionLines(DoesNotContain("tangerine")).
			Cancel()
	},
})
View Source
var SuggestionsCommand = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command that uses a suggestions command in a prompt step",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-one")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-two")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-three")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-four")
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `git checkout {{.Form.Branch}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Branch",
						Type:  "input",
						Title: "Enter a branch name",
						Suggestions: config.CustomCommandSuggestions{
							Command: "git branch --format='%(refname:short)'",
						},
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-four").IsSelected(),
				Contains("branch-three"),
				Contains("branch-two"),
				Contains("branch-one"),
			).
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Enter a branch name")).
			Type("three").
			SuggestionLines(Contains("branch-three")).
			ConfirmFirstSuggestion()

		t.Views().Branches().
			Lines(
				Contains("branch-three"),
				Contains("branch-four").IsSelected(),
				Contains("branch-two"),
				Contains("branch-one"),
			)
	},
})
View Source
var SuggestionsPreset = NewIntegrationTest(NewIntegrationTestArgs{
	Description:  "Using a custom command that uses a suggestions preset in a prompt step",
	ExtraCmdArgs: []string{},
	Skip:         false,
	SetupRepo: func(shell *Shell) {
		shell.NewBranch("branch-one")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-two")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-three")
		shell.EmptyCommit("blah")
		shell.NewBranch("branch-four")
		shell.EmptyCommit("blah")
	},
	SetupConfig: func(cfg *config.AppConfig) {
		cfg.UserConfig.CustomCommands = []config.CustomCommand{
			{
				Key:     "a",
				Context: "localBranches",
				Command: `git checkout {{.Form.Branch}}`,
				Prompts: []config.CustomCommandPrompt{
					{
						Key:   "Branch",
						Type:  "input",
						Title: "Enter a branch name",
						Suggestions: config.CustomCommandSuggestions{
							Preset: "branches",
						},
					},
				},
			},
		}
	},
	Run: func(t *TestDriver, keys config.KeybindingConfig) {
		t.Views().Branches().
			Focus().
			Lines(
				Contains("branch-four").IsSelected(),
				Contains("branch-three"),
				Contains("branch-two"),
				Contains("branch-one"),
			).
			Press("a")

		t.ExpectPopup().Prompt().
			Title(Equals("Enter a branch name")).
			Type("three").
			SuggestionLines(Contains("branch-three")).
			ConfirmFirstSuggestion()

		t.Views().Branches().
			Lines(
				Contains("branch-three"),
				Contains("branch-four").IsSelected(),
				Contains("branch-two"),
				Contains("branch-one"),
			)
	},
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL