Skip to content

Commit

Permalink
added benthos
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Nov 29, 2023
1 parent 6014a07 commit 9386096
Show file tree
Hide file tree
Showing 17 changed files with 485 additions and 0 deletions.
27 changes: 27 additions & 0 deletions completers/benthos_completer/cmd/blobl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var bloblCmd = &cobra.Command{
Use: "blobl ",
Short: "Execute a Bloblang mapping on documents consumed via stdin",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(bloblCmd).Standalone()

bloblCmd.Flags().StringP("file", "f", "", "execute a mapping from a file.")
bloblCmd.Flags().String("max-token-length", "", "Set the buffer size for document lines.")
bloblCmd.Flags().BoolP("pretty", "p", false, "pretty-print output.")
bloblCmd.Flags().BoolP("raw", "r", false, "consume raw strings.")
bloblCmd.Flags().StringP("threads", "t", "", "the number of processing threads to use, when >1 ordering is no longer guaranteed.")
rootCmd.AddCommand(bloblCmd)

carapace.Gen(bloblCmd).FlagCompletion(carapace.ActionMap{
"file": carapace.ActionFiles(),
})
}
31 changes: 31 additions & 0 deletions completers/benthos_completer/cmd/blobl_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/net"
"github.com/spf13/cobra"
)

var blobl_serverCmd = &cobra.Command{
Use: "server",
Short: "EXPERIMENTAL: Run a web server that hosts a Bloblang app",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(blobl_serverCmd).Standalone()

blobl_serverCmd.Flags().String("host", "", "the host to bind to.")
blobl_serverCmd.Flags().StringP("input-file", "i", "", "an optional path to an input file to load as the initial input to the mapping within the app.")
blobl_serverCmd.Flags().StringP("mapping-file", "m", "", "an optional path to a mapping file to load as the initial mapping within the app.")
blobl_serverCmd.Flags().BoolP("no-open", "n", false, "do not open the app in the browser automatically.")
blobl_serverCmd.Flags().StringP("port", "p", "", "the port to bind to.")
blobl_serverCmd.Flags().BoolP("write", "w", false, "when editing a mapping and/or input file write changes made back to the respective source file, if the file does not exist it will be created.")
bloblCmd.AddCommand(blobl_serverCmd)

carapace.Gen(blobl_serverCmd).FlagCompletion(carapace.ActionMap{
"input-file": carapace.ActionFiles(),
"mapping-file": carapace.ActionFiles(),
"port": net.ActionPorts(),
})
}
19 changes: 19 additions & 0 deletions completers/benthos_completer/cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var createCmd = &cobra.Command{
Use: "create",
Short: "Create a new Benthos config",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(createCmd).Standalone()

createCmd.Flags().BoolP("small", "s", false, "Print only the main components of a Benthos config (input, pipeline, output) and omit all fields marked as advanced.")
rootCmd.AddCommand(createCmd)
}
18 changes: 18 additions & 0 deletions completers/benthos_completer/cmd/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var echoCmd = &cobra.Command{
Use: "echo",
Short: "Parse a config file and echo back a normalised version",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(echoCmd).Standalone()

rootCmd.AddCommand(echoCmd)
}
23 changes: 23 additions & 0 deletions completers/benthos_completer/cmd/help.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var helpCmd = &cobra.Command{
Use: "help",
Short: "Shows a list of commands or help for one command",
Aliases: []string{"h"},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(helpCmd).Standalone()

rootCmd.AddCommand(helpCmd)

carapace.Gen(helpCmd).PositionalAnyCompletion(
carapace.ActionCommands(rootCmd),
)
}
25 changes: 25 additions & 0 deletions completers/benthos_completer/cmd/lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var lintCmd = &cobra.Command{
Use: "lint",
Short: "Parse Benthos configs and report any linting errors",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(lintCmd).Standalone()

lintCmd.Flags().Bool("deprecated", false, "Print linting errors for the presence of deprecated fields.")
lintCmd.Flags().Bool("labels", false, "Print linting errors when components do not have labels.")
lintCmd.Flags().Bool("skip-env-var-check", false, "Do not produce lint errors when environment interpolations exist without defaults within configs but aren't defined.")
rootCmd.AddCommand(lintCmd)

carapace.Gen(lintCmd).PositionalAnyCompletion(
carapace.ActionFiles(),
)
}
40 changes: 40 additions & 0 deletions completers/benthos_completer/cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List all Benthos component types",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(listCmd).Standalone()

listCmd.Flags().String("format", "", "Print the component list in a specific format. Options are text, json or cue.")
listCmd.Flags().String("status", "", "Filter the component list to only those matching the given status. Options are stable, beta or experimental.")
rootCmd.AddCommand(listCmd)

carapace.Gen(listCmd).FlagCompletion(carapace.ActionMap{
"format": carapace.ActionValues("text", "json", "cue"),
"status": carapace.ActionValues("stable", "beta", "experimental"),
})

carapace.Gen(listCmd).PositionalAnyCompletion(
carapace.ActionValues(
"bloblang-functions",
"bloblang-methods",
"buffers",
"caches",
"inputs",
"metrics",
"outputs",
"processors",
"rate-limits",
"tracers",
).FilterArgs(),
)
}
41 changes: 41 additions & 0 deletions completers/benthos_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "benthos",
Short: "",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}

func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().Bool("chilled", false, "continue to execute a config containing linter errors")
rootCmd.Flags().StringP("config", "c", "", "a path to a configuration file")
rootCmd.Flags().StringP("env-file", "e", "", "import environment variables from a dotenv file")
rootCmd.Flags().BoolP("help", "h", false, "show help")
rootCmd.Flags().String("log.level", "", "override the configured log level, options are: off, error, warn, info, debug, trace")
rootCmd.Flags().StringP("resources", "r", "", "pull in extra resources from a file, which can be referenced the same as resources defined in the main config, supports glob patterns (requires quotes)")
rootCmd.Flags().StringP("set", "s", "", "set a field (identified by a dot path) in the main configuration file, e.g. `\"metrics.type=prometheus\"`")
rootCmd.Flags().StringP("templates", "t", "", "EXPERIMENTAL: import Benthos templates, supports glob patterns (requires quotes)")
rootCmd.Flags().BoolP("version", "v", false, "display version info, then exit")
rootCmd.Flags().BoolP("watcher", "w", false, "EXPERIMENTAL: watch config files for changes and automatically apply them")

carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{
"config": carapace.ActionFiles(),
"env-file": carapace.ActionFiles(),
"log.level": carapace.ActionValues("off", "error", "warn", "info", "debug", "trace").StyleF(style.ForLogLevel),
"resources": carapace.ActionValues(), // TODO
"set": carapace.ActionValues(), // TODO
"templates": carapace.ActionValues(), // TODO
})
}
24 changes: 24 additions & 0 deletions completers/benthos_completer/cmd/streams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var streamsCmd = &cobra.Command{
Use: "streams",
Short: "Run Benthos in streams mode",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(streamsCmd).Standalone()

streamsCmd.Flags().Bool("no-api", false, "Disable the HTTP API for streams mode")
streamsCmd.Flags().Bool("prefix-stream-endpoints", false, "Whether HTTP endpoints registered by stream configs should be prefixed with the stream ID")
rootCmd.AddCommand(streamsCmd)

carapace.Gen(streamsCmd).PositionalAnyCompletion(
carapace.ActionFiles(),
)
}
19 changes: 19 additions & 0 deletions completers/benthos_completer/cmd/studio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var studioCmd = &cobra.Command{
Use: "studio",
Short: "Interact with Benthos studio (https://studio.benthos.dev)",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(studioCmd).Standalone()

studioCmd.Flags().StringP("endpoint", "e", "", "Specify the URL of the Benthos studio server to connect to.")
rootCmd.AddCommand(studioCmd)
}
23 changes: 23 additions & 0 deletions completers/benthos_completer/cmd/studio_pull.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var studio_pullCmd = &cobra.Command{
Use: "pull",
Short: "Run deployments configured within a Benthos Studio session",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(studio_pullCmd).Standalone()

studio_pullCmd.Flags().String("name", "", "An explicit name to adopt in this instance, used to identify its connection to the session. Each running node must have a unique name, if left unset a name is generated each time the command is run.")
studio_pullCmd.Flags().Bool("send-traces", false, "Whether to send trace data back to Studio during execution. This is opt-in and is used as a way to add trace events to the graph editor for testing and debugging configs. This is a very useful feature but should be used with caution as it exports information about messages passing through the stream.")
studio_pullCmd.Flags().StringP("session", "s", "", "The session ID to synchronise with.")
studio_pullCmd.Flags().String("token", "", "A token for the session, used to authenticate requests. If left blank the environment variable BSTDIO_NODE_TOKEN will be used instead.")
studio_pullCmd.Flags().String("token-secret", "", "A token secret the session, used to authenticate requests. If left blank the environment variable BSTDIO_NODE_SECRET will be used instead.")
studioCmd.AddCommand(studio_pullCmd)
}
20 changes: 20 additions & 0 deletions completers/benthos_completer/cmd/studio_syncSchema.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var studio_syncSchemaCmd = &cobra.Command{
Use: "sync-schema",
Short: "Synchronizes the schema of this Benthos instance with a studio session",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(studio_syncSchemaCmd).Standalone()

studio_syncSchemaCmd.Flags().StringP("session", "s", "", "The session ID to synchronize with.")
studio_syncSchemaCmd.Flags().StringP("token", "t", "", "The single use token used to authenticate the request.")
studioCmd.AddCommand(studio_syncSchemaCmd)
}
18 changes: 18 additions & 0 deletions completers/benthos_completer/cmd/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var templateCmd = &cobra.Command{
Use: "template",
Short: "Interact and generate Benthos templates",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(templateCmd).Standalone()

rootCmd.AddCommand(templateCmd)
}
22 changes: 22 additions & 0 deletions completers/benthos_completer/cmd/template_lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var template_lintCmd = &cobra.Command{
Use: "lint",
Short: "Parse Benthos templates and report any linting errors",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(template_lintCmd).Standalone()

templateCmd.AddCommand(template_lintCmd)

carapace.Gen(template_lintCmd).PositionalAnyCompletion(
carapace.ActionFiles(),
)
}
28 changes: 28 additions & 0 deletions completers/benthos_completer/cmd/test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace/pkg/style"
"github.com/spf13/cobra"
)

var testCmd = &cobra.Command{
Use: "test",
Short: "Execute Benthos unit tests",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(testCmd).Standalone()

testCmd.Flags().String("log", "", "allow components to write logs at a provided level to stdout.")
rootCmd.AddCommand(testCmd)

carapace.Gen(testCmd).FlagCompletion(carapace.ActionMap{
"log": carapace.ActionValues("error", "warn", "info", "debug", "trace").StyleF(style.ForLogLevel),
})

carapace.Gen(testCmd).PositionalAnyCompletion(
carapace.ActionFiles(),
)
}
Loading

0 comments on commit 9386096

Please sign in to comment.