Skip to content

Commit

Permalink
Merge pull request #1910 from rsteube/add-templ
Browse files Browse the repository at this point in the history
added templ
  • Loading branch information
rsteube authored Oct 15, 2023
2 parents e1fdf0a + 798dce5 commit 188ffdc
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
23 changes: 23 additions & 0 deletions completers/templ_completer/cmd/fmt.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 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(),
)
}
38 changes: 38 additions & 0 deletions completers/templ_completer/cmd/generate.go
Original file line number Diff line number Diff line change
@@ -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(),
})
}
46 changes: 46 additions & 0 deletions completers/templ_completer/cmd/lsp.go
Original file line number Diff line number Diff line change
@@ -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()
}
}),
})
}
26 changes: 26 additions & 0 deletions completers/templ_completer/cmd/migrate.go
Original file line number Diff line number Diff line change
@@ -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(),
})
}
20 changes: 20 additions & 0 deletions completers/templ_completer/cmd/root.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 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()
}
7 changes: 7 additions & 0 deletions completers/templ_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/templ_completer/cmd"

func main() {
cmd.Execute()
}

0 comments on commit 188ffdc

Please sign in to comment.