github.com/zhizhiboom/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/command/sentinel_delete.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type SentinelDeleteCommand struct { 11 Meta 12 } 13 14 func (c *SentinelDeleteCommand) Help() string { 15 helpText := ` 16 Usage: nomad sentinel delete [options] <name> 17 18 Delete is used to delete an existing Sentinel policy. 19 20 General Options: 21 22 ` + generalOptionsUsage() + ` 23 24 ` 25 return strings.TrimSpace(helpText) 26 } 27 28 func (c *SentinelDeleteCommand) AutocompleteFlags() complete.Flags { 29 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 30 complete.Flags{}) 31 } 32 33 func (c *SentinelDeleteCommand) AutocompleteArgs() complete.Predictor { 34 return complete.PredictNothing 35 } 36 37 func (c *SentinelDeleteCommand) Synopsis() string { 38 return "Delete an existing Sentinel policies" 39 } 40 41 func (c *SentinelDeleteCommand) Name() string { return "sentinel delete" } 42 43 func (c *SentinelDeleteCommand) Run(args []string) int { 44 flags := c.Meta.FlagSet(c.Name(), FlagSetClient) 45 flags.Usage = func() { c.Ui.Output(c.Help()) } 46 if err := flags.Parse(args); err != nil { 47 return 1 48 } 49 50 // Check that we got exactly one arguments 51 args = flags.Args() 52 if l := len(args); l != 1 { 53 c.Ui.Error("This command takes one argument: <name>") 54 c.Ui.Error(commandErrorText(c)) 55 return 1 56 } 57 58 // Get the name and file 59 policyName := args[0] 60 61 // Get the HTTP client 62 client, err := c.Meta.Client() 63 if err != nil { 64 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 65 return 1 66 } 67 68 // Get the list of policies 69 _, err = client.SentinelPolicies().Delete(policyName, nil) 70 if err != nil { 71 c.Ui.Error(fmt.Sprintf("Error deleting Sentinel policy: %s", err)) 72 return 1 73 } 74 75 c.Ui.Output(fmt.Sprintf("Successfully deleted %q Sentinel policy!", 76 policyName)) 77 return 0 78 }