github.com/djenriquez/nomad-1@v0.8.1/command/namespace.go (about) 1 package command 2 3 import ( 4 "strings" 5 6 "github.com/hashicorp/nomad/api/contexts" 7 "github.com/mitchellh/cli" 8 "github.com/posener/complete" 9 ) 10 11 type NamespaceCommand struct { 12 Meta 13 } 14 15 func (f *NamespaceCommand) Help() string { 16 helpText := ` 17 Usage: nomad namespace <subcommand> [options] [args] 18 19 This command groups subcommands for interacting with namespaces. Namespaces 20 allow jobs and their associated objects to be segmented from each other and 21 other users of the cluster. For a full guide on namespaces see: 22 https://www.nomadproject.io/guides/namespaces.html 23 24 Create or update a namespace: 25 26 $ nomad namespace apply <name> -description "My new namespace" 27 28 List namespaces: 29 30 $ nomad namespace list 31 32 View the status of a namespace: 33 34 $ nomad namespace status <name> 35 36 Please see the individual subcommand help for detailed usage information. 37 ` 38 39 return strings.TrimSpace(helpText) 40 } 41 42 func (f *NamespaceCommand) Synopsis() string { 43 return "Interact with namespaces" 44 } 45 46 func (f *NamespaceCommand) Run(args []string) int { 47 return cli.RunResultHelp 48 } 49 50 // NamespacePredictor returns a namespace predictor that can optionally filter 51 // specific namespaces 52 func NamespacePredictor(factory ApiClientFactory, filter map[string]struct{}) complete.Predictor { 53 return complete.PredictFunc(func(a complete.Args) []string { 54 client, err := factory() 55 if err != nil { 56 return nil 57 } 58 59 resp, _, err := client.Search().PrefixSearch(a.Last, contexts.Namespaces, nil) 60 if err != nil { 61 return []string{} 62 } 63 64 // Filter the returned namespaces. We assign the unfiltered slice to the 65 // filtered slice but with no elements. This causes the slices to share 66 // the underlying array and makes the filtering allocation free. 67 unfiltered := resp.Matches[contexts.Namespaces] 68 filtered := unfiltered[:0] 69 for _, ns := range unfiltered { 70 if _, ok := filter[ns]; !ok { 71 filtered = append(filtered, ns) 72 } 73 } 74 75 return filtered 76 }) 77 }