Refactoring of full-id argument and id length constants

* full-id argument is now called verbose to be more future-proof
* constants for identifier length are a little more concise
This commit is contained in:
Ivo Verberk 2016-01-15 23:32:38 +01:00
parent 149c55252d
commit 427d3d650d
10 changed files with 54 additions and 54 deletions

View File

@ -30,8 +30,8 @@ General Options:
-short
Display short output. Shows only the most recent task event.
-full-id
Show full identifiers.
-verbose
Show full information.
`
return strings.TrimSpace(helpText)
@ -42,12 +42,12 @@ func (c *AllocStatusCommand) Synopsis() string {
}
func (c *AllocStatusCommand) Run(args []string) int {
var short, fullId bool
var short, verbose bool
flags := c.Meta.FlagSet("alloc-status", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
@ -69,9 +69,9 @@ func (c *AllocStatusCommand) Run(args []string) int {
}
// Truncate the id unless full length is requested
length := shortIdLength
if fullId {
length = fullIdLength
length := shortId
if verbose {
length = fullId
}
// Query the allocation info

View File

@ -33,8 +33,8 @@ General Options:
Eval Monitor Options:
-full-id
Show full identifiers.
-verbose
Show full information.
`
return strings.TrimSpace(helpText)
}
@ -44,20 +44,20 @@ func (c *EvalMonitorCommand) Synopsis() string {
}
func (c *EvalMonitorCommand) Run(args []string) int {
var fullId bool
var verbose bool
flags := c.Meta.FlagSet("eval-monitor", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
}
// Truncate the id unless full length is requested
length := shortIdLength
if fullId {
length = fullIdLength
length := shortId
if verbose {
length = fullId
}
// Check that we got exactly one eval ID

View File

@ -17,8 +17,8 @@ const (
EnvNomadAddress = "NOMAD_ADDR"
// Constants for CLI identifier length
shortIdLength = 8
fullIdLength = 36
shortId = 8
fullId = 36
)
// FlagSetFlags is an enum to define what flags are present in the

View File

@ -12,7 +12,7 @@ import (
func TestMonitor_Update_Eval(t *testing.T) {
ui := new(cli.MockUi)
mon := newMonitor(ui, nil, fullIdLength)
mon := newMonitor(ui, nil, fullId)
// Evals triggered by jobs log
state := &evalState{
@ -65,7 +65,7 @@ func TestMonitor_Update_Eval(t *testing.T) {
func TestMonitor_Update_Allocs(t *testing.T) {
ui := new(cli.MockUi)
mon := newMonitor(ui, nil, fullIdLength)
mon := newMonitor(ui, nil, fullId)
// New allocations write new logs
state := &evalState{
@ -135,7 +135,7 @@ func TestMonitor_Update_Allocs(t *testing.T) {
func TestMonitor_Update_SchedulingFailure(t *testing.T) {
ui := new(cli.MockUi)
mon := newMonitor(ui, nil, shortIdLength)
mon := newMonitor(ui, nil, shortId)
// New allocs with desired status failed warns
state := &evalState{
@ -197,7 +197,7 @@ func TestMonitor_Update_SchedulingFailure(t *testing.T) {
func TestMonitor_Update_AllocModification(t *testing.T) {
ui := new(cli.MockUi)
mon := newMonitor(ui, nil, fullIdLength)
mon := newMonitor(ui, nil, fullId)
// New allocs with a create index lower than the
// eval create index are logged as modifications
@ -236,7 +236,7 @@ func TestMonitor_Monitor(t *testing.T) {
// Create the monitor
ui := new(cli.MockUi)
mon := newMonitor(ui, client, fullIdLength)
mon := newMonitor(ui, client, fullId)
// Submit a job - this creates a new evaluation we can monitor
job := testJob("job1")
@ -282,7 +282,7 @@ func TestMonitor_MonitorWithPrefix(t *testing.T) {
// Create the monitor
ui := new(cli.MockUi)
mon := newMonitor(ui, client, shortIdLength)
mon := newMonitor(ui, client, shortId)
// Submit a job - this creates a new evaluation we can monitor
job := testJob("job1")
@ -348,7 +348,7 @@ func TestMonitor_DumpAllocStatus(t *testing.T) {
},
},
}
dumpAllocStatus(ui, alloc, fullIdLength)
dumpAllocStatus(ui, alloc, fullId)
// Check the output
out := ui.OutputWriter.String()
@ -378,7 +378,7 @@ func TestMonitor_DumpAllocStatus(t *testing.T) {
// Dumping alloc status with no eligible nodes adds a warning
alloc.Metrics.NodesEvaluated = 0
dumpAllocStatus(ui, alloc, shortIdLength)
dumpAllocStatus(ui, alloc, shortId)
// Check the output
out = ui.OutputWriter.String()

View File

@ -32,8 +32,8 @@ Node Status Options:
Display short output. Used only when a single node is being
queried, and drops verbose output about node allocations.
-full-id
Display full identifiers.
-verbose
Display full information.
`
return strings.TrimSpace(helpText)
}
@ -43,12 +43,12 @@ func (c *NodeStatusCommand) Synopsis() string {
}
func (c *NodeStatusCommand) Run(args []string) int {
var short, fullId bool
var short, verbose bool
flags := c.Meta.FlagSet("node-status", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
@ -62,9 +62,9 @@ func (c *NodeStatusCommand) Run(args []string) int {
}
// Truncate the id unless full length is requested
length := shortIdLength
if fullId {
length = fullIdLength
length := shortId
if verbose {
length = fullId
}
// Get the HTTP client

View File

@ -95,7 +95,7 @@ func TestNodeStatusCommand_Run(t *testing.T) {
ui.OutputWriter.Reset()
// Request full id output
if code := cmd.Run([]string{"-address=" + url, "-full-id", nodeID[:4]}); code != 0 {
if code := cmd.Run([]string{"-address=" + url, "-verbose", nodeID[:4]}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
}
out = ui.OutputWriter.String()

View File

@ -48,8 +48,8 @@ Run Options:
You can use this ID to start a monitor using the eval-monitor
command later if needed.
-full-id
Display full identifiers.
-verbose
Display full information.
`
return strings.TrimSpace(helpText)
}
@ -59,21 +59,21 @@ func (c *RunCommand) Synopsis() string {
}
func (c *RunCommand) Run(args []string) int {
var detach, fullId bool
var detach, verbose bool
flags := c.Meta.FlagSet("run", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
}
// Truncate the id unless full length is requested
length := shortIdLength
if fullId {
length = fullIdLength
length := shortId
if verbose {
length = fullId
}
// Check that we got exactly one node

View File

@ -34,8 +34,8 @@ Status Options:
queried, and drops verbose information about allocations
and evaluations.
-full-id
Display full identifiers.
-verbose
Display full information.
`
return strings.TrimSpace(helpText)
}
@ -45,12 +45,12 @@ func (c *StatusCommand) Synopsis() string {
}
func (c *StatusCommand) Run(args []string) int {
var short, fullId bool
var short, verbose bool
flags := c.Meta.FlagSet("status", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
@ -64,9 +64,9 @@ func (c *StatusCommand) Run(args []string) int {
}
// Truncate the id unless full length is requested
c.length = shortIdLength
if fullId {
c.length = fullIdLength
c.length = shortId
if verbose {
c.length = fullId
}
// Get the HTTP client

View File

@ -108,7 +108,7 @@ func TestStatusCommand_Run(t *testing.T) {
ui.OutputWriter.Reset()
// Request full identifiers
if code := cmd.Run([]string{"-address=" + url, "-full-id", "job1"}); code != 0 {
if code := cmd.Run([]string{"-address=" + url, "-verbose", "job1"}); code != 0 {
t.Fatalf("expected exit 0, got: %d", code)
}
out = ui.OutputWriter.String()

View File

@ -31,8 +31,8 @@ Stop Options:
to the screen, which can be used to call up a monitor later if
needed using the eval-monitor command.
-full-id
Display full identifiers.
-verbose
Display full information.
`
return strings.TrimSpace(helpText)
}
@ -42,21 +42,21 @@ func (c *StopCommand) Synopsis() string {
}
func (c *StopCommand) Run(args []string) int {
var detach, fullId bool
var detach, verbose bool
flags := c.Meta.FlagSet("stop", FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&detach, "detach", false, "")
flags.BoolVar(&fullId, "full-id", false, "")
flags.BoolVar(&verbose, "verbose", false, "")
if err := flags.Parse(args); err != nil {
return 1
}
// Truncate the id unless full length is requested
length := shortIdLength
if fullId {
length = fullIdLength
length := shortId
if verbose {
length = fullId
}
// Check that we got exactly one job