Merge pull request #124 from hangxie/add-quiet-option

Add --quiet option to suppress git progress output
This commit is contained in:
Frederic Branczyk 2020-07-08 09:42:44 +02:00 committed by GitHub
commit ada055a225
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View file

@ -92,6 +92,7 @@ Flags:
--version Show application version. --version Show application version.
--jsonnetpkg-home="vendor" --jsonnetpkg-home="vendor"
The directory used to cache packages in. The directory used to cache packages in.
-q, --quiet Suppress any output from git command.
Commands: Commands:
help [<command>...] help [<command>...]

View file

@ -22,6 +22,8 @@ import (
"github.com/fatih/color" "github.com/fatih/color"
"github.com/pkg/errors" "github.com/pkg/errors"
"gopkg.in/alecthomas/kingpin.v2" "gopkg.in/alecthomas/kingpin.v2"
"github.com/jsonnet-bundler/jsonnet-bundler/pkg"
) )
const ( const (
@ -49,6 +51,8 @@ func Main() int {
a.Flag("jsonnetpkg-home", "The directory used to cache packages in."). a.Flag("jsonnetpkg-home", "The directory used to cache packages in.").
Default("vendor").StringVar(&cfg.JsonnetHome) Default("vendor").StringVar(&cfg.JsonnetHome)
a.Flag("quiet", "Suppress any output from git command.").
Short('q').BoolVar(&pkg.GitQuiet)
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile") initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")

View file

@ -48,13 +48,17 @@ func NewGitPackage(source *deps.Git) Interface {
} }
} }
var GitQuiet = false
func downloadGitHubArchive(filepath string, url string) error { func downloadGitHubArchive(filepath string, url string) error {
// Get the data // Get the data
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return err return err
} }
color.Cyan("GET %s %d", url, resp.StatusCode) if !GitQuiet {
color.Cyan("GET %s %d", url, resp.StatusCode)
}
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
return fmt.Errorf("unexpected status code %d", resp.StatusCode) return fmt.Errorf("unexpected status code %d", resp.StatusCode)
} }
@ -240,8 +244,13 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st
gitCmd := func(args ...string) *exec.Cmd { gitCmd := func(args ...string) *exec.Cmd {
cmd := exec.CommandContext(ctx, "git", args...) cmd := exec.CommandContext(ctx, "git", args...)
cmd.Stdin = os.Stdin cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout if GitQuiet {
cmd.Stderr = os.Stderr cmd.Stdout = nil
cmd.Stderr = nil
} else {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
cmd.Dir = tmpDir cmd.Dir = tmpDir
return cmd return cmd
} }