github.com/djenriquez/nomad-1@v0.8.1/command/namespace_inspect.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 type NamespaceInspectCommand struct { 11 Meta 12 } 13 14 func (c *NamespaceInspectCommand) Help() string { 15 helpText := ` 16 Usage: nomad namespace inspect [options] <namespace> 17 18 Inspect is used to view raw information about a particular namespace. 19 20 General Options: 21 22 ` + generalOptionsUsage() + ` 23 24 Inspect Options: 25 26 -t 27 Format and display the namespaces using a Go template. 28 ` 29 30 return strings.TrimSpace(helpText) 31 } 32 33 func (c *NamespaceInspectCommand) AutocompleteFlags() complete.Flags { 34 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 35 complete.Flags{ 36 "-t": complete.PredictAnything, 37 }) 38 } 39 40 func (c *NamespaceInspectCommand) AutocompleteArgs() complete.Predictor { 41 return NamespacePredictor(c.Meta.Client, nil) 42 } 43 44 func (c *NamespaceInspectCommand) Synopsis() string { 45 return "Inspect a namespace" 46 } 47 48 func (c *NamespaceInspectCommand) Run(args []string) int { 49 var tmpl string 50 flags := c.Meta.FlagSet("namespace inspect", FlagSetClient) 51 flags.Usage = func() { c.Ui.Output(c.Help()) } 52 flags.StringVar(&tmpl, "t", "", "") 53 54 if err := flags.Parse(args); err != nil { 55 return 1 56 } 57 58 // Check that we got one arguments 59 args = flags.Args() 60 if l := len(args); l != 1 { 61 c.Ui.Error(c.Help()) 62 return 1 63 } 64 65 name := args[0] 66 67 // Get the HTTP client 68 client, err := c.Meta.Client() 69 if err != nil { 70 c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err)) 71 return 1 72 } 73 74 // Do a prefix lookup 75 ns, possible, err := getNamespace(client.Namespaces(), name) 76 if err != nil { 77 c.Ui.Error(fmt.Sprintf("Error retrieving namespaces: %s", err)) 78 return 1 79 } 80 81 if len(possible) != 0 { 82 c.Ui.Error(fmt.Sprintf("Prefix matched multiple namespaces\n\n%s", formatNamespaces(possible))) 83 return 1 84 } 85 86 out, err := Format(len(tmpl) == 0, tmpl, ns) 87 if err != nil { 88 c.Ui.Error(err.Error()) 89 return 1 90 } 91 92 c.Ui.Output(out) 93 return 0 94 }