Exemplo n.º 1
0
func Init(defaultManifestFilename string) {
	targetFlag = profiles.DefaultTarget()

	var err error
	rootDir, err = project.JiriRoot()
	if err != nil {
		panic(err)
	}
	manifest := filepath.Join(rootDir, defaultManifestFilename)

	// Every sub-command accepts: --manifest
	for _, fs := range []*flag.FlagSet{
		&cmdInstall.Flags,
		&cmdUpdate.Flags,
		&cmdCleanup.Flags,
		&cmdUninstall.Flags,
		&cmdEnv.Flags,
		&cmdList.Flags,
		&cmdRecreate.Flags} {
		profiles.RegisterManifestFlag(fs, &manifestFlag, manifest)
	}

	// install accepts: --target and, --env.
	profiles.RegisterTargetAndEnvFlags(&cmdInstall.Flags, &targetFlag)

	// uninstall and env accept: --target,
	for _, fs := range []*flag.FlagSet{
		&cmdUninstall.Flags,
		&cmdEnv.Flags} {
		profiles.RegisterTargetFlag(fs, &targetFlag)
	}

	// uninstall accept --all-targets but with different defaults.
	cmdUninstall.Flags.BoolVar(&allFlag, "all-targets", false, "apply to all targets for the specified profile(s)")

	// update accepts --v
	cmdUpdate.Flags.BoolVar(&verboseFlag, "v", false, "print more detailed information")

	// list accepts --show-manifest, --availabe, --v
	cmdList.Flags.BoolVar(&showManifestFlag, "show-manifest", false, "print out the manifest file")
	cmdList.Flags.BoolVar(&availableFlag, "available", false, "print the list of available profiles")
	cmdList.Flags.BoolVar(&verboseFlag, "v", false, "print more detailed information")

	// env accepts --profile
	cmdEnv.Flags.StringVar(&profileFlag, "profile", "", "the profile whose environment is to be displayed")

	for _, mgr := range profiles.Managers() {
		profiles.LookupManager(mgr).AddFlags(&cmdInstall.Flags, profiles.Install)
		profiles.LookupManager(mgr).AddFlags(&cmdUninstall.Flags, profiles.Uninstall)
	}
}
Exemplo n.º 2
0
func RunMojoShellForV23ProxyTests(mojoFile, v23ProxyRoot string, args []string) *exec.Cmd {
	configFile := filepath.Join(v23ProxyRoot, "mojoconfig")
	mojoUrl := fmt.Sprintf("https://mojo.v.io/%s", mojoFile)
	buildDir := filepath.Join(v23ProxyRoot, "gen", "mojo", "linux_amd64")
	configAliases := map[string]string{
		"V23PROXY_DIR":       v23ProxyRoot,
		"V23PROXY_BUILD_DIR": buildDir,
	}
	argsFor := map[string][]string{
		mojoUrl:                     args,
		"mojo:dart_content_handler": []string{"--enable-strict-mode"},
	}
	target := profiles.DefaultTarget()
	return RunMojoShell(mojoUrl, configFile, configAliases, argsFor, target)
}
Exemplo n.º 3
0
func TestFindTarget(t *testing.T) {
	t1 := &profiles.Target{}
	t1.Set("a-o")
	ts := []*profiles.Target{t1}
	prev := os.Getenv("GOARCH")
	if len(prev) > 0 {
		// Clear GOARCH so that DefaultTarget is not set.
		os.Setenv("GOARCH", "")
		defer os.Setenv("GOARCH", prev)
	}
	def := profiles.DefaultTarget()
	if got, want := profiles.FindTargetWithDefault(ts, &def), t1; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}
	t2 := &profiles.Target{}
	t2.Set("a-o1")
	ts = append(ts, t2)
	if got := profiles.FindTarget(ts, &def); got != nil {
		t.Errorf("got %v, want nil", got)
	}

	w := &profiles.Target{}
	w.Set("a-o")
	if got, want := profiles.FindTarget(ts, w), t1; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}

	w.Set("a-o1")
	if got, want := profiles.FindTarget(ts, w), t2; !got.Match(want) {
		t.Errorf("got %v, want %v", got, want)
	}

	w.Set("c-d")
	if got := profiles.FindTarget(ts, w); got != nil {
		t.Errorf("got %v, want nil", got)
	}
}