...

Source file src/edge-infra.dev/pkg/edge/edgecli/commands/context/update/updatecluster.go

Documentation: edge-infra.dev/pkg/edge/edgecli/commands/context/update

     1  package update
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"edge-infra.dev/pkg/edge/edgecli"
     8  	"edge-infra.dev/pkg/lib/cli/command"
     9  	"edge-infra.dev/pkg/lib/cli/rags"
    10  )
    11  
    12  func updateCluster(cfg *edgecli.Config) *command.Command {
    13  	var (
    14  		// cluster fields
    15  		name          string
    16  		clusterEdgeID string
    17  	)
    18  
    19  	cmd := &command.Command{
    20  		ShortUsage: "edge update-context cluster",
    21  		ShortHelp:  "Update a cluster that is in stored clusters",
    22  		Flags: []*rags.Rag{
    23  			// cluster field flags
    24  			{
    25  				Name:  "name",
    26  				Usage: "Name of cluster",
    27  				Value: &rags.String{Var: &name},
    28  			},
    29  			{
    30  				Name:  "clusterEdgeID",
    31  				Usage: "Cluster Edge ID",
    32  				Value: &rags.String{Var: &clusterEdgeID},
    33  			},
    34  		},
    35  		Exec: func(_ context.Context, _ []string) error {
    36  			if name == "" {
    37  				name = cfg.CurrentClusterContext
    38  			}
    39  
    40  			if err := cfg.UpdateCluster(name, clusterEdgeID); err != nil {
    41  				return err
    42  			}
    43  
    44  			fmt.Println("Cluster Context '" + name + "' has been updated")
    45  			return nil
    46  		},
    47  	}
    48  
    49  	return cmd
    50  }
    51  

View as plain text