[artifacts] Add verbose option.

Logs for individual file downloads will only be printed if -v is
provided.

Bug: 72039
Change-Id: Ia9de3013046bd965ea62a0e84bc577a35376ac26
Reviewed-on: https://fuchsia-review.googlesource.com/c/infra/infra/+/504605
Commit-Queue: Ina Huh <ihuh@google.com>
Fuchsia-Auto-Submit: Ina Huh <ihuh@google.com>
Reviewed-by: Erick Tryzelaar <etryzelaar@google.com>
diff --git a/cmd/artifacts/copy.go b/cmd/artifacts/copy.go
index 32efb0b..12ca628 100644
--- a/cmd/artifacts/copy.go
+++ b/cmd/artifacts/copy.go
@@ -50,6 +50,9 @@
 
 	// The maximum number of concurrent downloading processes.
 	j int
+
+	// Whether to print verbose logs.
+	verbose bool
 }
 
 func (*CopyCommand) Name() string {
@@ -73,6 +76,7 @@
 		"If false, src will be taken as a relative path to the build-specific directory under the Cloud Storage bucket.")
 	f.StringVar(&cmd.srcsFile, "srcs-file", "", "The file containing the source paths of the artifacts to download. These should be listed one path per line.")
 	f.IntVar(&cmd.j, "j", 30, "The maximum number of concurrent downloading processes.")
+	f.BoolVar(&cmd.verbose, "v", false, "Whether to print verbose logs.")
 }
 
 func (cmd *CopyCommand) Execute(ctx context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
@@ -176,7 +180,9 @@
 				logStr = fmt.Sprintf("failed to download %s: %v", logStr, err)
 			}
 			mu.Lock()
-			fmt.Fprintln(stdout, logStr)
+			if cmd.verbose || err != nil {
+				fmt.Fprintln(stdout, logStr)
+			}
 			downloadedFileSizes = append(downloadedFileSizes, size)
 			mu.Unlock()
 			if err != nil {
diff --git a/cmd/artifacts/copy_test.go b/cmd/artifacts/copy_test.go
index 97e96ab..d6c1d87 100644
--- a/cmd/artifacts/copy_test.go
+++ b/cmd/artifacts/copy_test.go
@@ -214,6 +214,7 @@
 				dest:     tt.dest,
 				srcsFile: srcsFile,
 				j:        1,
+				verbose:  true,
 			}
 			testStdout := &bytes.Buffer{}
 			stdout = testStdout