mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Support using command output directly in menuFromCommand custom command prompt
The menuFromCommand option is a little complicated, so I'm adding an easy way to just use the command output directly, where each line becomes a suggestion, as-is. Now that we support suggestions in the input prompt, there's less of a need for menuFromCommand, but it probably still serves some purpose. In future I want to support this filter/valueFormat/labelFormat thing for suggestions too. I would like to think a little more about the interface though: is using a regex like we currently do really the simplest approach?
This commit is contained in:
@ -14,7 +14,7 @@ func TestMenuGenerator(t *testing.T) {
|
||||
filter string
|
||||
valueFormat string
|
||||
labelFormat string
|
||||
test func([]*commandMenuEntry, error)
|
||||
test func([]*commandMenuItem, error)
|
||||
}
|
||||
|
||||
scenarios := []scenario{
|
||||
@ -24,7 +24,7 @@ func TestMenuGenerator(t *testing.T) {
|
||||
"(?P<remote>[a-z_]+)/(?P<branch>.*)",
|
||||
"{{ .branch }}",
|
||||
"Remote: {{ .remote }}",
|
||||
func(actualEntry []*commandMenuEntry, err error) {
|
||||
func(actualEntry []*commandMenuItem, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "pr-1", actualEntry[0].value)
|
||||
assert.EqualValues(t, "Remote: upstream", actualEntry[0].label)
|
||||
@ -36,7 +36,7 @@ func TestMenuGenerator(t *testing.T) {
|
||||
"(?P<remote>[a-z]*)/(?P<branch>.*)",
|
||||
"{{ .branch }}|{{ .remote }}",
|
||||
"",
|
||||
func(actualEntry []*commandMenuEntry, err error) {
|
||||
func(actualEntry []*commandMenuItem, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value)
|
||||
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].label)
|
||||
@ -48,12 +48,36 @@ func TestMenuGenerator(t *testing.T) {
|
||||
"(?P<remote>[a-z]*)/(?P<branch>.*)",
|
||||
"{{ .group_2 }}|{{ .group_1 }}",
|
||||
"Remote: {{ .group_1 }}",
|
||||
func(actualEntry []*commandMenuEntry, err error) {
|
||||
func(actualEntry []*commandMenuItem, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value)
|
||||
assert.EqualValues(t, "Remote: upstream", actualEntry[0].label)
|
||||
},
|
||||
},
|
||||
{
|
||||
"No named groups",
|
||||
"upstream/pr-1",
|
||||
"([a-z]*)/(.*)",
|
||||
"{{ .group_2 }}|{{ .group_1 }}",
|
||||
"Remote: {{ .group_1 }}",
|
||||
func(actualEntry []*commandMenuItem, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "pr-1|upstream", actualEntry[0].value)
|
||||
assert.EqualValues(t, "Remote: upstream", actualEntry[0].label)
|
||||
},
|
||||
},
|
||||
{
|
||||
"No filter",
|
||||
"upstream/pr-1",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
func(actualEntry []*commandMenuItem, err error) {
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, "upstream/pr-1", actualEntry[0].value)
|
||||
assert.EqualValues(t, "upstream/pr-1", actualEntry[0].label)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, s := range scenarios {
|
||||
|
Reference in New Issue
Block a user