Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ var showConfigCmd = &cobra.Command{
SilenceUsage: true,
}

var useNodeCmd = &cobra.Command{
Use: "use-node",
Short: "Set the current node in the configuration",
RunE: useNodeCmdRun,
SilenceUsage: true,
}

var unsetCurrentNodeCmd = &cobra.Command{
Use: "unset-current-node",
Short: "Unset the current node in the configuration",
Expand Down Expand Up @@ -70,21 +63,14 @@ func init() {
utils.AddCommonFlags(configCmd, &commonFlags)
rootCmd.AddCommand(configCmd)

configCmd.AddCommand(showConfigCmd, useNodeCmd, unsetCurrentNodeCmd, unsetNodeCmd, unsetAllCmd, setNodeCmd, importCmd)
configCmd.AddCommand(showConfigCmd, unsetCurrentNodeCmd, unsetNodeCmd, unsetAllCmd, setNodeCmd, importCmd)
utils.AddNodeFlagsOnly(setNodeCmd)
}

func showConfigCmdRun(cmd *cobra.Command, args []string) error {
return config.New().ShowConfig()
}

func useNodeCmdRun(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("usage: %s <node name>", cmd.CommandPath())
}
return config.New().UseNodeConfig(args[0])
}

func unsetCurrentNodeCmdRun(cmd *cobra.Command, args []string) error {
return config.New().UnsetCurrentNodeConfig()
}
Expand Down Expand Up @@ -115,7 +101,17 @@ func setNodeCmdRun(cmd *cobra.Command, args []string) error {
nrg := cmd.Flag(utils.NodeResourceGroupKey).Value.String()
vmss := cmd.Flag(utils.VMSSKey).Value.String()
insID := cmd.Flag(utils.VMSSInstanceIDKey).Value.String()
return cfg.SetNodeConfigWithVMSSInfoFlag(args[0], subID, nrg, vmss, insID)
err := cfg.SetNodeConfigWithVMSSInfoFlag(args[0], subID, nrg, vmss, insID)
if err != nil {
return fmt.Errorf("setting node %s : %w", args[0], err)
}

if setNode, _ := cmd.Flags().GetBool(utils.CurrentNodeKey); setNode {
if setNode {
return cfg.UseNodeConfig(args[0])
}
}
return nil
}
}

Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
VMSSKey = "vmss"
VMSSInstanceIDKey = "instance-id"
ResourceIDKey = "id"
CurrentNodeKey = "current-node"
)

// We need package level variables to ensure that the viper flag binding works correctly.
Expand All @@ -33,6 +34,7 @@ var (
vmss string
vmssInstanceID string
resourceID string
currentNode bool
)

// CommonFlags contains CLI flags common for all subcommands
Expand Down Expand Up @@ -102,6 +104,12 @@ func addNodeFlags(command *cobra.Command, useFlagsOnly bool) {
e.g. /subscriptions/mySubID/resourceGroups/myRG/providers/myProvider/virtualMachineScaleSets/myVMSS/virtualMachines/myInsID.
Notice it is not case sensitive.`,
)
command.PersistentFlags().BoolVarP(
&currentNode,
CurrentNodeKey, "",
false,
"Sets node as current node.",
)

command.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
// If node or resource ID is set, we don't need to read the config file
Expand Down