Skip to content

Commit

Permalink
fleetctl: Support truthy values in boolean unit options
Browse files Browse the repository at this point in the history
Support truthy values in boolean unit options(yes, on, 1, t)

Fixes coreos#1108
  • Loading branch information
wuqixuan committed Jun 26, 2015
1 parent d3a2a6d commit 8142d72
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ func (u *Unit) IsGlobal() bool {
}
// Last value found wins
last := values[len(values)-1]
return strings.ToLower(last) == "true"
lastLower := strings.ToLower(last)
return lastLower == "true" || lastLower == "yes" || lastLower == "1" || lastLower == "on" || lastLower == "t"
}

// NewJob creates a new Job based on the given name and Unit.
Expand Down
5 changes: 5 additions & 0 deletions job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ func TestUnitIsGlobal(t *testing.T) {
// correct specifications
{"[X-Fleet]\nMachineOf=foo\nGlobal=true", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=True", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=Yes", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=On", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=1", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=t", true},
{"[X-Fleet]\nMachineOf=foo\nGlobal=12", false},
// multiple parameters - last wins
{"[X-Fleet]\nGlobal=true\nGlobal=false", false},
{"[X-Fleet]\nGlobal=false\nGlobal=true", true},
Expand Down

0 comments on commit 8142d72

Please sign in to comment.