...

Source file src/edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/delete/command.go

Documentation: edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/delete

     1  package delete
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/peterbourgon/ff/v3"
     7  
     8  	"edge-infra.dev/pkg/edge/api/graph/model"
     9  	"edge-infra.dev/pkg/edge/edgeadmin/commands/operatorintervention/edgeextension"
    10  	"edge-infra.dev/pkg/edge/edgecli"
    11  	"edge-infra.dev/pkg/edge/edgecli/flagutil"
    12  	"edge-infra.dev/pkg/lib/cli/command"
    13  	"edge-infra.dev/pkg/lib/cli/rags"
    14  )
    15  
    16  var deleteCommandLongHelp = `
    17  	This edgeadmin command can be used to delete a single OI command from the database.
    18  	The --command flag is required and the value should be set to the command to be removed.
    19  
    20  	Example Usage:
    21  
    22  	$ edgeadmin operatorintervention delete command --command ls
    23  `
    24  
    25  func NewDeleteCommand(cfg *edgecli.Config) *command.Command {
    26  	var (
    27  		edge = &edgeextension.Ext{Cfg: cfg}
    28  	)
    29  
    30  	var cmd *command.Command
    31  	cmd = &command.Command{
    32  		ShortUsage: "edgeadmin operatorintervention delete command",
    33  		ShortHelp:  "Deletes a single command from the database",
    34  		LongHelp:   deleteCommandLongHelp,
    35  		Options:    []ff.Option{},
    36  		Flags: []*rags.Rag{
    37  			{
    38  				Name:     flagutil.OICommand,
    39  				Usage:    "command to be removed",
    40  				Value:    &rags.String{},
    41  				Required: true,
    42  			},
    43  		},
    44  
    45  		Extensions: []command.Extension{
    46  			edge,
    47  		},
    48  
    49  		Exec: func(ctx context.Context, _ []string) error {
    50  			var mutation struct {
    51  				DeleteOperatorInterventionCommand struct {
    52  					model.DeleteOperatorInterventionCommandResponse
    53  				} `graphql:"deleteOperatorInterventionCommand(command: $command)"`
    54  			}
    55  
    56  			var variables = map[string]interface{}{
    57  				"command": model.OperatorInterventionCommandInput{
    58  					Name: flagutil.GetStringFlag(cmd.Rags, flagutil.OICommand),
    59  				},
    60  			}
    61  
    62  			err := edge.Client.Mutate(ctx, &mutation, variables)
    63  			if err != nil {
    64  				return err
    65  			}
    66  
    67  			return handleResponseFormatting(
    68  				"Command",
    69  				mutation.DeleteOperatorInterventionCommand.Errors,
    70  			)
    71  		},
    72  	}
    73  	return cmd
    74  }
    75  

View as plain text