Browse Source

Add the ability to disable any normal status output

Vadim Markovtsev 7 years ago
parent
commit
6e5ab22ec3
2 changed files with 19 additions and 15 deletions
  1. 2 2
      .travis.yml
  2. 17 13
      cmd/hercules/main.go

+ 2 - 2
.travis.yml

@@ -35,8 +35,8 @@ install:
 script:
   - go test -v -cpu=1,2 -coverprofile=coverage.txt -covermode=count gopkg.in/src-d/hercules.v3
   - $GOPATH/bin/hercules -version
-  - $GOPATH/bin/hercules -burndown -burndown-files -burndown-people -couples https://github.com/src-d/hercules | python3 labours.py -m all -o out --backend Agg --disable-projector
-  - $GOPATH/bin/hercules -burndown -burndown-files -burndown-people -couples -pb https://github.com/src-d/hercules | python3 labours.py -f pb -m all -o out --backend Agg --disable-projector
+  - $GOPATH/bin/hercules -burndown -burndown-files -burndown-people -couples -quiet https://github.com/src-d/hercules | python3 labours.py -m all -o out --backend Agg --disable-projector
+  - $GOPATH/bin/hercules -burndown -burndown-files -burndown-people -couples -quiet -pb https://github.com/src-d/hercules | python3 labours.py -f pb -m all -o out --backend Agg --disable-projector
 
 after_success:
   - bash <(curl -s https://codecov.io/bash)

+ 17 - 13
cmd/hercules/main.go

@@ -72,7 +72,7 @@ func (writer OneLineWriter) Write(p []byte) (n int, err error) {
 	return
 }
 
-func loadRepository(uri string) *git.Repository {
+func loadRepository(uri string, disableStatus bool) *git.Repository {
 	var repository *git.Repository
 	var backend storage.Storer
 	var err error
@@ -90,12 +90,15 @@ func loadRepository(uri string) *git.Repository {
 		} else {
 			backend = memory.NewStorage()
 		}
-		fmt.Fprint(os.Stderr, "connecting...\r")
-		repository, err = git.Clone(backend, nil, &git.CloneOptions{
-			URL: uri,
-			Progress: OneLineWriter{Writer: os.Stderr},
-		})
-		fmt.Fprint(os.Stderr, strings.Repeat(" ", 80) + "\r")
+		cloneOptions := &git.CloneOptions{URL: uri}
+		if !disableStatus {
+			fmt.Fprint(os.Stderr, "connecting...\r")
+			cloneOptions.Progress = OneLineWriter{Writer: os.Stderr}
+		}
+		repository, err = git.Clone(backend, nil, cloneOptions)
+		if !disableStatus {
+			fmt.Fprint(os.Stderr, strings.Repeat(" ", 80)+"\r")
+		}
 	} else {
 		if uri[len(uri)-1] == os.PathSeparator {
 			uri = uri[:len(uri)-1]
@@ -144,9 +147,7 @@ func loadPlugins() {
 
 func main() {
 	loadPlugins()
-	var printVersion bool
-	var protobuf bool
-	var profile bool
+	var printVersion, protobuf, profile, disableStatus bool
 	var commitsFile string
 	flag.BoolVar(&profile, "profile", false, "Collect the profile to hercules.pprof.")
 	flag.StringVar(&commitsFile, "commits", "", "Path to the text file with the "+
@@ -155,6 +156,7 @@ func main() {
 		"separate line. The first hash is the root.")
 	flag.BoolVar(&protobuf, "pb", false, "The output format will be Protocol Buffers instead of YAML.")
 	flag.BoolVar(&printVersion, "version", false, "Print version information and exit.")
+	flag.BoolVar(&disableStatus, "quiet", false, "Do not print status updates to stderr.")
 	facts, deployChoices := hercules.Registry.AddFlags()
 	flag.Parse()
 
@@ -175,12 +177,12 @@ func main() {
 		os.Exit(1)
 	}
 	uri := flag.Arg(0)
-	repository := loadRepository(uri)
+	repository := loadRepository(uri, disableStatus)
 
 	// core logic
 	pipeline := hercules.NewPipeline(repository)
 	pipeline.SetFeaturesFromFlags()
-	if terminal.IsTerminal(int(os.Stderr.Fd())) {
+	if terminal.IsTerminal(int(os.Stderr.Fd())) && !disableStatus {
 		progress := mpb.New(mpb.Output(os.Stderr))
 		defer progress.Stop()
 		var bar *mpb.Bar
@@ -229,7 +231,9 @@ func main() {
 	if err != nil {
 		panic(err)
 	}
-	fmt.Fprint(os.Stderr, "writing...\r")
+	if !disableStatus {
+		fmt.Fprint(os.Stderr, "writing...\r")
+	}
 	begin := commits[0].Author.When.Unix()
 	end := commits[len(commits)-1].Author.When.Unix()
 	if !protobuf {