Skip to content

Refactor: commands show help when no flag is set#7

Merged
xenOs76 merged 4 commits intomainfrom
refactor/cmd_help
Nov 17, 2025
Merged

Refactor: commands show help when no flag is set#7
xenOs76 merged 4 commits intomainfrom
refactor/cmd_help

Conversation

@xenOs76
Copy link
Copy Markdown
Owner

@xenOs76 xenOs76 commented Nov 17, 2025

Summary by CodeRabbit

  • Documentation

    • Updated README with clearer command syntax, examples, flag/help formatting, and installation instructions.
  • Improvements

    • Expanded and clarified help text for root, requests, and certinfo commands.
    • Added a --version flag and improved behavior when no flags are provided (shows help).
    • Added pre-flight validation to verify config file existence before loading.
  • Tests

    • Added automated checks to verify version/help outputs across commands.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 17, 2025

Walkthrough

Adds runtime version flag handling and pre-flight config-file existence checks to CLI commands (root, requests, certinfo); refactors flag value retrieval to local variables; updates command help/README text; integrates govulncheck into the development environment and adds automated version/help smoke tests; minor formatting change in an internal handler.

Changes

Cohort / File(s) Summary
CLI command changes
cmd/certinfo.go, cmd/requests.go, cmd/root.go
Added --version handling with early exit; added/changed pre-flight config-file existence checks and help behavior; refactored flag retrieval to local variables (ca-bundle, cert-bundle, key-file); updated command short/long/help text; adjusted Execute error return behavior.
Documentation
README.md
Updated examples and command usage to explicitly include the requests subcommand, adjusted flag/help wording, and tweaked installation instruction formatting.
Dev environment & tests
devenv.nix
Added govulncheck to dev packages and update-go-deps flow; added six test command scripts to verify version and help outputs and registered them in the test sequence.
Internal formatting
internal/certinfo/certinfo_handlers.go
Reflowed header construction in CertsToTables across multiple lines; no functional changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as CLI Command
    participant Viper as Config/Flags

    Note over CLI,Viper: Common pre-flight checks (new)

    User->>CLI: run command --version
    CLI->>Viper: viper.GetBool("version")
    Viper-->>CLI: true
    CLI-->>User: print version and exit

    User->>CLI: run command without required config
    CLI->>Viper: viper.ConfigFileUsed()
    Viper-->>CLI: (empty or path)
    alt no config file
        CLI-->>User: show help and exit
    else config file present
        CLI->>CLI: LoadConfig() and continue execution
        CLI-->>User: command output
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Inspect consistent implementation of version flag across commands (cmd/certinfo.go, cmd/requests.go, cmd/root.go).
  • Verify config-file existence checks (timing and error messages) in requests and certinfo flows.
  • Confirm local variable usage maps correctly to viper keys and is used in subsequent calls.
  • Review new test scripts in devenv.nix to ensure they assert the expected output strings and integrate cleanly with the test sequence.

Possibly related PRs

Poem

🐰 I hopped through flags and files today,

version printed bright, configs kept at bay.
Govulncheck joined the dev-time crew,
tests now hop to prove what's true.
A tiny rabbit cheers: "Nice work — hooray!"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main functional change across multiple commands: they now display help when no required flags are provided, which is the primary objective of this refactor.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/cmd_help

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a2227c and 84b5d00.

📒 Files selected for processing (1)
  • cmd/requests.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/requests.go (1)
cmd/root.go (1)
  • LoadConfig (116-125)
🔇 Additional comments (5)
cmd/requests.go (5)

10-14: LGTM!

The added imports for os and viper are necessary for the new config file existence checks and version flag handling.


26-28: LGTM!

The updated command descriptions clearly communicate that requests are defined in a YAML configuration file.


43-46: LGTM!

The early check for an empty cfgFile with help output provides clear guidance when no configuration file is specified.


55-59: LGTM!

The refactor to store LoadConfig() result in a local variable and the repositioning of this call after the config file checks improves code organization and flow.


31-36: The original review comment is invalid.

The version variable is properly defined at the package level in cmd/root.go (line 42) as version = "development". Since cmd/requests.go is in the same cmd package, it has direct access to this variable. The code at lines 31-36 is correct and requires no changes.

Likely an incorrect or invalid review comment.


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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
cmd/root.go (1)

88-89: Consider removing commented code or documenting the intent.

The commented-out flag registrations suggest these flags are no longer needed for the requests command. If this is intentional and permanent, consider removing the commented lines. If there's a plan to re-enable them, consider adding a TODO comment explaining why they're temporarily disabled.

Apply this diff to remove the commented code:

 	addCaBundleFlag(requestsCmd)
-	// addCertBundleFlag(requestsCmd)
-	// addKeyFileFlag(requestsCmd)
cmd/certinfo.go (2)

52-55: Version handling works correctly but consider extracting to a shared function.

The version handling logic is duplicated across rootCmd (root.go:55-60), requestsCmd (requests.go:31-36), and certinfoCmd (certinfo.go:52-55). Consider extracting this to a shared helper function to follow the DRY principle.

Example refactor:

// In cmd/root.go or a new cmd/helpers.go
func handleVersionFlag(cmd *cobra.Command) bool {
	if viper.GetBool("version") {
		fmt.Print(version)
		return true
	}
	return false
}

// In each command's Run function:
if handleVersionFlag(cmd) {
	return
}

57-61: Consider a more explicit flag check for clarity.

The string concatenation length check is clever but may be confusing for maintainability. Consider using a more explicit approach:

-		// display the help if none of the main flags is set
-		if len(caBundleValue+certBundleValue+keyFileValue+tlsEndpoint) == 0 {
-			_ = cmd.Help()
-			return
-		}
+		// display the help if none of the main flags is set
+		if caBundleValue == "" && certBundleValue == "" && keyFileValue == "" && tlsEndpoint == "" {
+			_ = cmd.Help()
+			return
+		}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3b4eb1 and 5a2227c.

⛔ Files ignored due to path filters (1)
  • devenv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • README.md (4 hunks)
  • cmd/certinfo.go (3 hunks)
  • cmd/requests.go (2 hunks)
  • cmd/root.go (3 hunks)
  • devenv.nix (4 hunks)
  • internal/certinfo/certinfo_handlers.go (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-15T17:16:55.051Z
Learnt from: xenOs76
Repo: xenOs76/https-wrench PR: 5
File: devenv.nix:569-569
Timestamp: 2025-11-15T17:16:55.051Z
Learning: In the xenOs76/https-wrench repository, the devenv.nix test environment is local-only without GitHub CI integration, so automatic dependency updates in enterTest are acceptable for the maintainer's workflow.

Applied to files:

  • devenv.nix
📚 Learning: 2025-11-08T16:00:48.187Z
Learnt from: xenOs76
Repo: xenOs76/https-wrench PR: 3
File: internal/requests/requests.go:164-182
Timestamp: 2025-11-08T16:00:48.187Z
Learning: In the https-wrench tool (xenOs76/https-wrench repository), do not enforce minimum TLS version constraints in the HTTP client configuration. The tool is designed to inspect and test TLS settings on various servers, including legacy ones, and needs the flexibility to connect to servers with older TLS versions.

Applied to files:

  • README.md
🧬 Code graph analysis (1)
internal/certinfo/certinfo_handlers.go (2)
internal/style/style_handlers.go (1)
  • LgSprintf (21-26)
internal/style/style.go (1)
  • CertKeyP4 (61-63)
🔇 Additional comments (14)
internal/certinfo/certinfo_handlers.go (1)

171-174: LGTM! Formatting improvement.

The multi-line formatting improves readability without changing functionality.

README.md (1)

27-42: LGTM! Documentation correctly updated.

The documentation changes accurately reflect the new command structure and usage patterns introduced in this PR.

Also applies to: 49-49, 105-105, 143-143, 159-159

cmd/requests.go (2)

31-36: LGTM! Clean version handling.

The version flag implementation follows a clear early-return pattern.


10-10: LGTM! Imports and descriptions updated appropriately.

The new imports support the version and config validation features, and the updated descriptions are clearer.

Also applies to: 14-14, 26-28

cmd/root.go (3)

50-52: LGTM! Clearer command descriptions.

The updated descriptions better communicate the tool's purpose.


62-64: LGTM! Simplified help display logic.

Showing help when no config file is provided aligns with the PR objective and improves user experience.


68-73: LGTM! Better error handling pattern.

Returning the error instead of calling os.Exit(1) is better practice as it allows the caller to handle errors appropriately.

cmd/certinfo.go (3)

24-45: LGTM! Excellent documentation improvement.

The extended help text with examples significantly improves the user experience by providing clear usage patterns.


47-50: LGTM! Improved flag value handling.

Using local variables instead of repeated viper.GetString() calls improves code readability and reduces coupling.


71-71: LGTM! Consistent use of local variables.

The refactored code consistently uses the local variables defined earlier, improving readability.

Also applies to: 75-75, 83-83

devenv.nix (4)

27-27: LGTM! Good addition for security.

Adding govulncheck helps identify known vulnerabilities in dependencies.


152-159: LGTM! Integrated vulnerability checking into dependency workflow.

Running govulncheck after updating dependencies ensures vulnerabilities are caught early in the development process.


210-238: LGTM! Comprehensive test coverage for new functionality.

The new test commands effectively verify version and help output for all commands. The consistent pattern and use of grep for validation is appropriate.


601-619: LGTM! Test sequence updated appropriately.

The test sequence now includes the new version and help verification tests, ensuring the refactored command behavior is validated.

Based on learnings

@xenOs76 xenOs76 merged commit 1505c54 into main Nov 17, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Nov 21, 2025
@xenOs76 xenOs76 self-assigned this Dec 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant