• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

numtide / treefmt
50%
main: 39%

Build:
Build:
LAST BUILD BRANCH: dependabot/github_actions/actions/checkout-5
DEFAULT BRANCH: main
Repo Added 14 Nov 2024 08:50AM UTC
Files 23
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

LAST BUILD ON BRANCH feat/verbosity-changes
branch: feat/verbosity-changes
CHANGE BRANCH
x
Reset
  • feat/verbosity-changes
  • better-error
  • check-for-errors
  • dependabot/github_actions/actions/checkout-5
  • dependabot/github_actions/actions/setup-go-6
  • dependabot/github_actions/cachix/install-nix-action-31
  • document-missing-formatter
  • feat/batch-size
  • feat/config-wrappers
  • feat/git-merge-tool
  • feat/git-untracked-files
  • feat/go-1.24
  • feat/refine-docs
  • feat/refine-error-handling
  • feat/refine-untracked-files
  • feat/refine-vendor-hash-update
  • feat/simpler-nix-build
  • feat/tree-root-cmd
  • feat/update-vendor-hash-automatically
  • feat/validate-formatter-name
  • fix/completions
  • fix/concurrent-invocation
  • fix/default-tree-root-cmd
  • fix/exit-on-formatter-errors
  • fix/logging
  • fix/non-ascii-paths
  • fix/update-vendor-hash-workflow
  • fixup/non-ascii-paths
  • main
  • mergify/configuration-deprecated-update
  • more-linter
  • new-README
  • renovate/actions-checkout-5.x
  • renovate/actions-setup-go-6.x
  • renovate/github.com-otiai10-copy-1.x
  • renovate/github.com-spf13-cobra-1.x
  • renovate/github.com-spf13-pflag-1.x
  • renovate/github.com-stretchr-testify-1.x
  • renovate/go-1.x
  • renovate/golang.org-x-sync-0.x
  • renovate/golang.org-x-sys-0.x
  • renovate/ubuntu-24.x
  • tagline
  • termenv-fix
  • v2.1.1
  • v2.2.0
  • v2.2.1
  • v2.3.0
  • v2.3.1

08 Jan 2025 02:25PM UTC coverage: 50.219% (+0.4%) from 49.811%
12672546106

Pull #504

github

brianmcgee
feat: add a quiet flag to suppress all output except for errors

Signed-off-by: Brian McGee <brian@bmcgee.ie>

diff --git a/cmd/root.go b/cmd/root.go
index 72348f1..cd3f8f7 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -144,13 +144,19 @@ func runE(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, args []string)
 	log.SetOutput(os.Stderr)
 	log.SetReportTimestamp(false)

-	switch v.GetInt("verbose") {
-	case 0:
-		log.SetLevel(log.WarnLevel)
-	case 1:
-		log.SetLevel(log.InfoLevel)
-	default:
-		log.SetLevel(log.DebugLevel)
+	if v.GetBool("quiet") {
+		// if quiet, we only log errors
+		log.SetLevel(log.ErrorLevel)
+	} else {
+		// otherwise, the verbose flag controls the log level
+		switch v.GetInt("verbose") {
+		case 0:
+			log.SetLevel(log.WarnLevel)
+		case 1:
+			log.SetLevel(log.InfoLevel)
+		default:
+			log.SetLevel(log.DebugLevel)
+		}
 	}

 	// format
diff --git a/cmd/root_test.go b/cmd/root_test.go
index 2846504..628a69b 100644
--- a/cmd/root_test.go
+++ b/cmd/root_test.go
@@ -131,6 +131,33 @@ func TestOnUnmatched(t *testing.T) {
 	})
 }

+func TestQuiet(t *testing.T) {
+	as := require.New(t)
+	tempDir := test.TempExamples(t)
+
+	test.ChangeWorkDir(t, tempDir)
+
+	// allow missing formatter
+	t.Setenv("TREEFMT_ALLOW_MISSING_FORMATTER", "true")
+
+	noOutput := func(out []byte) {
+		as.Empty(out)
+	}
+
+	treefmt(t, withArgs("-q"), withNoError(t), withStdout(noOutput), withStderr(noOutput))
+	treefmt(t, withArgs("--quiet"), withNoError(t), withStdout(noOutput), withStderr(noOutput))
+
+	t.Setenv("TREEFMT_QUIET", "true")
+	treefmt(t, withNoError(t), withStdout(noOutput), withStderr(noOutput))
+
+	t.Setenv("TREEFMT_ALLOW_MISSING_FORMATTER", "false")
+
+	// check it doesn't suppress errors
+	treefmt(t, withError(func(err error) {
+		as.ErrorContains(err, "error looking up 'foo-fmt'")
+	}))
+}
+
 func TestCpuProfile(t *testing.T) {
 	as := require.New(t)
 	tempDir := test.TempExamples(t)
diff --git a/config/config.go b/config/config.go
inde... (continued)
Pull Request #504: Verbosity changes

22 of 22 new or added lines in 4 files covered. (100.0%)

802 of 1597 relevant lines covered (50.22%)

33.09 hits per line

Relevant lines Covered
Build:
Build:
1597 RELEVANT LINES 802 COVERED LINES
33.09 HITS PER LINE
Source Files on feat/verbosity-changes
  • Tree
  • List 19
  • Changed 6
  • Source Changed 4
  • Coverage Changed 3
Coverage ∆ File Lines Relevant Covered Missed Hits/Line

Recent builds

Builds Branch Commit Type Ran Committer Via Coverage
12672546106 feat/verbosity-changes feat: add a quiet flag to suppress all output except for errors Signed-off-by: Brian McGee <brian@bmcgee.ie> diff --git a/cmd/root.go b/cmd/root.go index 72348f1..cd3f8f7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -144,13 +144,19 @@ func runE... Pull #504 08 Jan 2025 02:27PM UTC brianmcgee github
50.22
12656539520 feat/verbosity-changes feat: add a quiet flag to suppress all output except for errors Signed-off-by: Brian McGee <brian@bmcgee.ie> Pull #504 07 Jan 2025 05:50PM UTC brianmcgee github
50.06
12603396845 feat/verbosity-changes feat: change default log level for unmatched to info instead of warn Signed-off-by: Brian McGee <brian@bmcgee.ie> Pull #504 03 Jan 2025 08:19PM UTC brianmcgee github
49.94
See All Builds (204)
  • Repo on GitHub
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc