From 7dabc492856e8ce6965a4cc22f3764e525a5a332 Mon Sep 17 00:00:00 2001 From: rsteube Date: Fri, 6 Dec 2024 10:27:10 +0100 Subject: [PATCH] added saw --- completers/saw_completer/cmd/completion.go | 18 +++++++++++ .../saw_completer/cmd/completion_bash.go | 19 ++++++++++++ .../saw_completer/cmd/completion_fish.go | 19 ++++++++++++ .../cmd/completion_powershell.go | 19 ++++++++++++ .../saw_completer/cmd/completion_zsh.go | 19 ++++++++++++ completers/saw_completer/cmd/get.go | 31 +++++++++++++++++++ completers/saw_completer/cmd/groups.go | 19 ++++++++++++ completers/saw_completer/cmd/help.go | 18 +++++++++++ completers/saw_completer/cmd/root.go | 31 +++++++++++++++++++ completers/saw_completer/cmd/streams.go | 26 ++++++++++++++++ completers/saw_completer/cmd/version.go | 18 +++++++++++ completers/saw_completer/cmd/watch.go | 29 +++++++++++++++++ completers/saw_completer/main.go | 7 +++++ pkg/actions/tools/saw/group.go | 20 ++++++++++++ pkg/actions/tools/saw/stream.go | 20 ++++++++++++ 15 files changed, 313 insertions(+) create mode 100644 completers/saw_completer/cmd/completion.go create mode 100644 completers/saw_completer/cmd/completion_bash.go create mode 100644 completers/saw_completer/cmd/completion_fish.go create mode 100644 completers/saw_completer/cmd/completion_powershell.go create mode 100644 completers/saw_completer/cmd/completion_zsh.go create mode 100644 completers/saw_completer/cmd/get.go create mode 100644 completers/saw_completer/cmd/groups.go create mode 100644 completers/saw_completer/cmd/help.go create mode 100644 completers/saw_completer/cmd/root.go create mode 100644 completers/saw_completer/cmd/streams.go create mode 100644 completers/saw_completer/cmd/version.go create mode 100644 completers/saw_completer/cmd/watch.go create mode 100644 completers/saw_completer/main.go create mode 100644 pkg/actions/tools/saw/group.go create mode 100644 pkg/actions/tools/saw/stream.go diff --git a/completers/saw_completer/cmd/completion.go b/completers/saw_completer/cmd/completion.go new file mode 100644 index 0000000000..54db79269d --- /dev/null +++ b/completers/saw_completer/cmd/completion.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var completionCmd = &cobra.Command{ + Use: "completion", + Short: "Generate the autocompletion script for the specified shell", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(completionCmd).Standalone() + + rootCmd.AddCommand(completionCmd) +} diff --git a/completers/saw_completer/cmd/completion_bash.go b/completers/saw_completer/cmd/completion_bash.go new file mode 100644 index 0000000000..df23c85cc8 --- /dev/null +++ b/completers/saw_completer/cmd/completion_bash.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var completion_bashCmd = &cobra.Command{ + Use: "bash", + Short: "Generate the autocompletion script for bash", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(completion_bashCmd).Standalone() + + completion_bashCmd.Flags().Bool("no-descriptions", false, "disable completion descriptions") + completionCmd.AddCommand(completion_bashCmd) +} diff --git a/completers/saw_completer/cmd/completion_fish.go b/completers/saw_completer/cmd/completion_fish.go new file mode 100644 index 0000000000..a4eb4e3602 --- /dev/null +++ b/completers/saw_completer/cmd/completion_fish.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var completion_fishCmd = &cobra.Command{ + Use: "fish", + Short: "Generate the autocompletion script for fish", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(completion_fishCmd).Standalone() + + completion_fishCmd.Flags().Bool("no-descriptions", false, "disable completion descriptions") + completionCmd.AddCommand(completion_fishCmd) +} diff --git a/completers/saw_completer/cmd/completion_powershell.go b/completers/saw_completer/cmd/completion_powershell.go new file mode 100644 index 0000000000..5bb7b0a664 --- /dev/null +++ b/completers/saw_completer/cmd/completion_powershell.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var completion_powershellCmd = &cobra.Command{ + Use: "powershell", + Short: "Generate the autocompletion script for powershell", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(completion_powershellCmd).Standalone() + + completion_powershellCmd.Flags().Bool("no-descriptions", false, "disable completion descriptions") + completionCmd.AddCommand(completion_powershellCmd) +} diff --git a/completers/saw_completer/cmd/completion_zsh.go b/completers/saw_completer/cmd/completion_zsh.go new file mode 100644 index 0000000000..f5d6028d07 --- /dev/null +++ b/completers/saw_completer/cmd/completion_zsh.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var completion_zshCmd = &cobra.Command{ + Use: "zsh", + Short: "Generate the autocompletion script for zsh", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(completion_zshCmd).Standalone() + + completion_zshCmd.Flags().Bool("no-descriptions", false, "disable completion descriptions") + completionCmd.AddCommand(completion_zshCmd) +} diff --git a/completers/saw_completer/cmd/get.go b/completers/saw_completer/cmd/get.go new file mode 100644 index 0000000000..880725b3b4 --- /dev/null +++ b/completers/saw_completer/cmd/get.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/saw" + "github.com/spf13/cobra" +) + +var getCmd = &cobra.Command{ + Use: "get ", + Short: "Get log events", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(getCmd).Standalone() + + getCmd.Flags().Bool("expand", false, "indent JSON log messages") + getCmd.Flags().String("filter", "", "event filter pattern") + getCmd.Flags().Bool("invert", false, "invert colors for light terminal themes") + getCmd.Flags().String("prefix", "", "log group prefix filter") + getCmd.Flags().Bool("pretty", false, "print timestamp and stream name prefix") + getCmd.Flags().Bool("rawString", false, "print JSON strings without escaping") + getCmd.Flags().String("start", "", "start getting the logs from this point") + getCmd.Flags().String("stop", "", "stop getting the logs at this point") + rootCmd.AddCommand(getCmd) + + carapace.Gen(getCmd).PositionalCompletion( + saw.ActionGroups(), + ) +} diff --git a/completers/saw_completer/cmd/groups.go b/completers/saw_completer/cmd/groups.go new file mode 100644 index 0000000000..10fa50c6b4 --- /dev/null +++ b/completers/saw_completer/cmd/groups.go @@ -0,0 +1,19 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var groupsCmd = &cobra.Command{ + Use: "groups", + Short: "List log groups", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(groupsCmd).Standalone() + + groupsCmd.Flags().String("prefix", "", "log group prefix filter") + rootCmd.AddCommand(groupsCmd) +} diff --git a/completers/saw_completer/cmd/help.go b/completers/saw_completer/cmd/help.go new file mode 100644 index 0000000000..12ec8f35c6 --- /dev/null +++ b/completers/saw_completer/cmd/help.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var helpCmd = &cobra.Command{ + Use: "help [command]", + Short: "Help about any command", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(helpCmd).Standalone() + + rootCmd.AddCommand(helpCmd) +} diff --git a/completers/saw_completer/cmd/root.go b/completers/saw_completer/cmd/root.go new file mode 100644 index 0000000000..8bd1514c6b --- /dev/null +++ b/completers/saw_completer/cmd/root.go @@ -0,0 +1,31 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/aws" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "saw ", + Short: "A fast, multipurpose tool for AWS CloudWatch Logs", + Long: "https://github.com/TylerBrock/saw", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + carapace.Gen(rootCmd).Standalone() + + rootCmd.PersistentFlags().String("endpoint-url", "", "override default endpoint URL") + rootCmd.PersistentFlags().String("profile", "", "override default AWS profile") + rootCmd.PersistentFlags().String("region", "", "override profile AWS region") + + carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ + "profile": aws.ActionProfiles(), + "region": aws.ActionRegions(), + }) +} diff --git a/completers/saw_completer/cmd/streams.go b/completers/saw_completer/cmd/streams.go new file mode 100644 index 0000000000..678e1551d1 --- /dev/null +++ b/completers/saw_completer/cmd/streams.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/saw" + "github.com/spf13/cobra" +) + +var streamsCmd = &cobra.Command{ + Use: "streams ", + Short: "List streams in log group", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(streamsCmd).Standalone() + + streamsCmd.Flags().Bool("descending", false, "order streams descending") + streamsCmd.Flags().String("orderBy", "", "order streams by LogStreamName or LastEventTime") + streamsCmd.Flags().String("prefix", "", "stream prefix filter") + rootCmd.AddCommand(streamsCmd) + + carapace.Gen(streamsCmd).PositionalCompletion( + saw.ActionGroups(), + ) +} diff --git a/completers/saw_completer/cmd/version.go b/completers/saw_completer/cmd/version.go new file mode 100644 index 0000000000..b4501a157e --- /dev/null +++ b/completers/saw_completer/cmd/version.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Prints the version string", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(versionCmd).Standalone() + + rootCmd.AddCommand(versionCmd) +} diff --git a/completers/saw_completer/cmd/watch.go b/completers/saw_completer/cmd/watch.go new file mode 100644 index 0000000000..b71d8a3c3d --- /dev/null +++ b/completers/saw_completer/cmd/watch.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/carapace-sh/carapace" + "github.com/carapace-sh/carapace-bin/pkg/actions/tools/saw" + "github.com/spf13/cobra" +) + +var watchCmd = &cobra.Command{ + Use: "watch ", + Short: "Continuously stream log events", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(watchCmd).Standalone() + + watchCmd.Flags().Bool("expand", false, "indent JSON log messages") + watchCmd.Flags().String("filter", "", "event filter pattern") + watchCmd.Flags().Bool("invert", false, "invert colors for light terminal themes") + watchCmd.Flags().String("prefix", "", "log stream prefix filter") + watchCmd.Flags().Bool("raw", false, "print raw log event without timestamp or stream prefix") + watchCmd.Flags().Bool("rawString", false, "print JSON strings without escaping") + rootCmd.AddCommand(watchCmd) + + carapace.Gen(watchCmd).PositionalCompletion( + saw.ActionGroups(), + ) +} diff --git a/completers/saw_completer/main.go b/completers/saw_completer/main.go new file mode 100644 index 0000000000..932f4fd79f --- /dev/null +++ b/completers/saw_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/carapace-sh/carapace-bin/completers/saw_completer/cmd" + +func main() { + cmd.Execute() +} diff --git a/pkg/actions/tools/saw/group.go b/pkg/actions/tools/saw/group.go new file mode 100644 index 0000000000..e4b1340f14 --- /dev/null +++ b/pkg/actions/tools/saw/group.go @@ -0,0 +1,20 @@ +package saw + +import ( + "strings" + + "github.com/carapace-sh/carapace" +) + +// ActionGroups completes log groups. +// +// lambda/one +// ecs/two +func ActionGroups() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return carapace.ActionExecCommand("saw", "groups", "--prefix", c.Value)(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + return carapace.ActionValues(lines...) + }) + }).Tag("groups") +} diff --git a/pkg/actions/tools/saw/stream.go b/pkg/actions/tools/saw/stream.go new file mode 100644 index 0000000000..d8afb0ebef --- /dev/null +++ b/pkg/actions/tools/saw/stream.go @@ -0,0 +1,20 @@ +package saw + +import ( + "strings" + + "github.com/carapace-sh/carapace" +) + +// ActionStreams completes log streams. +// +// streamOne +// streamTwo +func ActionStreams() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return carapace.ActionExecCommand("saw", "streams", "--prefix", c.Value)(func(output []byte) carapace.Action { + lines := strings.Split(string(output), "\n") + return carapace.ActionValues(lines...) + }) + }).Tag("streams") +}