Browse Source

Make release output quieter

One doesn't usually care about skipped or ignored things, so exclude
them from output by default. Change the `--verbose` flag (shortcut
`-v`) to be a level of verbosity, s.t. `-vv` gives all output (skipped
and ignored things as well as successes and errors).
Michael Bridgen 2 years ago
parent
commit
dcecac4dae
6 changed files with 23 additions and 14 deletions
  1. 2
    2
      cmd/fluxctl/await.go
  2. 2
    2
      cmd/fluxctl/format.go
  3. 1
    1
      cmd/fluxctl/policy_cmd.go
  4. 1
    1
      cmd/fluxctl/release_cmd.go
  5. 11
    2
      update/print.go
  6. 6
    6
      update/print_test.go

+ 2
- 2
cmd/fluxctl/await.go View File

@@ -18,13 +18,13 @@ var ErrTimeout = errors.New("timeout")
18 18
 
19 19
 // await polls for a job to complete, then for the resulting commit to
20 20
 // be applied
21
-func await(ctx context.Context, stdout, stderr io.Writer, client api.Client, jobID job.ID, apply, verbose bool) error {
21
+func await(ctx context.Context, stdout, stderr io.Writer, client api.Client, jobID job.ID, apply bool, verbosity int) error {
22 22
 	metadata, err := awaitJob(ctx, client, jobID)
23 23
 	if err != nil && err.Error() != git.ErrNoChanges.Error() {
24 24
 		return err
25 25
 	}
26 26
 	if metadata.Result != nil {
27
-		update.PrintResults(stdout, metadata.Result, verbose)
27
+		update.PrintResults(stdout, metadata.Result, verbosity)
28 28
 	}
29 29
 	if metadata.Revision != "" {
30 30
 		fmt.Fprintf(stderr, "Commit pushed:\t%s\n", metadata.ShortRevision())

+ 2
- 2
cmd/fluxctl/format.go View File

@@ -11,11 +11,11 @@ import (
11 11
 )
12 12
 
13 13
 type outputOpts struct {
14
-	verbose bool
14
+	verbosity int
15 15
 }
16 16
 
17 17
 func AddOutputFlags(cmd *cobra.Command, opts *outputOpts) {
18
-	cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "include ignored controllers in output")
18
+	cmd.Flags().CountVarP(&opts.verbosity, "verbose", "v", "include skipped (and ignored, with -vv) controllers in output")
19 19
 }
20 20
 
21 21
 func newTabwriter() *tabwriter.Writer {

+ 1
- 1
cmd/fluxctl/policy_cmd.go View File

@@ -110,7 +110,7 @@ func (opts *controllerPolicyOpts) RunE(cmd *cobra.Command, args []string) error
110 110
 	if err != nil {
111 111
 		return err
112 112
 	}
113
-	return await(ctx, cmd.OutOrStdout(), cmd.OutOrStderr(), opts.API, jobID, false, opts.verbose)
113
+	return await(ctx, cmd.OutOrStdout(), cmd.OutOrStderr(), opts.API, jobID, false, opts.verbosity)
114 114
 }
115 115
 
116 116
 func calculatePolicyChanges(opts *controllerPolicyOpts) (policy.Update, error) {

+ 1
- 1
cmd/fluxctl/release_cmd.go View File

@@ -135,5 +135,5 @@ func (opts *controllerReleaseOpts) RunE(cmd *cobra.Command, args []string) error
135 135
 		return err
136 136
 	}
137 137
 
138
-	return await(ctx, cmd.OutOrStdout(), cmd.OutOrStderr(), opts.API, jobID, !opts.dryRun, opts.verbose)
138
+	return await(ctx, cmd.OutOrStdout(), cmd.OutOrStderr(), opts.API, jobID, !opts.dryRun, opts.verbosity)
139 139
 }

+ 11
- 2
update/print.go View File

@@ -8,14 +8,23 @@ import (
8 8
 	"github.com/weaveworks/flux"
9 9
 )
10 10
 
11
-func PrintResults(out io.Writer, results Result, verbose bool) {
11
+// PrintResults outputs a result set to the `io.Writer` provided, at
12
+// the given level of verbosity:
13
+//  - 2 = include skipped and ignored resources
14
+//  - 1 = include skipped resources, exclude ignored resources
15
+//  - 0 = exclude skipped and ignored resources
16
+func PrintResults(out io.Writer, results Result, verbosity int) {
12 17
 	w := tabwriter.NewWriter(out, 0, 2, 2, ' ', 0)
13 18
 	fmt.Fprintln(w, "CONTROLLER \tSTATUS \tUPDATES")
14 19
 	for _, serviceID := range results.ServiceIDs() {
15 20
 		result := results[flux.MustParseResourceID(serviceID)]
16 21
 		switch result.Status {
17 22
 		case ReleaseStatusIgnored:
18
-			if !verbose {
23
+			if verbosity < 2 {
24
+				continue
25
+			}
26
+		case ReleaseStatusSkipped:
27
+			if verbosity < 1 {
19 28
 				continue
20 29
 			}
21 30
 		}

+ 6
- 6
update/print_test.go View File

@@ -18,10 +18,10 @@ func mustParseRef(s string) image.Ref {
18 18
 
19 19
 func TestPrintResults(t *testing.T) {
20 20
 	for _, example := range []struct {
21
-		name     string
22
-		result   Result
23
-		verbose  bool
24
-		expected string
21
+		name      string
22
+		result    Result
23
+		verbosity int
24
+		expected  string
25 25
 	}{
26 26
 		{
27 27
 			name: "basic, just results",
@@ -85,13 +85,13 @@ default/d    success
85 85
 	} {
86 86
 		out := &bytes.Buffer{}
87 87
 		out.WriteString("\n") // All our "expected" values start with a newline, to make maintaining them easier.
88
-		PrintResults(out, example.result, example.verbose)
88
+		PrintResults(out, example.result, example.verbosity)
89 89
 		if out.String() != example.expected {
90 90
 			t.Errorf(
91 91
 				"Name: %s\nPrintResults(out, %#v, %v)\nExpected\n-------%s-------\nGot\n-------%s-------",
92 92
 				example.name,
93 93
 				example.result,
94
-				example.verbose,
94
+				example.verbosity,
95 95
 				example.expected,
96 96
 				out.String(),
97 97
 			)

Loading…
Cancel
Save