mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-20 11:58:39 +00:00
release/dist/cli: add --verbose to print subcommand output
By default, cmd/dist only prints the output of failed commands. With this, you can turn all the noisy output back on. Updates tailscale/corp#9045 Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
parent
0df11253ec
commit
311352d195
3
release/dist/cli/cli.go
vendored
3
release/dist/cli/cli.go
vendored
@ -60,6 +60,7 @@ func CLI(getTargets func() ([]dist.Target, error)) *ffcli.Command {
|
|||||||
FlagSet: (func() *flag.FlagSet {
|
FlagSet: (func() *flag.FlagSet {
|
||||||
fs := flag.NewFlagSet("build", flag.ExitOnError)
|
fs := flag.NewFlagSet("build", flag.ExitOnError)
|
||||||
fs.StringVar(&buildArgs.manifest, "manifest", "", "manifest file to write")
|
fs.StringVar(&buildArgs.manifest, "manifest", "", "manifest file to write")
|
||||||
|
fs.BoolVar(&buildArgs.verbose, "verbose", false, "verbose logging")
|
||||||
return fs
|
return fs
|
||||||
})(),
|
})(),
|
||||||
LongHelp: strings.TrimSpace(`
|
LongHelp: strings.TrimSpace(`
|
||||||
@ -88,6 +89,7 @@ func runList(ctx context.Context, filters []string, targets []dist.Target) error
|
|||||||
|
|
||||||
var buildArgs struct {
|
var buildArgs struct {
|
||||||
manifest string
|
manifest string
|
||||||
|
verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func runBuild(ctx context.Context, filters []string, targets []dist.Target) error {
|
func runBuild(ctx context.Context, filters []string, targets []dist.Target) error {
|
||||||
@ -109,6 +111,7 @@ func runBuild(ctx context.Context, filters []string, targets []dist.Target) erro
|
|||||||
return fmt.Errorf("creating build context: %w", err)
|
return fmt.Errorf("creating build context: %w", err)
|
||||||
}
|
}
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
b.Verbose = buildArgs.verbose
|
||||||
|
|
||||||
out, err := b.Build(tgts)
|
out, err := b.Build(tgts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
19
release/dist/dist.go
vendored
19
release/dist/dist.go
vendored
@ -32,10 +32,14 @@ type Target interface {
|
|||||||
type Build struct {
|
type Build struct {
|
||||||
// Repo is a path to the root Go module for the build.
|
// Repo is a path to the root Go module for the build.
|
||||||
Repo string
|
Repo string
|
||||||
// Tmp is a temporary directory that gets deleted when the Builder is closed.
|
|
||||||
Tmp string
|
|
||||||
// Out is where build artifacts are written.
|
// Out is where build artifacts are written.
|
||||||
Out string
|
Out string
|
||||||
|
// Verbose is whether to print all command output, rather than just failed
|
||||||
|
// commands.
|
||||||
|
Verbose bool
|
||||||
|
|
||||||
|
// Tmp is a temporary directory that gets deleted when the Builder is closed.
|
||||||
|
Tmp string
|
||||||
// Go is the path to the Go binary to use for building.
|
// Go is the path to the Go binary to use for building.
|
||||||
Go string
|
Go string
|
||||||
// Version is the version info of the build.
|
// Version is the version info of the build.
|
||||||
@ -198,7 +202,7 @@ func (b *Build) BuildGoBinary(path string, env map[string]string) (string, error
|
|||||||
sort.Strings(envStrs)
|
sort.Strings(envStrs)
|
||||||
log.Printf("Building %s (with env %s)", path, strings.Join(envStrs, " "))
|
log.Printf("Building %s (with env %s)", path, strings.Join(envStrs, " "))
|
||||||
buildDir := b.TmpDir()
|
buildDir := b.TmpDir()
|
||||||
cmd := b.Command(b.Repo, b.Go, "build", "-o", buildDir, path)
|
cmd := b.Command(b.Repo, b.Go, "build", "-v", "-o", buildDir, path)
|
||||||
for k, v := range env {
|
for k, v := range env {
|
||||||
cmd.Cmd.Env = append(cmd.Cmd.Env, k+"="+v)
|
cmd.Cmd.Env = append(cmd.Cmd.Env, k+"="+v)
|
||||||
}
|
}
|
||||||
@ -218,8 +222,13 @@ func (b *Build) Command(dir, cmd string, args ...string) *Command {
|
|||||||
ret := &Command{
|
ret := &Command{
|
||||||
Cmd: exec.Command(cmd, args...),
|
Cmd: exec.Command(cmd, args...),
|
||||||
}
|
}
|
||||||
ret.Cmd.Stdout = &ret.Output
|
if b.Verbose {
|
||||||
ret.Cmd.Stderr = &ret.Output
|
ret.Cmd.Stdout = os.Stdout
|
||||||
|
ret.Cmd.Stderr = os.Stderr
|
||||||
|
} else {
|
||||||
|
ret.Cmd.Stdout = &ret.Output
|
||||||
|
ret.Cmd.Stderr = &ret.Output
|
||||||
|
}
|
||||||
// dist always wants to use gocross if any Go is involved.
|
// dist always wants to use gocross if any Go is involved.
|
||||||
ret.Cmd.Env = append(os.Environ(), "TS_USE_GOCROSS=1")
|
ret.Cmd.Env = append(os.Environ(), "TS_USE_GOCROSS=1")
|
||||||
ret.Cmd.Dir = dir
|
ret.Cmd.Dir = dir
|
||||||
|
Loading…
x
Reference in New Issue
Block a user