func ExampleProfileTarget() { var target profiles.Target flags := flag.NewFlagSet("test", flag.ContinueOnError) profiles.RegisterTargetAndEnvFlags(flags, &target) flags.Parse([]string{"--target=arm-linux", "--env=A=B,C=D", "--env=E=F"}) fmt.Println(target.String()) fmt.Println(target.DebugString()) // Output: // arm-linux@ // arm-linux@ dir: --env=A=B,C=D,E=F envvars:[] }
// ensureAction ensures that the requested profile and target // is installed/uninstalled, installing/uninstalling it if and only if necessary. func ensureAction(jirix *jiri.X, pdb *profiles.DB, action profiles.Action, installer, profile string, root jiri.RelPath, target profiles.Target) error { verb := "" switch action { case profiles.Install: verb = "install" case profiles.Uninstall: verb = "uninstall" default: return fmt.Errorf("unrecognised action %v", action) } if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%s %v %s\n", verb, action, target) } if t := pdb.LookupProfileTarget(installer, profile, target); t != nil { if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%v %v is already %sed as %v\n", profile, target, verb, t) } return nil } mgr := LookupManager(profiles.QualifiedProfileName(installer, profile)) if mgr == nil { return fmt.Errorf("profile %v is not supported", profile) } version, err := mgr.VersionInfo().Select(target.Version()) if err != nil { return err } target.SetVersion(version) if jirix.Verbose() { fmt.Fprintf(jirix.Stdout(), "%s %s %s\n", verb, profile, target.DebugString()) } if action == profiles.Install { return mgr.Install(jirix, pdb, root, target) } return mgr.Uninstall(jirix, pdb, root, target) }