Refactor help system to consolidate error messages and command-specific help

- Simplify main help to show brief command descriptions only
- Add --help support to all commands with detailed usage information
- Replace duplicated help text in error messages with error + help pattern
- Remove 'help' command in favor of consistent --help flag usage
- Add helper functions CheckForHelpFlag() and ShowErrorWithHelp() for standardization
- Refactor deploy command to reduce cognitive complexity and improve maintainability

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Felipe M 2025-07-28 19:20:36 +02:00
parent 59dd709d83
commit dee239a3d4
No known key found for this signature in database
GPG key ID: 52E5D65FCF99808A
11 changed files with 370 additions and 80 deletions

View file

@ -91,8 +91,32 @@ func applyManifest(manifest *model.Manifest, pluginPath string) error {
// RunManifestCommand implements the 'manifest' command functionality with subcommands.
func RunManifestCommand(args []string, pluginPath string) error {
helpText := `Manage plugin manifest files
Usage:
pluginctl manifest <subcommand> [options]
Subcommands:
get TEMPLATE Get manifest field using template syntax (e.g., {{.id}}, {{.version}})
apply Generate manifest files for server/webapp
check Validate plugin manifest
Options:
--help, -h Show this help message
Examples:
pluginctl manifest get '{{.id}}' # Get plugin ID
pluginctl manifest get '{{.version}}' # Get plugin version
pluginctl manifest apply # Generate server/webapp manifest files
pluginctl manifest check # Validate manifest`
// Check for help flag
if CheckForHelpFlag(args, helpText) {
return nil
}
if len(args) == 0 {
return fmt.Errorf("manifest command requires a subcommand: get {{.field_name}}, apply, check")
return ShowErrorWithHelp("manifest command requires a subcommand", helpText)
}
// Convert to absolute path
@ -111,7 +135,7 @@ func RunManifestCommand(args []string, pluginPath string) error {
switch subcommand {
case "get":
if len(args) < 2 {
return fmt.Errorf("get subcommand requires a template expression (e.g., {{.id}}, {{.version}})")
return ShowErrorWithHelp("get subcommand requires a template expression", helpText)
}
templateStr := args[1]
@ -139,8 +163,7 @@ func RunManifestCommand(args []string, pluginPath string) error {
}
Logger.Info("Plugin manifest is valid")
default:
return fmt.Errorf("unknown subcommand: %s. Available subcommands: get {{.field_name}}, apply, check",
subcommand)
return ShowErrorWithHelp(fmt.Sprintf("unknown subcommand: %s", subcommand), helpText)
}
return nil