From 798dce512e14991a7b60e894b0520ef42c5baf0e Mon Sep 17 00:00:00 2001 From: rsteube Date: Sun, 15 Oct 2023 01:23:53 +0200 Subject: [PATCH] added templ --- completers/templ_completer/cmd/fmt.go | 23 +++++++++++ completers/templ_completer/cmd/generate.go | 38 ++++++++++++++++++ completers/templ_completer/cmd/lsp.go | 46 ++++++++++++++++++++++ completers/templ_completer/cmd/migrate.go | 26 ++++++++++++ completers/templ_completer/cmd/root.go | 20 ++++++++++ completers/templ_completer/main.go | 7 ++++ 6 files changed, 160 insertions(+) create mode 100644 completers/templ_completer/cmd/fmt.go create mode 100644 completers/templ_completer/cmd/generate.go create mode 100644 completers/templ_completer/cmd/lsp.go create mode 100644 completers/templ_completer/cmd/migrate.go create mode 100644 completers/templ_completer/cmd/root.go create mode 100644 completers/templ_completer/main.go diff --git a/completers/templ_completer/cmd/fmt.go b/completers/templ_completer/cmd/fmt.go new file mode 100644 index 0000000000..a97c68e63f --- /dev/null +++ b/completers/templ_completer/cmd/fmt.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var fmtCmd = &cobra.Command{ + Use: "fmt", + Short: "Format *.templ files", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(fmtCmd).Standalone() + + fmtCmd.Flags().BoolS("help", "help", false, "Print help and exit.") + rootCmd.AddCommand(fmtCmd) + + carapace.Gen(fmtCmd).PositionalCompletion( + carapace.ActionDirectories(), + ) +} diff --git a/completers/templ_completer/cmd/generate.go b/completers/templ_completer/cmd/generate.go new file mode 100644 index 0000000000..b828417bc1 --- /dev/null +++ b/completers/templ_completer/cmd/generate.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/net" + "github.com/rsteube/carapace-bridge/pkg/actions/bridge" + "github.com/spf13/cobra" +) + +var generateCmd = &cobra.Command{ + Use: "generate", + Short: "Generate Go code from *.templ files", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(generateCmd).Standalone() + + generateCmd.Flags().StringS("cmd", "cmd", "", "Set the command to run after generating code") + generateCmd.Flags().StringS("f", "f", "", "Optionally generates code for a single file") + generateCmd.Flags().BoolS("help", "help", false, "Print help and exit.") + generateCmd.Flags().StringS("path", "path", "", "Generates code for all files in path") + generateCmd.Flags().StringS("pprof", "pprof", "", "Port to start pprof web server on") + generateCmd.Flags().StringS("proxy", "proxy", "", "Set the URL to proxy") + generateCmd.Flags().StringS("proxyport", "proxyport", "", "The port the proxy will listen on") + generateCmd.Flags().BoolS("sourceMapVisualisations", "sourceMapVisualisations", false, "Generate HTML files to visualise the templ code") + generateCmd.Flags().StringS("w", "w", "", "Number of workers to run in parallel") + generateCmd.Flags().BoolS("watch", "watch", false, "Watch the path for changes and regenerate code") + rootCmd.AddCommand(generateCmd) + + carapace.Gen(generateCmd).FlagCompletion(carapace.ActionMap{ + "cmd": bridge.ActionCarapaceBin().Split(), + "f": carapace.ActionFiles(), + "path": carapace.ActionDirectories(), + "pprof": net.ActionPorts(), + "proxyport": net.ActionPorts(), + }) +} diff --git a/completers/templ_completer/cmd/lsp.go b/completers/templ_completer/cmd/lsp.go new file mode 100644 index 0000000000..cffbeb8fb5 --- /dev/null +++ b/completers/templ_completer/cmd/lsp.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/pkg/actions/net" + "github.com/spf13/cobra" +) + +var lspCmd = &cobra.Command{ + Use: "lsp", + Short: "Start LSP server", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(lspCmd).Standalone() + + lspCmd.Flags().StringS("goplsLog", "goplsLog", "", "The file to log gopls output, or leave empty to disable logging.") + lspCmd.Flags().BoolS("goplsRPCTrace", "goplsRPCTrace", false, "Set gopls to log input and output messages") + lspCmd.Flags().BoolS("help", "help", false, "Print help and exit") + lspCmd.Flags().StringS("http", "http", "", "Enable http debug server by setting a listen address") + lspCmd.Flags().StringS("log", "log", "", "The file to log templ LSP output to, or leave empty to disable logging") + lspCmd.Flags().BoolS("pprof", "pprof", false, "Enable pprof web server") + rootCmd.AddCommand(lspCmd) + + carapace.Gen(lspCmd).FlagCompletion(carapace.ActionMap{ + "goplsLog": carapace.ActionFiles(), + "http": carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues() + default: + return net.ActionPorts() + } + }), + "log": carapace.ActionFiles(), + "pprof": carapace.ActionMultiPartsN(":", 2, func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues() + default: + return net.ActionPorts() + } + }), + }) +} diff --git a/completers/templ_completer/cmd/migrate.go b/completers/templ_completer/cmd/migrate.go new file mode 100644 index 0000000000..1e39085595 --- /dev/null +++ b/completers/templ_completer/cmd/migrate.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var migrateCmd = &cobra.Command{ + Use: "migrate", + Short: "Migrate *.templ files", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(migrateCmd).Standalone() + + migrateCmd.Flags().StringS("f", "f", "", "Optionally migrate a single file") + migrateCmd.Flags().BoolS("help", "help", false, "Print help and exit") + migrateCmd.Flags().StringS("path", "path", "", "Migrates code for all files in path") + rootCmd.AddCommand(migrateCmd) + + carapace.Gen(migrateCmd).FlagCompletion(carapace.ActionMap{ + "f": carapace.ActionFiles(".templ"), + "path": carapace.ActionDirectories(), + }) +} diff --git a/completers/templ_completer/cmd/root.go b/completers/templ_completer/cmd/root.go new file mode 100644 index 0000000000..0adcdc7b58 --- /dev/null +++ b/completers/templ_completer/cmd/root.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "templ", + Short: "A language for writing HTML user interfaces in Go", + Long: "https://github.com/a-h/templ", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} +func init() { + carapace.Gen(rootCmd).Standalone() +} diff --git a/completers/templ_completer/main.go b/completers/templ_completer/main.go new file mode 100644 index 0000000000..9fc7911f21 --- /dev/null +++ b/completers/templ_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/templ_completer/cmd" + +func main() { + cmd.Execute() +}