Commit 6ac93e2a authored by Rob Pike's avatar Rob Pike

flag: export commandLine, the previously internal default FlagSet

s/commandLine/CommandLine/g

Fixes #4209.

R=golang-dev, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/12587043
parent a97a91de
...@@ -12,11 +12,6 @@ import "os" ...@@ -12,11 +12,6 @@ import "os"
// After calling ResetForTesting, parse errors in flag handling will not // After calling ResetForTesting, parse errors in flag handling will not
// exit the program. // exit the program.
func ResetForTesting(usage func()) { func ResetForTesting(usage func()) {
commandLine = NewFlagSet(os.Args[0], ContinueOnError) CommandLine = NewFlagSet(os.Args[0], ContinueOnError)
Usage = usage Usage = usage
} }
// CommandLine returns the default FlagSet.
func CommandLine() *FlagSet {
return commandLine
}
This diff is collapsed.
...@@ -139,7 +139,7 @@ func TestGet(t *testing.T) { ...@@ -139,7 +139,7 @@ func TestGet(t *testing.T) {
func TestUsage(t *testing.T) { func TestUsage(t *testing.T) {
called := false called := false
ResetForTesting(func() { called = true }) ResetForTesting(func() { called = true })
if CommandLine().Parse([]string{"-x"}) == nil { if CommandLine.Parse([]string{"-x"}) == nil {
t.Error("parse did not fail for unknown flag") t.Error("parse did not fail for unknown flag")
} }
if !called { if !called {
...@@ -215,7 +215,7 @@ func testParse(f *FlagSet, t *testing.T) { ...@@ -215,7 +215,7 @@ func testParse(f *FlagSet, t *testing.T) {
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
ResetForTesting(func() { t.Error("bad parse") }) ResetForTesting(func() { t.Error("bad parse") })
testParse(CommandLine(), t) testParse(CommandLine, t)
} }
func TestFlagSetParse(t *testing.T) { func TestFlagSetParse(t *testing.T) {
...@@ -311,7 +311,7 @@ func TestChangingArgs(t *testing.T) { ...@@ -311,7 +311,7 @@ func TestChangingArgs(t *testing.T) {
defer func() { os.Args = oldArgs }() defer func() { os.Args = oldArgs }()
os.Args = []string{"cmd", "-before", "subcmd", "-after", "args"} os.Args = []string{"cmd", "-before", "subcmd", "-after", "args"}
before := Bool("before", false, "") before := Bool("before", false, "")
if err := CommandLine().Parse(os.Args[1:]); err != nil { if err := CommandLine.Parse(os.Args[1:]); err != nil {
t.Fatal(err) t.Fatal(err)
} }
cmd := Arg(0) cmd := Arg(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment