Compare commits
No commits in common. "b687e6348e0b080a0e11f26a4f5349c1371b2859" and "4981a14e14908c4b15ff4a22a600b61a49508126" have entirely different histories.
b687e6348e
...
4981a14e14
2
FAQ.md
2
FAQ.md
|
@ -113,7 +113,7 @@ I realize that many users will be using GitHub, and most will likely still be us
|
||||||
|
|
||||||
## Backup and Restore
|
## Backup and Restore
|
||||||
|
|
||||||
1. The simplest solution is to make a copy of your `registry.yaml` (default: `~/.tmpl/registry.yaml`).
|
1. The simplest solution is to make a copy of your `registry.toml` (default: `~/.tmpl/registry.toml`).
|
||||||
* Once in the new location, you will need to use `tmpl restore`.
|
* Once in the new location, you will need to use `tmpl restore`.
|
||||||
|
|
||||||
2. Alternatively, you can copy/paste the entire registry (default: `~/.tmpl`) and skip the restore step.
|
2. Alternatively, you can copy/paste the entire registry (default: `~/.tmpl`) and skip the restore step.
|
||||||
|
|
|
@ -2,8 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"go.jolheiser.com/tmpl/env"
|
"go.jolheiser.com/tmpl/env"
|
||||||
|
@ -17,7 +15,7 @@ var Download = &cli.Command{
|
||||||
Name: "download",
|
Name: "download",
|
||||||
Usage: "Download a template",
|
Usage: "Download a template",
|
||||||
Description: "Download a template and save it to the local registry",
|
Description: "Download a template and save it to the local registry",
|
||||||
ArgsUsage: "[repository URL] <name>",
|
ArgsUsage: "[repository URL] [name]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "branch",
|
Name: "branch",
|
||||||
|
@ -31,7 +29,7 @@ var Download = &cli.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDownload(ctx *cli.Context) error {
|
func runDownload(ctx *cli.Context) error {
|
||||||
if ctx.NArg() < 1 {
|
if ctx.NArg() < 2 {
|
||||||
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +67,7 @@ func runDownload(ctx *cli.Context) error {
|
||||||
cloneURL += ".git"
|
cloneURL += ".git"
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := reg.DownloadTemplate(deriveName(ctx), cloneURL, ctx.String("branch"))
|
t, err := reg.DownloadTemplate(ctx.Args().Get(1), cloneURL, ctx.String("branch"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -77,19 +75,3 @@ func runDownload(ctx *cli.Context) error {
|
||||||
log.Info().Msgf("Added new template %q", t.Name)
|
log.Info().Msgf("Added new template %q", t.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deriveName(ctx *cli.Context) string {
|
|
||||||
if ctx.NArg() > 1 {
|
|
||||||
return ctx.Args().Get(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
envBranch, envSet := os.LookupEnv("TMPL_BRANCH")
|
|
||||||
flagBranch, flagSet := ctx.String("branch"), ctx.IsSet("branch")
|
|
||||||
if flagSet {
|
|
||||||
if !envSet || envBranch != flagBranch {
|
|
||||||
return flagBranch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.Base(ctx.Args().First())
|
|
||||||
}
|
|
||||||
|
|
13
cmd/list.go
13
cmd/list.go
|
@ -1,7 +1,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
@ -15,25 +14,15 @@ var List = &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List templates in the registry",
|
Usage: "List templates in the registry",
|
||||||
Description: "List all usable templates currently downloaded in the registry",
|
Description: "List all usable templates currently downloaded in the registry",
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "json",
|
|
||||||
Usage: "JSON format",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Action: runList,
|
Action: runList,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runList(ctx *cli.Context) error {
|
func runList(_ *cli.Context) error {
|
||||||
reg, err := registry.Open(registryFlag)
|
reg, err := registry.Open(registryFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Bool("json") {
|
|
||||||
return json.NewEncoder(os.Stdout).Encode(reg.Templates)
|
|
||||||
}
|
|
||||||
|
|
||||||
wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
if _, err := fmt.Fprintf(wr, "NAME\tURL\tLOCAL\tLAST UPDATED\n"); err != nil {
|
if _, err := fmt.Fprintf(wr, "NAME\tURL\tLOCAL\tLAST UPDATED\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
@ -29,12 +28,6 @@ var (
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List available sources",
|
Usage: "List available sources",
|
||||||
Description: "List all available sources in the registry",
|
Description: "List all available sources in the registry",
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "json",
|
|
||||||
Usage: "JSON format",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Action: runSourceList,
|
Action: runSourceList,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,16 +48,12 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func runSourceList(ctx *cli.Context) error {
|
func runSourceList(_ *cli.Context) error {
|
||||||
reg, err := registry.Open(registryFlag)
|
reg, err := registry.Open(registryFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Bool("json") {
|
|
||||||
return json.NewEncoder(os.Stdout).Encode(reg.Sources)
|
|
||||||
}
|
|
||||||
|
|
||||||
wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
wr := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
|
||||||
if _, err := fmt.Fprintf(wr, "NAME\tURL\n"); err != nil {
|
if _, err := fmt.Fprintf(wr, "NAME\tURL\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
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
|
|
||||||
]
|
|
Loading…
Reference in New Issue