95 lines
1.9 KiB
Go
95 lines
1.9 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/posener/complete"
|
|
)
|
|
|
|
type NamespaceInspectCommand struct {
|
|
Meta
|
|
}
|
|
|
|
func (c *NamespaceInspectCommand) Help() string {
|
|
helpText := `
|
|
Usage: nomad namespace inspect [options] <quota>
|
|
|
|
Inspect is used to view raw information about a particular namespace.
|
|
|
|
General Options:
|
|
|
|
` + generalOptionsUsage() + `
|
|
|
|
Inspect Options:
|
|
|
|
-t
|
|
Format and display the namespaces using a Go template.
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
}
|
|
|
|
func (c *NamespaceInspectCommand) AutocompleteFlags() complete.Flags {
|
|
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
|
|
complete.Flags{
|
|
"-t": complete.PredictAnything,
|
|
})
|
|
}
|
|
|
|
func (c *NamespaceInspectCommand) AutocompleteArgs() complete.Predictor {
|
|
return NamespacePredictor(c.Meta.Client, nil)
|
|
}
|
|
|
|
func (c *NamespaceInspectCommand) Synopsis() string {
|
|
return "Inspect a namespace"
|
|
}
|
|
|
|
func (c *NamespaceInspectCommand) Run(args []string) int {
|
|
var tmpl string
|
|
flags := c.Meta.FlagSet("namespace inspect", FlagSetClient)
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
flags.StringVar(&tmpl, "t", "", "")
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
return 1
|
|
}
|
|
|
|
// Check that we got one arguments
|
|
args = flags.Args()
|
|
if l := len(args); l != 1 {
|
|
c.Ui.Error(c.Help())
|
|
return 1
|
|
}
|
|
|
|
name := args[0]
|
|
|
|
// Get the HTTP client
|
|
client, err := c.Meta.Client()
|
|
if err != nil {
|
|
c.Ui.Error(fmt.Sprintf("Error initializing client: %s", err))
|
|
return 1
|
|
}
|
|
|
|
// Do a prefix lookup
|
|
ns, possible, err := getNamespace(client.Namespaces(), name)
|
|
if err != nil {
|
|
c.Ui.Error(fmt.Sprintf("Error retrieving namespaces: %s", err))
|
|
return 1
|
|
}
|
|
|
|
if len(possible) != 0 {
|
|
c.Ui.Error(fmt.Sprintf("Prefix matched multiple namespaces\n\n%s", formatNamespaces(possible)))
|
|
return 1
|
|
}
|
|
|
|
out, err := Format(len(tmpl) == 0, tmpl, ns)
|
|
if err != nil {
|
|
c.Ui.Error(err.Error())
|
|
return 1
|
|
}
|
|
|
|
c.Ui.Output(out)
|
|
return 0
|
|
}
|