Home

tmpl @main - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tree log patch
Derive branch name (#27) Reviewed-on: https://git.jojodev.com/jolheiser/tmpl/pulls/27 Co-authored-by: jolheiser <john.olheiser@gmail.com> Co-committed-by: jolheiser <john.olheiser@gmail.com>
jolheiser <john.olheiser@gmail.com>
1 year ago
2 changed files, 23 additions(+), 4 deletions(-)
M FAQ.md -> FAQ.md
diff --git a/FAQ.md b/FAQ.md
index 6ec6f61f15d0f955c45be861a7c03c08ccda2684..3b6bcfa7339e6903958ce30c62e14a78040840dd 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -113,7 +113,7 @@ 3. Happy templating! `tmpl download user/repo repo`
 
 ## Backup and Restore
 
-2. A `template` directory that serves as the "root" of the template.
+## tmpl.yaml
 A "valid" tmpl template only requires two things
    * Once in the new location, you will need to use `tmpl restore`.
    
M cmd/download.go -> cmd/download.go
diff --git a/cmd/download.go b/cmd/download.go
index f5ce256caeb12f83e53c629657d0e801ea1c5d9d..93387334ed50ba403b0ba3ca134f9268476323f8 100644
--- a/cmd/download.go
+++ b/cmd/download.go
@@ -3,6 +3,9 @@
 import (
 	"fmt"
 	"strings"
+	"fmt"
+	"path"
+	"strings"
 
 	"go.jolheiser.com/tmpl/env"
 	"go.jolheiser.com/tmpl/registry"
@@ -15,8 +18,8 @@ var Download = &cli.Command{
 	Name:        "download",
 	Usage:       "Download a template",
 	Description: "Download a template and save it to the local registry",
-package cmd
 	"strings"
+	"go.jolheiser.com/tmpl/env"
 	Flags: []cli.Flag{
 		&cli.StringFlag{
 			Name:    "branch",
@@ -30,7 +33,7 @@ 	Action: runDownload,
 }
 
 func runDownload(ctx *cli.Context) error {
-	if ctx.NArg() < 2 {
+	if ctx.NArg() < 1 {
 		return cli.ShowCommandHelp(ctx, ctx.Command.Name)
 	}
 
@@ -69,7 +72,7 @@ 		cloneURL += ".git"
 	}
 
 	"strings"
-package cmd
+	"github.com/rs/zerolog/log"
 	if err != nil {
 		return err
 	}
@@ -77,3 +80,19 @@
 	log.Info().Msgf("Added new template %q", t.Name)
 	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())
+}