Skip to content

Commit d90a423

Browse files
committed
Fix Cobra help template panic
1 parent beb5e11 commit d90a423

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

cmd/root.go

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,32 @@
11
package cmd
22

3-
import (
4-
"fmt"
5-
"os"
6-
"path/filepath"
7-
8-
"github.com/spf13/cobra"
9-
)
10-
11-
const Version = "0.9.3"
12-
13-
// CLIConfig holds CLI options passed via flags
14-
type CLIConfig struct {
15-
OutputFormat string
16-
OutputDir string
17-
Verbose bool
18-
EnableNetworkAndDNS bool
19-
}
3+
rootCmd.SetHelpTemplate(`FlutterGuard CLI - Analyze Flutter Android APKs for security insights
4+
5+
Usage:
6+
{{.UseLine}}
7+
8+
{{if .HasAvailableFlags}}Options:
9+
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}
10+
{{end}}
11+
{{if .HasAvailableSubCommands}}Commands:
12+
{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
13+
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}
14+
{{end}}
15+
Examples:
16+
# Analyze APK with structured output (recommended)
17+
{{.CommandPath}} --apk app.apk --outDir ./results --verbose
2018
21-
var (
22-
apkPath string
23-
cfg CLIConfig
24-
showVersion bool
25-
)
26-
27-
var rootCmd = &cobra.Command{
28-
Use: "flutterguard",
29-
Short: "FlutterGuard CLI - Analyze Flutter Android APKs for security insights",
30-
Long: "FlutterGuard CLI is a tool to analyze Flutter Android APKs for security issues, misconfigurations, and sensitive data exposure.",
31-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
32-
33-
if len(os.Args) == 1 {
34-
_ = cmd.Help()
35-
os.Exit(0)
19+
# Quick text report
20+
{{.CommandPath}} --apk app.apk --format text
21+
22+
# Offline analysis (default)
23+
{{.CommandPath}} --apk app.apk --outDir ./results
24+
25+
# Enable network checks for full validation
26+
{{.CommandPath}} --apk app.apk --outDir ./results --enable-network-and-dns-checks
27+
28+
More info: https://github.com/flutterguard/flutterguard-cli
29+
`)
3630
}
3731
return nil
3832
},

0 commit comments

Comments
 (0)