WIP
This commit is contained in:
@@ -160,10 +160,11 @@ func hostsRemoveRunE(_ *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func newCommandHostsDefault() *cobra.Command {
|
func newCommandHostsDefault() *cobra.Command {
|
||||||
command := &cobra.Command{
|
command := &cobra.Command{
|
||||||
Use: "set-default",
|
Use: "set-default",
|
||||||
Short: "установка хоста по-умолчанию",
|
Short: "установка хоста по-умолчанию",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
RunE: hostsDefaultRunE,
|
ValidArgsFunction: ArgHostCompletion,
|
||||||
|
RunE: hostsDefaultRunE,
|
||||||
}
|
}
|
||||||
|
|
||||||
return command
|
return command
|
||||||
|
|||||||
27
cmd/utils.go
27
cmd/utils.go
@@ -34,3 +34,30 @@ func ArgRoleCompletion(_ *cobra.Command, _ []string, toComplete string) ([]strin
|
|||||||
|
|
||||||
return suggestions, cobra.ShellCompDirectiveDefault
|
return suggestions, cobra.ShellCompDirectiveDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ArgHostCompletion(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
exitApp := func(err error) {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var suggestions []string
|
||||||
|
|
||||||
|
workDir, err := filepath.Abs(flagWorkdir)
|
||||||
|
if err != nil {
|
||||||
|
exitApp(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
hosts, err := types.ReadHosts(workDir)
|
||||||
|
if err != nil {
|
||||||
|
exitApp(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for host := range *hosts {
|
||||||
|
if toComplete == "" || len(host) >= len(toComplete) && host[:len(toComplete)] == toComplete {
|
||||||
|
suggestions = append(suggestions, host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return suggestions, cobra.ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user