Skip to content

refactor: use some colors in CLI output#962

Open
steveiliop56 wants to merge 5 commits into
mainfrom
refactor/cli
Open

refactor: use some colors in CLI output#962
steveiliop56 wants to merge 5 commits into
mainfrom
refactor/cli

Conversation

@steveiliop56

@steveiliop56 steveiliop56 commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added a dedicated help subcommand and improved version styling.
    • Enhanced CLI output with styled, YAML-focused configuration snippets (including OIDC client generation).
  • Bug Fixes
    • Strengthened validation for user inputs (e.g., username rules and required fields).
    • Improved TOTP and verify feedback, including clearer warnings and human-friendly instructions.
    • Fixed Docker rendering of credentials while keeping YAML config consistent.
  • Chores
    • Updated config YAML serialization tags for more consistent optional fields.

@dosubot dosubot Bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 229b530a-b602-4fbe-bbce-d574c350a000

📥 Commits

Reviewing files that changed from the base of the PR and between 97daac3 and 5fabc8b.

📒 Files selected for processing (1)
  • cmd/tinyauth/tinyauth.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • cmd/tinyauth/tinyauth.go

📝 Walkthrough

Walkthrough

This PR changes tinyauth CLI commands to emit styled YAML-oriented output, adds shared CLI presentation helpers and error handling, updates config struct YAML tags to omitempty, and ignores JetBrains project files.

Changes

CLI Command Output and Error Handling Refactor

Layer / File(s) Summary
Shared styling and CLI wiring
cmd/tinyauth/tinyauth.go
Adds lipgloss styles, fatalf, and renderToBuf; adds a help subcommand; updates subcommand descriptions and error handling for command lookup and execution failures.
config command YAML output
cmd/tinyauth/config.go
Replaces JSON output with styled YAML rendering.
create-oidc-client styled output
cmd/tinyauth/create_oidc_client.go
Rebuilds output via strings.Builder/renderToBuf, adds a YAML config snippet, changes CLI flag naming format, and updates footer text.
create-user command rework
cmd/tinyauth/create_user.go
Restructures command wiring, adds username validation, removes logger usage, changes Docker $-escaping, and generates styled env var, flag, and YAML output.
generate-totp command rework
cmd/tinyauth/generate_totp.go
Restructures command wiring, adds required-user validation, removes logger messages, and prints styled QR, secret, and config instructions.
verify-user command rework
cmd/tinyauth/verify_user.go
Restructures command wiring, adds required-field checks, and replaces logger warnings and success messages with styled output for TOTP and password verification.
version command styling
cmd/tinyauth/version.go
Wraps version, commit hash, and build timestamp in blueStyle.Render.

Config Struct YAML Tag Updates

Layer / File(s) Summary
omitempty YAML tags across Config structs
internal/model/config.go
Adds omitempty to YAML tags across exported configuration structs, including database, server, auth, OAuth/OIDC, UI, LDAP, logging, Tailscale, and app ACL types.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • tinyauthapp/tinyauth#533: Overlaps with the CLI command construction, help handling, and output formatting changes in cmd/tinyauth.
  • tinyauthapp/tinyauth#672: Touches the same OIDC client creation flow updated in cmd/tinyauth/create_oidc_client.go.

Suggested reviewers: Rycochet

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: refactoring CLI output to use colors and styling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/cli

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Comment thread cmd/tinyauth/config.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (3)
cmd/tinyauth/tinyauth.go (3)

166-169: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Fatal errors are written to stdout, not stderr.

fatalf uses fmt.Printf, sending error output to stdout. Conventionally, fatal/error messages should go to stderr so they aren't mixed with normal output when stdout is redirected/piped.

🛠️ Suggested fix
 func fatalf(err error, msg string) {
-	fmt.Printf("%s: %v\n", msg, err)
+	fmt.Fprintf(os.Stderr, "%s: %v\n", msg, err)
 	os.Exit(1)
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/tinyauth/tinyauth.go` around lines 166 - 169, fatalf is printing fatal
error messages to stdout via fmt.Printf, which should be changed to stderr.
Update fatalf in tinyauth.go to write the error message using stderr output
instead of stdout, keeping the same message format and os.Exit(1) behavior so
normal program output is not mixed with error output.

133-135: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Silent no-op on "is not runnable".

When a command is not runnable (e.g. a group command invoked without a subcommand), the program silently returns with no output at all. Consider printing help or a short hint so the user isn't left staring at a blank prompt.

💡 Suggested fix
 		if strings.Contains(err.Error(), "is not runnable") {
+			_ = cmdTinyauth.PrintHelp(os.Stdout)
 			return
 		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/tinyauth/tinyauth.go` around lines 133 - 135, The error handling in
tinyauth.go currently returns silently when err.Error() contains "is not
runnable", which leaves users with no feedback. Update the command execution
path around the existing err check to emit a short hint or the command help
instead of returning immediately, using the same command object or help-related
logic in the surrounding handler so group commands without subcommands still
produce output.

60-124: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Repeated AddCommand + error-check boilerplate.

The err := ...; if err != nil { fatalf(...) } pattern is repeated 10 times. A small helper would reduce duplication and the risk of a copy-paste mistake (e.g. wrong error message for the wrong command).

♻️ Suggested helper
func mustAddCommand(parent, child *cli.Command, failMsg string) {
	if err := parent.AddCommand(child); err != nil {
		fatalf(err, failMsg)
	}
}

Then each call site becomes e.g. mustAddCommand(cmdTinyauth, helpCmd, "Failed to add help command").

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/tinyauth/tinyauth.go` around lines 60 - 124, The command registration in
tinyauth setup repeats the same AddCommand error-handling pattern many times.
Introduce a small helper around AddCommand, using the existing
cmdTinyauth/cmdUser/cmdTotp/cmdOidc registration flow, so each command is added
through one shared function that calls fatalf on error with the provided
message. This will remove the duplicated err checks and reduce the chance of
copy-paste mistakes in the command setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/tinyauth/config.go`:
- Line 15: The help text for the config dump command is stale: the Description
in config.go still says JSON even though the command now emits YAML via
yaml.Marshal and the user-facing message in the config command says YAML. Update
the command metadata in the config command setup so the Description matches the
actual output format, and keep it consistent with the config dumping logic in
the config command implementation.
- Around line 29-41: The YAML line coloring logic in the config rendering path
incorrectly splits every line on the first colon, which breaks scalar list items
like "- value" entries that contain colons in their content. Update the
rendering logic around the loop in config.go to skip colon-splitting for list
items and only treat actual mapping lines as key/value pairs, and apply the same
fix to the duplicated implementation in create_oidc_client.go. If possible,
extract the shared formatting into a helper such as renderYAMLToBuf so both call
sites use the same corrected behavior.

In `@cmd/tinyauth/create_user.go`:
- Around line 89-98: The credential formatting in create_user.go is escaping `$`
twice and in the wrong places, so the Docker-specific output and the non-Docker
output diverge incorrectly. In the create_user flow, keep the raw `user` value
(built from tCfg.Username and passwdStr) for the YAML/example section, and apply
the `strings.ReplaceAll(..., "$", "$$")` transformation only once to the env
var/CLI value that becomes `escapedUser`. Make sure the `tCfg.Docker` branch
affects only the docker-compose-safe string and does not alter the raw hash used
elsewhere.

In `@cmd/tinyauth/tinyauth.go`:
- Around line 171-178: The output order in renderToBuf is non-deterministic
because it ranges over a map, so update renderToBuf to accept an ordered slice
of key/value pairs instead of kv map[string]string and iterate in that provided
order. Then adjust the callers in create_user.go and create_oidc_client.go to
build and pass an ordered list so the rendered CLI output is stable across runs.

---

Nitpick comments:
In `@cmd/tinyauth/tinyauth.go`:
- Around line 166-169: fatalf is printing fatal error messages to stdout via
fmt.Printf, which should be changed to stderr. Update fatalf in tinyauth.go to
write the error message using stderr output instead of stdout, keeping the same
message format and os.Exit(1) behavior so normal program output is not mixed
with error output.
- Around line 133-135: The error handling in tinyauth.go currently returns
silently when err.Error() contains "is not runnable", which leaves users with no
feedback. Update the command execution path around the existing err check to
emit a short hint or the command help instead of returning immediately, using
the same command object or help-related logic in the surrounding handler so
group commands without subcommands still produce output.
- Around line 60-124: The command registration in tinyauth setup repeats the
same AddCommand error-handling pattern many times. Introduce a small helper
around AddCommand, using the existing cmdTinyauth/cmdUser/cmdTotp/cmdOidc
registration flow, so each command is added through one shared function that
calls fatalf on error with the provided message. This will remove the duplicated
err checks and reduce the chance of copy-paste mistakes in the command setup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1f2c4b94-9b3b-4ec6-a0c6-4c868b5232ef

📥 Commits

Reviewing files that changed from the base of the PR and between 04b93fa and 92172af.

📒 Files selected for processing (8)
  • cmd/tinyauth/config.go
  • cmd/tinyauth/create_oidc_client.go
  • cmd/tinyauth/create_user.go
  • cmd/tinyauth/generate_totp.go
  • cmd/tinyauth/tinyauth.go
  • cmd/tinyauth/verify_user.go
  • cmd/tinyauth/version.go
  • internal/model/config.go

Comment thread cmd/tinyauth/config.go Outdated
Comment thread cmd/tinyauth/config.go
Comment thread cmd/tinyauth/create_user.go
Comment thread cmd/tinyauth/tinyauth.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants