本文整理汇总了Golang中v/io/jiri.X.Stdout方法的典型用法代码示例。如果您正苦于以下问题:Golang X.Stdout方法的具体用法?Golang X.Stdout怎么用?Golang X.Stdout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类v/io/jiri.X
的用法示例。
在下文中一共展示了X.Stdout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: packagesImpl
func packagesImpl(jirix *jiri.X, cl *packagesFlagValues, args []string) error {
mgrs, _, err := availableProfileManagers(jirix, cl.dbPath, args)
if err != nil {
return err
}
cl.target.UseCommandLineEnv()
root := jiri.NewRelPath(cl.root).Join(profileInstaller)
s := jirix.NewSeq()
installPackages := cl.installPackages
// Never ask a subcommand to install packages.
cl.installPackages = false
for _, mgr := range mgrs {
cmds, err := mgr.packageCmds(jirix, cl, root)
if err != nil {
return err
}
for _, cmd := range cmds {
if installPackages {
if err := s.Verbose(true).Last(cmd[0], cmd[1:]...); err != nil {
return err
}
} else {
fmt.Fprintf(jirix.Stdout(), "%s\n", strings.TrimSpace(strings.Join(cmd, " ")))
}
}
}
return nil
}
示例2: AtomicAction
// AtomicAction performs an action 'atomically' by keeping track of successfully
// completed actions in the supplied completion log and re-running them if they
// are not successfully logged therein after deleting the entire contents of the
// dir parameter. Consequently it does not make sense to apply AtomicAction to
// the same directory in sequence.
func AtomicAction(jirix *jiri.X, installFn func() error, dir, message string) error {
atomicFn := func() error {
completionLogPath := filepath.Join(dir, ".complete")
s := jirix.NewSeq()
if dir != "" {
if exists, _ := s.IsDir(dir); exists {
// If the dir exists but the completionLogPath doesn't, then it
// means the previous action didn't finish.
// Remove the dir so we can perform the action again.
if exists, _ := s.IsFile(completionLogPath); !exists {
s.RemoveAll(dir).Done()
} else {
if jirix.Verbose() {
fmt.Fprintf(jirix.Stdout(), "AtomicAction: %s already completed in %s\n", message, dir)
}
return nil
}
}
}
if err := installFn(); err != nil {
if dir != "" {
s.RemoveAll(dir).Done()
}
return err
}
return s.WriteFile(completionLogPath, []byte("completed"), DefaultFilePerm).Done()
}
return jirix.NewSeq().Call(atomicFn, message).Done()
}
示例3: installImpl
func installImpl(jirix *jiri.X, cl *installFlagValues, args []string) error {
mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args)
if err != nil {
return err
}
cl.target.UseCommandLineEnv()
newMgrs := []profileManager{}
for _, mgr := range mgrs {
name := mgr.mgrName()
if !cl.force {
installer, profile := profiles.SplitProfileName(name)
if p := db.LookupProfileTarget(installer, profile, cl.target); p != nil {
fmt.Fprintf(jirix.Stdout(), "%v %v is already installed as %v\n", name, cl.target, p)
continue
}
}
newMgrs = append(newMgrs, mgr)
}
root := jiri.NewRelPath(cl.root).Join(profileInstaller)
for _, mgr := range newMgrs {
if err := mgr.install(jirix, cl, root); err != nil {
return err
}
}
return writeDB(jirix, db, profileInstaller, cl.dbPath)
}
示例4: MissingOSPackages
// MissingOSPackages returns the subset of the supplied packages that are
// missing from the underlying operating system and hence will need to
// be installed.
func MissingOSPackages(jirix *jiri.X, pkgs []string) ([]string, error) {
installedPkgs := map[string]bool{}
switch runtime.GOOS {
case "linux":
if IsFNLHost() {
fmt.Fprintf(jirix.Stdout(), "skipping %v on FNL host\n", pkgs)
break
}
var err error
installedPkgs, err = linuxList(jirix, pkgs)
if err != nil {
return nil, err
}
case "darwin":
var err error
installedPkgs, err = brewList(jirix)
if err != nil {
return nil, err
}
}
missing := []string{}
for _, pkg := range pkgs {
if !installedPkgs[pkg] {
missing = append(missing, pkg)
}
}
return missing, nil
}
示例5: uninstall
func (ip *inproc) uninstall(jirix *jiri.X, cl *uninstallFlagValues, root jiri.RelPath) error {
profile := ip.db.LookupProfile(ip.installer, ip.name)
if profile == nil {
fmt.Fprintf(jirix.Stdout(), "%s is not installed\n", ip.qname)
return nil
}
mgr := profilesmanager.LookupManager(ip.qname)
var targets []*profiles.Target
if cl.allTargets {
targets = profile.Targets()
} else {
def, err := targetAtDefaultVersion(mgr, cl.target)
if err != nil {
return err
}
targets = []*profiles.Target{&def}
}
for _, target := range targets {
if err := mgr.Uninstall(jirix, ip.db, root, *target); err != nil {
logResult(jirix, "Uninstall", mgr, *target, err)
return err
}
logResult(jirix, "Uninstall", mgr, *target, nil)
}
return nil
}
示例6: update
func (ip *inproc) update(jirix *jiri.X, cl *updateFlagValues, root jiri.RelPath) error {
profile := ip.db.LookupProfile(ip.installer, ip.name)
if profile == nil {
// silently ignore uninstalled profile.
return nil
}
mgr := profilesmanager.LookupManager(ip.qname)
vi := mgr.VersionInfo()
for _, target := range profile.Targets() {
if vi.IsTargetOlderThanDefault(target.Version()) {
// Check if default target is already installed.
defTarget := *target
defTarget.SetVersion(vi.Default())
if profiles.FindTarget(profile.Targets(), &defTarget) != nil {
// Default target is already installed. Skip.
continue
}
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "Updating %s %s from %q to %s\n", ip.qname, target, target.Version(), vi)
}
err := mgr.Install(jirix, ip.db, root, defTarget)
logResult(jirix, "Update", mgr, defTarget, err)
if err != nil {
return err
}
} else {
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "%s %s at %q is up to date(%s)\n", ip.qname, target, target.Version(), vi)
}
}
}
return nil
}
示例7: brewList
func brewList(jirix *jiri.X) (map[string]bool, error) {
var out bytes.Buffer
err := jirix.NewSeq().Capture(&out, &out).Last("brew", "list")
if err != nil || tool.VerboseFlag {
fmt.Fprintf(jirix.Stdout(), "%s", out.String())
}
scanner := bufio.NewScanner(&out)
pkgs := map[string]bool{}
for scanner.Scan() {
pkgs[scanner.Text()] = true
}
return pkgs, err
}
示例8: runCLMail
// runCLMail is a wrapper that sets up and runs a review instance across
// multiple projects.
func runCLMail(jirix *jiri.X, _ []string) error {
mp, err := initForMultiPart(jirix)
if err != nil {
return err
}
if mp.clean {
if err := mp.cleanMultiPartMetadata(jirix); err != nil {
return err
}
return nil
}
if mp.current {
return runCLMailCurrent(jirix, []string{})
}
// multipart mode
if err := mp.writeMultiPartMetadata(jirix); err != nil {
mp.cleanMultiPartMetadata(jirix)
return err
}
if err := runCLMailCurrent(jirix, []string{}); err != nil {
return err
}
git := gitutil.New(jirix.NewSeq())
branch, err := git.CurrentBranchName()
if err != nil {
return err
}
initialMessage, err := strippedGerritCommitMessage(jirix, branch)
if err != nil {
return err
}
s := jirix.NewSeq()
tmp, err := s.TempFile("", branch+"-")
if err != nil {
return err
}
defer func() {
tmp.Close()
os.Remove(tmp.Name())
}()
if _, err := io.WriteString(tmp, initialMessage); err != nil {
return err
}
// Use Capture to make sure that all output from the subcommands is
// sent to stdout/stderr.
flags := clMailMultiFlags()
flags = append(flags, "--commit-message-body-file="+tmp.Name())
return s.Capture(jirix.Stdout(), jirix.Stderr()).Last("jiri", mp.commandline(mp.currentKey, flags)...)
}
示例9: uninstallImpl
func uninstallImpl(jirix *jiri.X, cl *uninstallFlagValues, args []string) error {
mgrs, db, err := availableProfileManagers(jirix, cl.dbPath, args)
if err != nil {
return err
}
if cl.allTargets && cl.target.IsSet() {
fmt.Fprintf(jirix.Stdout(), "ignore target (%v) when used in conjunction with --all-targets\n", cl.target)
}
root := jiri.NewRelPath(cl.root).Join(profileInstaller)
for _, mgr := range mgrs {
if err := mgr.uninstall(jirix, cl, root); err != nil {
return err
}
}
return writeDB(jirix, db, profileInstaller, cl.dbPath)
}
示例10: linuxInstall
func linuxInstall(jirix *jiri.X, pkgs []string) []string {
aptitude, yum, pacman := UsingAptitude(jirix), UsingYum(jirix), UsingPacman(jirix)
var cmd []string
switch {
case aptitude:
cmd = append(cmd, "apt-get", "install", "-y")
case yum:
cmd = append(cmd, "yum", "install", "-y")
case pacman:
cmd = append(cmd, "pacman", "-S", "--noconfirm")
default:
fmt.Fprintf(jirix.Stdout(), "no usable package manager found, tested for aptitude, yum and pacman")
return nil
}
return append(cmd, pkgs...)
}
示例11: OSPackageInstallCommands
// OSPackagesInstallCommands returns the list of commands required to
// install the specified packages on the underlying operating system.
func OSPackageInstallCommands(jirix *jiri.X, pkgs []string) [][]string {
cmds := make([][]string, 0, 1)
switch runtime.GOOS {
case "linux":
if IsFNLHost() {
fmt.Fprintf(jirix.Stdout(), "skipping %v on FNL host\n", pkgs)
break
}
if len(pkgs) > 0 {
cmds = append(cmds, linuxInstall(jirix, pkgs))
}
case "darwin":
if len(pkgs) > 0 {
return append(cmds, append([]string{"brew", "install"}, pkgs...))
}
}
return cmds
}
示例12: cleanup
func (ip *inproc) cleanup(jirix *jiri.X, cl *cleanupFlagValues, root jiri.RelPath) error {
if cl.gc {
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "Removing targets older than the default version for %s\n", ip.qname)
}
if err := cleanupGC(jirix, ip.db, root, cl.verbose, ip.qname); err != nil {
return fmt.Errorf("gc: %v", err)
}
}
if cl.rmAll {
if cl.verbose {
fmt.Fprintf(jirix.Stdout(), "Removing profile manifest and all profile output files\n")
}
if err := cleanupRmAll(jirix, ip.db, root); err != nil {
return err
}
}
return nil
}
示例13: runEnv
func runEnv(jirix *jiri.X, args []string) error {
if len(envFlags.Profiles) == 0 {
return fmt.Errorf("no profiles were specified using --profiles")
}
rd, err := profilesreader.NewReader(jirix, envFlags.ProfilesMode, envFlags.DBFilename)
if err != nil {
return err
}
profileNames := strings.Split(envFlags.Profiles, ",")
if err := rd.ValidateRequestedProfilesAndTarget(profileNames, envFlags.Target); err != nil {
return err
}
rd.MergeEnvFromProfiles(envFlags.MergePolicies, envFlags.Target, profileNames...)
out := fmtVars(rd.ToMap(), args)
if len(out) > 0 {
fmt.Fprintln(jirix.Stdout(), out)
}
return nil
}
示例14: cleanupRmAll
func cleanupRmAll(jirix *jiri.X, db *profiles.DB, root jiri.RelPath) error {
s := jirix.NewSeq()
if err := s.AssertFileExists(db.Path()).Remove(db.Path()).Done(); err != nil && !runutil.IsNotExist(err) {
return err
} else {
if err := s.AssertDirExists(db.Path()).RemoveAll(db.Path()).Done(); err != nil && !runutil.IsNotExist(err) {
return err
}
}
d := root.Abs(jirix)
err := s.AssertDirExists(d).
Run("chmod", "-R", "u+w", d).
RemoveAll(d).
Done()
if err == nil || runutil.IsNotExist(err) {
fmt.Fprintf(jirix.Stdout(), "success\n")
return nil
} else {
fmt.Fprintf(jirix.Stdout(), "%v\n", err)
}
return err
}
示例15: logResult
func logResult(jirix *jiri.X, action string, mgr profiles.Manager, target profiles.Target, err error) {
fmt.Fprintf(jirix.Stdout(), "%s: %s %s: ", action, profiles.QualifiedProfileName(mgr.Installer(), mgr.Name()), target)
if err == nil {
fmt.Fprintf(jirix.Stdout(), "success\n")
} else {
fmt.Fprintf(jirix.Stdout(), "%v\n", err)
}
}