Skip to content

Completion does not work correctly if there is a @ symbol in the string #2144

Open
@Bernigend

Description

@Bernigend

Summary

If the flag can take values that contain the "@" character, then value substitution stops working after entering this character.

Examples

All available values

[$] clddev systemctl status2 --unit
group1@subunit   group2@subunit2  unit1            unit1_long

Value which starts with group

[$] clddev systemctl status2 --unit group
group1@subunit   group2@subunit2

Value with symbol @

[$] clddev systemctl status2 --unit group1@sub

And it is empty

How to reproduce

package status2

import (
	"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
	cmd := &cobra.Command{
		Use:  "status2",
		RunE: Handler,
	}

	cmd.Flags().String("unit", "", "systemctl status unit")
	cmd.RegisterFlagCompletionFunc("unit", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		return []string{
			"unit1",
			"unit1_long",
			"group1@subunit",
			"group2@subunit2",
		}, 0
	})

	return cmd
}

func Handler(cmd *cobra.Command, args []string) error {
	return nil
}

Log

========= starting completion logic ==========
cur is , words[*] is clddev systemctl status2 --unit , #words[@] is 5, cword is 4
Truncated words[*]: clddev systemctl status2 --unit ,
lastParam , lastChar
Adding extra empty parameter
Calling clddev __complete systemctl status2 --unit  ''
The completion directive is: 0
The completions are: unit1
unit1_long
group1@subunit
group2@subunit2

__clddev_handle_completion_types: COMP_TYPE is 63

========= starting completion logic ==========
cur is group, words[*] is clddev systemctl status2 --unit group, #words[@] is 5, cword is 4
Truncated words[*]: clddev systemctl status2 --unit group,
lastParam group, lastChar p
Calling clddev __complete systemctl status2 --unit group
The completion directive is: 0
The completions are: unit1
unit1_long
group1@subunit
group2@subunit2

__clddev_handle_completion_types: COMP_TYPE is 9

========= starting completion logic ==========
cur is group, words[*] is clddev systemctl status2 --unit group, #words[@] is 5, cword is 4
Truncated words[*]: clddev systemctl status2 --unit group,
lastParam group, lastChar p
Calling clddev __complete systemctl status2 --unit group
The completion directive is: 0
The completions are: unit1
unit1_long
group1@subunit
group2@subunit2

__clddev_handle_completion_types: COMP_TYPE is 63

========= starting completion logic ==========
cur is @, words[*] is clddev systemctl status2 --unit group1 @, #words[@] is 6, cword is 5
Truncated words[*]: clddev systemctl status2 --unit group1 @,
lastParam @, lastChar @
Calling clddev __complete systemctl status2 --unit group1 @
The completion directive is: 0
The completions are:
__clddev_handle_completion_types: COMP_TYPE is 9

========= starting completion logic ==========
cur is @, words[*] is clddev systemctl status2 --unit group1 @, #words[@] is 6, cword is 5
Truncated words[*]: clddev systemctl status2 --unit group1 @,
lastParam @, lastChar @
Calling clddev __complete systemctl status2 --unit group1 @
The completion directive is: 0
The completions are:
__clddev_handle_completion_types: COMP_TYPE is 63

========= starting completion logic ==========
cur is sub, words[*] is clddev systemctl status2 --unit group1 @ sub, #words[@] is 7, cword is 6
Truncated words[*]: clddev systemctl status2 --unit group1 @ sub,
lastParam sub, lastChar b
Calling clddev __complete systemctl status2 --unit group1 @ sub
The completion directive is: 0
The completions are:
__clddev_handle_completion_types: COMP_TYPE is 9

========= starting completion logic ==========
cur is sub, words[*] is clddev systemctl status2 --unit group1 @ sub, #words[@] is 7, cword is 6
Truncated words[*]: clddev systemctl status2 --unit group1 @ sub,
lastParam sub, lastChar b
Calling clddev __complete systemctl status2 --unit group1 @ sub
The completion directive is: 0
The completions are:
__clddev_handle_completion_types: COMP_TYPE is 63

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions