github.com/djenriquez/nomad-1@v0.8.1/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) Run(args []string) int { 42 flags := c.Meta.FlagSet("sentinel delete", FlagSetClient) 43 flags.Usage = func() { c.Ui.Output(c.Help()) } 44 if err := flags.Parse(args); err != nil { 45 return 1 46 } 47 48 // Check that we got exactly one arguments 49 args = flags.Args() 50 if l := len(args); l != 1 { 51 c.Ui.Error(c.Help()) 52 return 1 53 } 54 55 // Get the name and file 56 policyName := args[0] 57 58 // Get the HTTP client 59 client, err := c.Meta.Client() 60 if err != nil { 61 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 62 return 1 63 } 64 65 // Get the list of policies 66 _, err = client.SentinelPolicies().Delete(policyName, nil) 67 if err != nil { 68 c.Ui.Error(fmt.Sprintf("Error deleting Sentinel policy: %s", err)) 69 return 1 70 } 71 72 c.Ui.Output(fmt.Sprintf("Successfully deleted %q Sentinel policy!", 73 policyName)) 74 return 0 75 }