mirror of
https://github.com/rsteube/carapace-bin.git
synced 2025-05-05 23:42:54 +00:00
added saw (#2620)
This commit is contained in:
parent
a5a8d832b1
commit
07501f62e6
18
completers/saw_completer/cmd/completion.go
Normal file
18
completers/saw_completer/cmd/completion.go
Normal file
@ -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)
|
||||||
|
}
|
19
completers/saw_completer/cmd/completion_bash.go
Normal file
19
completers/saw_completer/cmd/completion_bash.go
Normal file
@ -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)
|
||||||
|
}
|
19
completers/saw_completer/cmd/completion_fish.go
Normal file
19
completers/saw_completer/cmd/completion_fish.go
Normal file
@ -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)
|
||||||
|
}
|
19
completers/saw_completer/cmd/completion_powershell.go
Normal file
19
completers/saw_completer/cmd/completion_powershell.go
Normal file
@ -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)
|
||||||
|
}
|
19
completers/saw_completer/cmd/completion_zsh.go
Normal file
19
completers/saw_completer/cmd/completion_zsh.go
Normal file
@ -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)
|
||||||
|
}
|
37
completers/saw_completer/cmd/get.go
Normal file
37
completers/saw_completer/cmd/get.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/carapace-sh/carapace"
|
||||||
|
"github.com/carapace-sh/carapace-bin/pkg/actions/time"
|
||||||
|
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/saw"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var getCmd = &cobra.Command{
|
||||||
|
Use: "get <log group>",
|
||||||
|
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).FlagCompletion(carapace.ActionMap{
|
||||||
|
"start": time.ActionDate(),
|
||||||
|
"stop": time.ActionDate(),
|
||||||
|
})
|
||||||
|
|
||||||
|
carapace.Gen(getCmd).PositionalCompletion(
|
||||||
|
saw.ActionGroups(),
|
||||||
|
)
|
||||||
|
}
|
19
completers/saw_completer/cmd/groups.go
Normal file
19
completers/saw_completer/cmd/groups.go
Normal file
@ -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)
|
||||||
|
}
|
18
completers/saw_completer/cmd/help.go
Normal file
18
completers/saw_completer/cmd/help.go
Normal file
@ -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)
|
||||||
|
}
|
44
completers/saw_completer/cmd/root.go
Normal file
44
completers/saw_completer/cmd/root.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/carapace-sh/carapace"
|
||||||
|
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/aws"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
var rootCmd = &cobra.Command{
|
||||||
|
Use: "saw <command>",
|
||||||
|
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(),
|
||||||
|
})
|
||||||
|
|
||||||
|
carapace.Gen(rootCmd).PreInvoke(func(cmd *cobra.Command, flag *pflag.Flag, action carapace.Action) carapace.Action {
|
||||||
|
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||||
|
if f := rootCmd.Flag("profile"); f.Changed {
|
||||||
|
c.Setenv("AWS_PROFILE", f.Value.String())
|
||||||
|
}
|
||||||
|
if f := rootCmd.Flag("region"); f.Changed {
|
||||||
|
c.Setenv("AWS_REGION", f.Value.String())
|
||||||
|
}
|
||||||
|
return action.Invoke(c).ToA()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
30
completers/saw_completer/cmd/streams.go
Normal file
30
completers/saw_completer/cmd/streams.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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 <log group>",
|
||||||
|
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).FlagCompletion(carapace.ActionMap{
|
||||||
|
"orderBy": carapace.ActionValues("LogStreamName", "LastEventTime"),
|
||||||
|
})
|
||||||
|
|
||||||
|
carapace.Gen(streamsCmd).PositionalCompletion(
|
||||||
|
saw.ActionGroups(),
|
||||||
|
)
|
||||||
|
}
|
18
completers/saw_completer/cmd/version.go
Normal file
18
completers/saw_completer/cmd/version.go
Normal file
@ -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)
|
||||||
|
}
|
29
completers/saw_completer/cmd/watch.go
Normal file
29
completers/saw_completer/cmd/watch.go
Normal file
@ -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 <log group>",
|
||||||
|
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(),
|
||||||
|
)
|
||||||
|
}
|
7
completers/saw_completer/main.go
Normal file
7
completers/saw_completer/main.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/carapace-sh/carapace-bin/completers/saw_completer/cmd"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cmd.Execute()
|
||||||
|
}
|
20
pkg/actions/tools/saw/group.go
Normal file
20
pkg/actions/tools/saw/group.go
Normal file
@ -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")
|
||||||
|
}
|
20
pkg/actions/tools/saw/stream.go
Normal file
20
pkg/actions/tools/saw/stream.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package saw
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/carapace-sh/carapace"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ActionStreams completes log streams.
|
||||||
|
//
|
||||||
|
// streamOne
|
||||||
|
// streamTwo
|
||||||
|
func ActionStreams(group string) carapace.Action {
|
||||||
|
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
|
||||||
|
return carapace.ActionExecCommand("saw", "streams", "--prefix", c.Value, group)(func(output []byte) carapace.Action {
|
||||||
|
lines := strings.Split(string(output), "\n")
|
||||||
|
return carapace.ActionValues(lines...)
|
||||||
|
})
|
||||||
|
}).Tag("streams")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user