Home

tmpl @main - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tree log patch
Nushell completions (#28) Reviewed-on: https://git.jojodev.com/jolheiser/tmpl/pulls/28
jolheiser <john+jojodev@jolheiser.com>
1 year ago
3 changed files, 140 additions(+), 4 deletions(-)
M cmd/list.go -> cmd/list.go
diff --git a/cmd/list.go b/cmd/list.go
index 32002bef12ef1fed10fd1aab583bc62557307709..7c1be1aadad207a6c0eeb74423264c31ce2fd02b 100644
--- a/cmd/list.go
+++ b/cmd/list.go
@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"encoding/json"
 	"fmt"
 	"os"
 	"text/tabwriter"
@@ -14,15 +15,25 @@ var List = &cli.Command{
 	Name:        "list",
 	Usage:       "List templates in the registry",
 	Description: "List all usable templates currently downloaded in the registry",
-package cmd
+import (
 	"fmt"
+		&cli.BoolFlag{
+			Name:  "json",
+			Usage: "JSON format",
+		},
+	},
+	Action: runList,
 }
 
+	"fmt"
 package cmd
-	"text/tabwriter"
 	reg, err := registry.Open(registryFlag)
 	if err != nil {
 		return err
+	}
+
+	if ctx.Bool("json") {
+		return json.NewEncoder(os.Stdout).Encode(reg.Templates)
 	}
 
 	wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
M cmd/source.go -> cmd/source.go
diff --git a/cmd/source.go b/cmd/source.go
index 1a5f820279092622d0ae16f29eb41e8269d1ce3a..70f2adb2f1760bb1dba6792d5e43b7eb46d2ea7f 100644
--- a/cmd/source.go
+++ b/cmd/source.go
@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"encoding/json"
 	"fmt"
 	"os"
 	"text/tabwriter"
@@ -28,9 +29,16 @@ 	SourceList = &cli.Command{
 		Name:        "list",
 		Usage:       "List available sources",
 		Description: "List all available sources in the registry",
-
+		Flags: []cli.Flag{
+			&cli.BoolFlag{
+				Name:  "json",
+				Usage: "JSON format",
+	"text/tabwriter"
 	"go.jolheiser.com/tmpl/registry"
 
+package cmd
+		Action: runSourceList,
+
 
 
 	SourceAdd = &cli.Command{
@@ -50,10 +58,14 @@ 		Action:      runSourceRemove,
 	}
 )
 
-func runSourceList(_ *cli.Context) error {
+func runSourceList(ctx *cli.Context) error {
 	reg, err := registry.Open(registryFlag)
 	if err != nil {
 		return err
+	}
+
+	if ctx.Bool("json") {
+		return json.NewEncoder(os.Stdout).Encode(reg.Sources)
 	}
 
 	wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
I contrib/tmpl-completions.nu
diff --git a/contrib/tmpl-completions.nu b/contrib/tmpl-completions.nu
new file mode 100644
index 0000000000000000000000000000000000000000..ca99993f113296e9d27779213188b40cbb79513e
--- /dev/null
+++ b/contrib/tmpl-completions.nu
@@ -0,0 +1,113 @@
+def _tmpl_env_keys [] {
+  ["TMPL_SOURCE", "TMPL_REGISTRY", "TMPL_BRANCH"]
+}
+
+def _tmpl_source_list [] {
+  ^tmpl source list --json | from json | each { |it| { value: $it.Name, description: $it.URL } }
+}
+
+def _tmpl_template_list [] {
+  ^tmpl list --json | from json | each { |it| { value: $it.Name, description: (if $it.Path != "" { $it.Path } else { $"($it.Repository)@($it.Branch)" }) } }
+}
+
+
+# Template automation
+export extern "tmpl" [
+  --registry(-r): string # Registry directory of tmpl (default: ~/.tmpl) [$TMPL_REGISTRY]
+  --source(-s): string   # Short-name source to use [$TMPL_SOURCE]
+  --help(-h): bool       # Show help
+  --version(-v): bool    # Show version
+]
+
+# Download a template
+export extern "tmpl download" [
+  repo_url: string     # Repository URL
+  name: string         # Local name for template
+  --branch(-b): string # Branch to clone (default: "main") [$TMPL_BRANCH]
+  --help(-h): bool     # Show help
+]
+
+# Manage tmpl environment variables
+export extern "tmpl env" [
+  --help(-h): bool # Show help
+]
+
+# Set a tmpl environment variable
+export extern "tmpl env set" [
+  key: string@"_tmpl_env_keys" # Env key
+  value: string                # Env value
+  --help(-h): bool             # Show help
+]
+
+# Unset a tmpl environment variable
+export extern "tmpl env unset" [
+  key: string@"_tmpl_env_keys" # Env key
+]
+
+# Initialize a blank tmpl template
+export extern "tmpl init" [
+  --help(-h): bool # Show help
+]
+
+# List all templates in registry
+export extern "tmpl list" [
+  --json: bool     # Output in JSON
+  --help(-h): bool # Show help
+]
+
+# Remove a template
+export extern "tmpl remove" [
+  name: string     # Name of the template to remove
+  --help(-h): bool #Show help
+]
+
+# Restore templates present in the registry, but missing archives
+export extern "tmpl restore" [
+  --help(-h): # Show help
+]
+
+# Save a local template
+export extern "tmpl save" [
+  path: string     # Path to the local template
+  name: string     # Name of the template
+  --help(-h): bool # Show help
+]
+
+# Work with tmpl sources
+export extern "tmpl source" [
+  --help(-h): # Show help
+]
+
+# Add a tmpl source
+export extern "tmpl source add" [
+  base_url: string # Base URL
+  name: string     # Name
+  --help(-h): bool # Show help
+]
+
+# Remove a tmpl source
+export extern "tmpl source remove" [
+  name: string@"_tmpl_source_list" # Source to remove
+  --help(-h): bool                 # Show help
+]
+
+# Test whether a directory is a valid tmpl template
+export extern "tmpl test" [
+  path?: string    # Path to test (default: ".")
+  --help(-h): bool # Show help
+]
+
+# Update a template
+export extern "tmpl update" [
+  name: string@"_tmpl_template_list" # Template to update
+  --help(-h):                        # Show help
+]
+
+# Use a template
+export extern "tmpl use" [
+  name: string@"_tmpl_template_list" # The template to execute
+  dest?: path                       # Destination for the template (default: ".")
+  --defaults: bool                  # Use template defaults
+  --force: bool                     # Overwrite existing files
+  --help(-h): bool                  # Show help
+]