Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Command Line Groupings #4027

Merged
merged 12 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ func TestNodes_ToggleEligibility(t *testing.T) {
if out.SchedulingEligibility != structs.NodeSchedulingEligible {
t.Fatalf("bad eligibility: %v vs %v", out.SchedulingEligibility, structs.NodeSchedulingEligible)
}
if out.DrainStrategy != nil {
t.Fatalf("drain strategy should be unset")
}
}

func TestNodes_Allocations(t *testing.T) {
Expand Down
19 changes: 19 additions & 0 deletions command/alloc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package command

import "github.com/mitchellh/cli"

type AllocCommand struct {
Meta
}

func (f *AllocCommand) Help() string {
return "This command is accessed by using one of the subcommands below."
}

func (f *AllocCommand) Synopsis() string {
return "Interact with allocations"
}

func (f *AllocCommand) Run(args []string) int {
return cli.RunResultHelp
}
4 changes: 2 additions & 2 deletions command/alloc_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type AllocStatusCommand struct {

func (c *AllocStatusCommand) Help() string {
helpText := `
Usage: nomad alloc-status [options] <allocation>
Usage: nomad alloc status [options] <allocation>
Display information about existing allocations and its tasks. This command can
be used to inspect the current status of an allocation, including its running
Expand Down Expand Up @@ -87,7 +87,7 @@ func (c *AllocStatusCommand) Run(args []string) int {
var short, displayStats, verbose, json bool
var tmpl string

flags := c.Meta.FlagSet("alloc-status", FlagSetClient)
flags := c.Meta.FlagSet("alloc status", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
Expand Down
28 changes: 14 additions & 14 deletions command/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import (
"github.com/posener/complete"
)

type ClientConfigCommand struct {
type NodeConfigCommand struct {
Meta
}

func (c *ClientConfigCommand) Help() string {
func (c *NodeConfigCommand) Help() string {
helpText := `
Usage: nomad client-config [options]
Usage: nomad node config [options]

View or modify client configuration details. This command only
works on client nodes, and can be used to update the running
client configurations it supports.
View or modify a client node's configuration details. This command only works
on client nodes, and can be used to update the running client configurations
it supports.

The arguments behave differently depending on the flags given.
See each flag's description for its specific requirements.
The arguments behave differently depending on the flags given. See each
flag's description for its specific requirements.
Copy link
Contributor

@preetapan preetapan Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this old alias client config be mentioned in the docs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only called out aliases we want to keep. Like shortcuts. We will need to add a version section to: https://www.nomadproject.io/docs/upgrade/upgrade-specific.html


General Options:

Expand All @@ -41,19 +41,19 @@ Client Config Options:
to configure. The set is updated atomically.

Example:
$ nomad client-config -update-servers foo:4647 bar:4647
$ nomad node config -update-servers foo:4647 bar:4647
`
return strings.TrimSpace(helpText)
}

func (c *ClientConfigCommand) Synopsis() string {
func (c *NodeConfigCommand) Synopsis() string {
return "View or modify client configuration details"
}

func (c *ClientConfigCommand) Run(args []string) int {
func (c *NodeConfigCommand) Run(args []string) int {
var listServers, updateServers bool

flags := c.Meta.FlagSet("client-servers", FlagSetClient)
flags := c.Meta.FlagSet("node config", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&listServers, "servers", false, "")
flags.BoolVar(&updateServers, "update-servers", false, "")
Expand Down Expand Up @@ -111,14 +111,14 @@ func (c *ClientConfigCommand) Run(args []string) int {
return 1
}

func (c *ClientConfigCommand) AutocompleteFlags() complete.Flags {
func (c *NodeConfigCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-servers": complete.PredictNothing,
"-update-servers": complete.PredictAnything,
})
}

func (c *ClientConfigCommand) AutocompleteArgs() complete.Predictor {
func (c *NodeConfigCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
6 changes: 3 additions & 3 deletions command/client_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestClientConfigCommand_Implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &ClientConfigCommand{}
var _ cli.Command = &NodeConfigCommand{}
}

func TestClientConfigCommand_UpdateServers(t *testing.T) {
Expand All @@ -21,7 +21,7 @@ func TestClientConfigCommand_UpdateServers(t *testing.T) {
defer srv.Shutdown()

ui := new(cli.MockUi)
cmd := &ClientConfigCommand{Meta: Meta{Ui: ui}}
cmd := &NodeConfigCommand{Meta: Meta{Ui: ui}}

// Fails if trying to update with no servers
code := cmd.Run([]string{"-update-servers"})
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestClientConfigCommand_UpdateServers(t *testing.T) {
func TestClientConfigCommand_Fails(t *testing.T) {
t.Parallel()
ui := new(cli.MockUi)
cmd := &ClientConfigCommand{Meta: Meta{Ui: ui}}
cmd := &NodeConfigCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
Expand Down
19 changes: 19 additions & 0 deletions command/eval.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package command

import "github.com/mitchellh/cli"

type EvalCommand struct {
Meta
}

func (f *EvalCommand) Help() string {
return "This command is accessed by using one of the subcommands below."
}

func (f *EvalCommand) Synopsis() string {
return "Interact with evaluations"
}

func (f *EvalCommand) Run(args []string) int {
return cli.RunResultHelp
}
4 changes: 2 additions & 2 deletions command/eval_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type EvalStatusCommand struct {

func (c *EvalStatusCommand) Help() string {
helpText := `
Usage: nomad eval-status [options] <evaluation>
Usage: nomad eval status [options] <evaluation>

Display information about evaluations. This command can be used to inspect the
current status of an evaluation as well as determine the reason an evaluation
Expand Down Expand Up @@ -81,7 +81,7 @@ func (c *EvalStatusCommand) Run(args []string) int {
var monitor, verbose, json bool
var tmpl string

flags := c.Meta.FlagSet("eval-status", FlagSetClient)
flags := c.Meta.FlagSet("eval status", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&monitor, "monitor", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
Expand Down
18 changes: 9 additions & 9 deletions command/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ const (
defaultTailLines int64 = 10
)

type FSCommand struct {
type AllocFSCommand struct {
Meta
}

func (f *FSCommand) Help() string {
func (f *AllocFSCommand) Help() string {
helpText := `
Usage: nomad fs [options] <allocation> <path>
Usage: nomad alloc fs [options] <allocation> <path>

fs displays either the contents of an allocation directory for the passed allocation,
or displays the file at the given path. The path is relative to the root of the alloc
Expand Down Expand Up @@ -75,11 +75,11 @@ FS Specific Options:
return strings.TrimSpace(helpText)
}

func (f *FSCommand) Synopsis() string {
func (f *AllocFSCommand) Synopsis() string {
return "Inspect the contents of an allocation directory"
}

func (c *FSCommand) AutocompleteFlags() complete.Flags {
func (c *AllocFSCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-H": complete.PredictNothing,
Expand All @@ -93,7 +93,7 @@ func (c *FSCommand) AutocompleteFlags() complete.Flags {
})
}

func (f *FSCommand) AutocompleteArgs() complete.Predictor {
func (f *AllocFSCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictFunc(func(a complete.Args) []string {
client, err := f.Meta.Client()
if err != nil {
Expand All @@ -108,11 +108,11 @@ func (f *FSCommand) AutocompleteArgs() complete.Predictor {
})
}

func (f *FSCommand) Run(args []string) int {
func (f *AllocFSCommand) Run(args []string) int {
var verbose, machine, job, stat, tail, follow bool
var numLines, numBytes int64

flags := f.Meta.FlagSet("fs", FlagSetClient)
flags := f.Meta.FlagSet("alloc fs", FlagSetClient)
flags.Usage = func() { f.Ui.Output(f.Help()) }
flags.BoolVar(&verbose, "verbose", false, "")
flags.BoolVar(&machine, "H", false, "")
Expand Down Expand Up @@ -333,7 +333,7 @@ func (f *FSCommand) Run(args []string) int {

// followFile outputs the contents of the file to stdout relative to the end of
// the file. If numLines does not equal -1, then tail -n behavior is used.
func (f *FSCommand) followFile(client *api.Client, alloc *api.Allocation,
func (f *AllocFSCommand) followFile(client *api.Client, alloc *api.Allocation,
path, origin string, offset, numLines int64) (io.ReadCloser, error) {

cancel := make(chan struct{})
Expand Down
6 changes: 3 additions & 3 deletions command/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestFSCommand_Implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &FSCommand{}
var _ cli.Command = &AllocFSCommand{}
}

func TestFSCommand_Fails(t *testing.T) {
Expand All @@ -22,7 +22,7 @@ func TestFSCommand_Fails(t *testing.T) {
defer srv.Shutdown()

ui := new(cli.MockUi)
cmd := &FSCommand{Meta: Meta{Ui: ui}}
cmd := &AllocFSCommand{Meta: Meta{Ui: ui}}

// Fails on lack of job ID
if code := cmd.Run([]string{"-job"}); code != 1 {
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestFSCommand_AutocompleteArgs(t *testing.T) {
defer srv.Shutdown()

ui := new(cli.MockUi)
cmd := &FSCommand{Meta: Meta{Ui: ui, flagAddress: url}}
cmd := &AllocFSCommand{Meta: Meta{Ui: ui, flagAddress: url}}

// Create a fake alloc
state := srv.Agent.Server().State()
Expand Down
12 changes: 6 additions & 6 deletions command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ const (
DefaultInitName = "example.nomad"
)

// InitCommand generates a new job template that you can customize to your
// JobInitCommand generates a new job template that you can customize to your
// liking, like vagrant init
type InitCommand struct {
type JobInitCommand struct {
Meta
}

func (c *InitCommand) Help() string {
func (c *JobInitCommand) Help() string {
helpText := `
Usage: nomad init
Usage: nomad job init

Creates an example job file that can be used as a starting
point to customize further.
`
return strings.TrimSpace(helpText)
}

func (c *InitCommand) Synopsis() string {
func (c *JobInitCommand) Synopsis() string {
return "Create an example job file"
}

func (c *InitCommand) Run(args []string) int {
func (c *JobInitCommand) Run(args []string) int {
// Check for misuse
if len(args) != 0 {
c.Ui.Error(c.Help())
Expand Down
4 changes: 2 additions & 2 deletions command/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (

func TestInitCommand_Implements(t *testing.T) {
t.Parallel()
var _ cli.Command = &InitCommand{}
var _ cli.Command = &JobInitCommand{}
}

func TestInitCommand_Run(t *testing.T) {
t.Parallel()
ui := new(cli.MockUi)
cmd := &InitCommand{Meta: Meta{Ui: ui}}
cmd := &JobInitCommand{Meta: Meta{Ui: ui}}

// Fails on misuse
if code := cmd.Run([]string{"some", "bad", "args"}); code != 1 {
Expand Down
16 changes: 8 additions & 8 deletions command/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/posener/complete"
)

type InspectCommand struct {
type JobInspectCommand struct {
Meta
}

func (c *InspectCommand) Help() string {
func (c *JobInspectCommand) Help() string {
helpText := `
Usage: nomad inspect [options] <job>
Usage: nomad job inspect [options] <job>

Inspect is used to see the specification of a submitted job.

Expand All @@ -37,11 +37,11 @@ Inspect Options:
return strings.TrimSpace(helpText)
}

func (c *InspectCommand) Synopsis() string {
func (c *JobInspectCommand) Synopsis() string {
return "Inspect a submitted job"
}

func (c *InspectCommand) AutocompleteFlags() complete.Flags {
func (c *JobInspectCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"-version": complete.PredictAnything,
Expand All @@ -50,7 +50,7 @@ func (c *InspectCommand) AutocompleteFlags() complete.Flags {
})
}

func (c *InspectCommand) AutocompleteArgs() complete.Predictor {
func (c *JobInspectCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictFunc(func(a complete.Args) []string {
client, err := c.Meta.Client()
if err != nil {
Expand All @@ -65,11 +65,11 @@ func (c *InspectCommand) AutocompleteArgs() complete.Predictor {
})
}

func (c *InspectCommand) Run(args []string) int {
func (c *JobInspectCommand) Run(args []string) int {
var json bool
var tmpl, versionStr string

flags := c.Meta.FlagSet("inspect", FlagSetClient)
flags := c.Meta.FlagSet("job inspect", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&json, "json", false, "")
flags.StringVar(&tmpl, "t", "", "")
Expand Down
Loading