Skip to content

Commit 3a4d6d6

Browse files
author
scttymn
committed
Refactor pod commands for better CLI organization
- Add new `gcpeasy pod` command with subcommands: list, logs, shell - Add `--status` flag to `pod list` for detailed vs simple output - Create top-level shortcuts: `gcpeasy logs` and `gcpeasy shell` - Deprecate `gcpeasy rails logs` with backward compatibility - Remove old `pods` and standalone `shell` commands - Make CLI framework-agnostic for broader developer adoption
1 parent 27caf74 commit 3a4d6d6

File tree

5 files changed

+409
-298
lines changed

5 files changed

+409
-298
lines changed

cmd/logs.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var logsCmd = &cobra.Command{
10+
Use: "logs",
11+
Short: "View pod logs (shortcut for 'pod logs')",
12+
Long: "View logs from application pods. This is a shortcut for 'gcpeasy pod logs'.",
13+
Run: func(cmd *cobra.Command, args []string) {
14+
follow, _ := cmd.Flags().GetBool("follow")
15+
errorOnly, _ := cmd.Flags().GetBool("error")
16+
warnOnly, _ := cmd.Flags().GetBool("warn")
17+
infoOnly, _ := cmd.Flags().GetBool("info")
18+
debugOnly, _ := cmd.Flags().GetBool("debug")
19+
20+
var level string
21+
if errorOnly {
22+
level = "error"
23+
} else if warnOnly {
24+
level = "warn"
25+
} else if infoOnly {
26+
level = "info"
27+
} else if debugOnly {
28+
level = "debug"
29+
}
30+
31+
if err := runPodLogs(follow, level); err != nil {
32+
fmt.Printf("Error viewing logs: %v\n", err)
33+
}
34+
},
35+
}
36+
37+
func init() {
38+
logsCmd.Flags().BoolP("follow", "f", false, "Follow logs in real-time")
39+
logsCmd.Flags().BoolP("error", "e", false, "Show only error logs")
40+
logsCmd.Flags().BoolP("warn", "w", false, "Show only warning logs")
41+
logsCmd.Flags().BoolP("info", "i", false, "Show only info logs")
42+
logsCmd.Flags().BoolP("debug", "d", false, "Show only debug logs")
43+
rootCmd.AddCommand(logsCmd)
44+
}

0 commit comments

Comments
 (0)