mirror of https://github.com/perkeep/perkeep.git
Fix crash with "go test -v -cpu=1,1 ./cmd/camput/"
Don't double-register the help flag. Only affects tests run twice, like above. Change-Id: Ia235f2e2aa4a70e3b5a5c6fe21d8add90069664f
This commit is contained in:
parent
1333551de1
commit
85e2e5e301
|
@ -89,6 +89,23 @@ func TestUsageOnNoargs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestCommandUsage tests that we output a command-specific usage message and return
|
||||||
|
// with a non-zero exit status.
|
||||||
|
func TestCommandUsage(t *testing.T) {
|
||||||
|
var e env
|
||||||
|
out, err, code := e.Run("attr")
|
||||||
|
if code != 1 {
|
||||||
|
t.Errorf("exit code = %d; want 1", code)
|
||||||
|
}
|
||||||
|
if len(out) != 0 {
|
||||||
|
t.Errorf("wanted nothing on stdout; got:\n%s", out)
|
||||||
|
}
|
||||||
|
sub := "Attr takes 3 args: <permanode> <attr> <value>"
|
||||||
|
if !bytes.Contains(err, []byte(sub)) {
|
||||||
|
t.Errorf("stderr doesn't contain substring %q. Got:\n%s", sub, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUploadingChangingDirectory(t *testing.T) {
|
func TestUploadingChangingDirectory(t *testing.T) {
|
||||||
// TODO(bradfitz):
|
// TODO(bradfitz):
|
||||||
// $ mkdir /tmp/somedir
|
// $ mkdir /tmp/somedir
|
||||||
|
|
|
@ -61,6 +61,7 @@ var (
|
||||||
// mode name to actual subcommand mapping
|
// mode name to actual subcommand mapping
|
||||||
modeCommand = make(map[string]CommandRunner)
|
modeCommand = make(map[string]CommandRunner)
|
||||||
modeFlags = make(map[string]*flag.FlagSet)
|
modeFlags = make(map[string]*flag.FlagSet)
|
||||||
|
wantHelp = make(map[string]*bool)
|
||||||
|
|
||||||
// Indirections for replacement by tests
|
// Indirections for replacement by tests
|
||||||
Stderr io.Writer = os.Stderr
|
Stderr io.Writer = os.Stderr
|
||||||
|
@ -100,6 +101,10 @@ func RegisterCommand(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunne
|
||||||
}
|
}
|
||||||
flags := flag.NewFlagSet(mode+" options", flag.ContinueOnError)
|
flags := flag.NewFlagSet(mode+" options", flag.ContinueOnError)
|
||||||
flags.Usage = func() {}
|
flags.Usage = func() {}
|
||||||
|
|
||||||
|
var cmdHelp bool
|
||||||
|
flags.BoolVar(&cmdHelp, "help", false, "Help for this mode.")
|
||||||
|
wantHelp[mode] = &cmdHelp
|
||||||
modeFlags[mode] = flags
|
modeFlags[mode] = flags
|
||||||
modeCommand[mode] = makeCmd(flags)
|
modeCommand[mode] = makeCmd(flags)
|
||||||
}
|
}
|
||||||
|
@ -249,13 +254,11 @@ func Main() {
|
||||||
|
|
||||||
cmdFlags := modeFlags[mode]
|
cmdFlags := modeFlags[mode]
|
||||||
cmdFlags.SetOutput(Stderr)
|
cmdFlags.SetOutput(Stderr)
|
||||||
var cmdHelp bool
|
|
||||||
cmdFlags.BoolVar(&cmdHelp, "help", false, "Help for this mode.")
|
|
||||||
err := cmdFlags.Parse(args[1:])
|
err := cmdFlags.Parse(args[1:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = ErrUsage
|
err = ErrUsage
|
||||||
} else {
|
} else {
|
||||||
if cmdHelp {
|
if *wantHelp[mode] {
|
||||||
help(mode)
|
help(mode)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue