Repository navigation
Expand file tree
/
Copy pathcmd_root.go
More file actions
93 lines (83 loc) · 2.86 KB
/
Copy pathcmd_root.go
File metadata and controls
93 lines (83 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import "github.com/spf13/cobra"
var (
// Global flags
searchTerm string
regexSearch string
levelFilter string
minLevelFilter string
userFilter string
startTime string
endTime string
jsonOutput bool
csvOutput string
outputFile string
analyze bool
apiKey string
llmProvider string
llmModel string
trim bool
trimJSON string
maxEntries int
problem string
thinkingBudget int
ollamaHost string
ollamaTimeout int
interactive bool
autoConfirm bool
verbose bool
quiet bool
verboseAnalysis bool
rawOutput bool
)
// rootCmd represents the base command when called without any subcommands.
var rootCmd = &cobra.Command{
Use: "lamp",
Short: "lamp is a tool for parsing and analyzing Mattermost log files",
Long: `lamp (Log Analyser for Mattermost Packet) allows you to parse, filter, and analyze Mattermost log files
and support packets. It provides various filtering options, analysis capabilities,
and AI-powered insights using LLM technology.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
enteredPreRun = true
initLogger()
},
}
// aiCmd is the parent for AI-powered log analysis subcommands.
var aiCmd = &cobra.Command{
Use: "ai-analyze",
Short: "Analyze Mattermost logs using AI",
Long: `Send parsed log entries to an LLM for analysis. Use subcommands to specify the log source.`,
}
func init() {
// Enable command completion
rootCmd.CompletionOptions.DisableDefaultCmd = false
// --verbose and --quiet apply to all subcommands
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Enable verbose output logging")
rootCmd.PersistentFlags().BoolVar(&quiet, "quiet", false, "Only output errors")
registerFlagCompletion(rootCmd, "verbose", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
})
registerFlagCompletion(rootCmd, "quiet", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"true", "false"}, cobra.ShellCompDirectiveNoFileComp
})
// Add subcommands to root
rootCmd.AddCommand(fileCmd)
rootCmd.AddCommand(notificationCmd)
rootCmd.AddCommand(supportPacketCmd)
rootCmd.AddCommand(aiCmd)
rootCmd.AddCommand(versionCmd)
// Add AI subcommands
aiCmd.AddCommand(aiFileCmd)
aiCmd.AddCommand(aiNotificationCmd)
aiCmd.AddCommand(aiSupportPacketCmd)
// Flags for standard log processing commands
for _, cmd := range []*cobra.Command{fileCmd, notificationCmd, supportPacketCmd} {
addFilterFlags(cmd)
addOutputFlags(cmd)
}
// Flags for AI analysis commands
for _, cmd := range []*cobra.Command{aiFileCmd, aiNotificationCmd, aiSupportPacketCmd} {
addFilterFlags(cmd)
addAIFlags(cmd)
}
}