diff --git a/cli/command/hosts/list.go b/cli/command/hosts/list.go index 839d5b675..894f0a737 100644 --- a/cli/command/hosts/list.go +++ b/cli/command/hosts/list.go @@ -23,6 +23,8 @@ package hosts import ( + "strings" + "github.com/opencurve/curveadm/cli/cli" "github.com/opencurve/curveadm/internal/configure/hosts" "github.com/opencurve/curveadm/internal/tui" @@ -32,7 +34,7 @@ import ( type listOptions struct { verbose bool - labels []string + labels string } func NewListCommand(curveadm *cli.CurveAdm) *cobra.Command { @@ -51,7 +53,7 @@ func NewListCommand(curveadm *cli.CurveAdm) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&options.verbose, "verbose", "v", false, "Verbose output for hosts") - flags.StringSliceVarP(&options.labels, "labels", "l", []string{}, "Specify the host labels") + flags.StringVarP(&options.labels, "labels", "l", "", "Specify the host labels") return cmd } @@ -156,7 +158,8 @@ func runList(curveadm *cli.CurveAdm, options listOptions) error { var err error data := curveadm.Hosts() if len(data) > 0 { - hcs, err = filter(data, options.labels) // filter hosts + labels := strings.Split(options.labels, ":") + hcs, err = filter(data, labels) // filter hosts if err != nil { return err } diff --git a/internal/configure/hosts/hc_get.go b/internal/configure/hosts/hc_get.go index 37774c9ae..256c89394 100644 --- a/internal/configure/hosts/hc_get.go +++ b/internal/configure/hosts/hc_get.go @@ -74,9 +74,15 @@ func (hc *HostConfig) GetSSHPort() int { return hc.getInt(CONFIG_SSH_P func (hc *HostConfig) GetPrivateKeyFile() string { return hc.getString(CONFIG_PRIVATE_CONFIG_FILE) } func (hc *HostConfig) GetForwardAgent() bool { return hc.getBool(CONFIG_FORWARD_AGENT) } func (hc *HostConfig) GetBecomeUser() string { return hc.getString(CONFIG_BECOME_USER) } -func (hc *HostConfig) GetLabels() []string { return hc.labels } func (hc *HostConfig) GetEnvs() []string { return hc.envs } +func (hc *HostConfig) GetLabels() []string { + if len(hc.labels) == 0 { + return []string{hc.GetHost()} + } + return hc.labels +} + func (hc *HostConfig) GetUser() string { user := hc.getString(CONFIG_USER) if user == "${user}" {