コード例 #1
0
ファイル: list.go プロジェクト: zaphod-concur/gb
func list(ctx *gb.Context, args []string) error {
	gb.Debugf("list: %v", args)
	if formatStdin {
		var formatBuffer bytes.Buffer
		io.Copy(&formatBuffer, os.Stdin)
		format = formatBuffer.String()
	}
	args = cmd.ImportPaths(ctx, cmd.MustGetwd(), args)
	pkgs, err := cmd.ResolvePackages(ctx, args...)
	if err != nil {
		gb.Fatalf("unable to resolve: %v", err)
	}

	if jsonOutput {
		views := make([]*PackageView, 0, len(pkgs))
		for _, pkg := range pkgs {
			views = append(views, NewPackageView(pkg))
		}
		encoder := json.NewEncoder(os.Stdout)
		if err := encoder.Encode(views); err != nil {
			return fmt.Errorf("Error occurred during json encoding: %v", err)
		}
	} else {
		tmpl, err := template.New("list").Parse(format)
		if err != nil {
			return fmt.Errorf("unable to parse template %q: %v", format, err)
		}

		for _, pkg := range pkgs {
			if err := tmpl.Execute(os.Stdout, pkg); err != nil {
				return fmt.Errorf("unable to execute template: %v", err)
			}
			fmt.Fprintln(os.Stdout)
		}
	}
	return nil
}
コード例 #2
0
ファイル: build.go プロジェクト: zaphod-concur/gb
	-v
		increases verbosity, effectively lowering the output level from INFO to DEBUG.
	-ldflags 'flag list'
		arguments to pass on each linker invocation.

The list flags accept a space-separated list of strings. To embed spaces in an element in the list, surround it with either single or double quotes.

For more about specifying packages, see 'gb help packages'. For more about where packages and binaries are installed, run 'gb help project'.`,
	Run: func(ctx *gb.Context, args []string) error {
		// TODO(dfc) run should take a *gb.Context not a *gb.Project
		t0 := time.Now()
		ctx.Force = F
		ctx.SkipInstall = FF
		defer func() {
			gb.Debugf("build duration: %v %v", time.Since(t0), ctx.Statistics.String())
		}()

		pkgs, err := cmd.ResolvePackages(ctx, args...)
		if err != nil {
			ctx.Destroy()
			return err
		}
		if err := gb.Build(pkgs...); err != nil {
			ctx.Destroy()
			return err
		}
		return ctx.Destroy()
	},
	AddFlags: addBuildFlags,
}