Exemple #1
0
func TestReaderParent(t *testing.T) {
	profilescmdline.Reset()
	p := parent
	args := []string{"--profiles-db=foo", "--skip-profiles"}
	var rf profilescmdline.ReaderFlagValues
	// If RegisterReaderCommandsUsingParent is called, the common reader
	// flags are hosted by the parent command.
	profilescmdline.RegisterReaderCommandsUsingParent(&p, &rf, "", "")
	if got, want := len(p.Children), 2; got != want {
		t.Errorf("got %v, want %v", got, want)
	}
	if err := p.Children[0].Flags.Parse(args); err == nil {
		t.Errorf("this should have failed")
	}
	if err := p.Flags.Parse(args); err != nil {
		t.Error(err)
	}
	if got, want := rf.DBFilename, "foo"; got != want {
		t.Errorf("got %v, want %v", got, want)
	}
	if got, want := rf.ProfilesMode, profilesreader.SkipProfiles; got != want {
		t.Errorf("got %v, want %v", got, want)
	}

	profilescmdline.Reset()
	p = parent
	profilescmdline.RegisterReaderFlags(&p.Flags, &rf, "", "")
	if got, want := len(p.Children), 0; got != want {
		t.Errorf("got %v, want %v", got, want)
	}
	if err := p.Flags.Parse(args); err != nil {
		t.Fatal(err)
	}
	if got, want := rf.DBFilename, "foo"; got != want {
		t.Errorf("got %v, want %v", got, want)
	}

	profilescmdline.Reset()
	p = parent
	// If RegisterReaderCommands is not called, the common reader
	// flags are hosted by the subcommands.
	profilescmdline.RegisterReaderCommands(&p, "", "")
	if err := p.Flags.Parse(args); err == nil {
		t.Fatal(fmt.Errorf("this should have failed"))
	}
	if err := p.Children[0].Flags.Parse([]string{"--profiles=a,b"}); err != nil {
		t.Fatal(err)
	}
	// NOTE, that we can't access the actual values of the flags when they
	// are hosted by the subcommands.
}
Exemple #2
0
func registerCommonFlags(flags *flag.FlagSet, values *runpFlagValues) {
	profilescmdline.RegisterReaderFlags(flags, &values.ReaderFlagValues, "", jiri.ProfilesDBDir)
	flags.BoolVar(&values.verbose, "v", false, "Print verbose logging information")
	flags.StringVar(&values.projectKeys, "projects", "", "A Regular expression specifying project keys to run commands in. By default, runp will use projects that have the same branch checked as the current project unless it is run from outside of a project in which case it will default to using all projects.")
	flags.BoolVar(&values.hasUncommitted, "has-uncommitted", false, "If specified, match projects that have, or have no, uncommitted changes")
	flags.BoolVar(&values.hasUntracked, "has-untracked", false, "If specified, match projects that have, or have no, untracked files")
	flags.BoolVar(&values.hasGerritMessage, "has-gerrit-message", false, "If specified, match branches that have, or have no, gerrit message")
	flags.BoolVar(&values.interactive, "interactive", true, "If set, the command to be run is interactive and should not have its stdout/stderr manipulated. This flag cannot be used with -show-name-prefix, -show-key-prefix or -collate-stdout.")
	flags.BoolVar(&values.showNamePrefix, "show-name-prefix", false, "If set, each line of output from each project will begin with the name of the project followed by a colon. This is intended for use with long running commands where the output needs to be streamed. Stdout and stderr are spliced apart. This flag cannot be used with -interactive, -show-key-prefix or -collate-stdout.")
	flags.BoolVar(&values.showKeyPrefix, "show-key-prefix", false, "If set, each line of output from each project will begin with the key of the project followed by a colon. This is intended for use with long running commands where the output needs to be streamed. Stdout and stderr are spliced apart. This flag cannot be used with -interactive, -show-name-prefix or -collate-stdout")
	flags.BoolVar(&values.collateOutput, "collate-stdout", true, "Collate all stdout output from each parallel invocation and display it as if had been generated sequentially. This flag cannot be used with -show-name-prefix, -show-key-prefix or -interactive.")
	flags.BoolVar(&values.exitOnError, "exit-on-error", false, "If set, all commands will killed as soon as one reports an error, otherwise, each will run to completion.")
	flags.StringVar(&values.hasBranch, "has-branch", "", "A regular expression specifying branch names to use in matching projects. A project will match if the specified branch exists, even if it is not checked out.")
}