From 8c9f8715e9fa4988a47914e4ea76693a6249959e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sat, 6 Apr 2024 00:11:21 +0200 Subject: [PATCH] allow to specify a git branch to mention in the readme --- cmd/generate.go | 9 +++++++++ template/README.md.tmpl | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index e64da75..542a62e 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -20,12 +20,17 @@ func GenerateCommand() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { projectName := cmd.Flag("project-name").Value.String() githubRepo := cmd.Flag("github-repo").Value.String() + gitBranch := cmd.Flag("git-branch").Value.String() out := cmd.Flag("out").Value.String() if githubRepo == "" { return errors.Errorf("Github repo is missing") } + if gitBranch == "" { + return errors.Errorf("Git branch is missing") + } + s := scaffolder.New() if !test { @@ -35,6 +40,7 @@ func GenerateCommand() *cobra.Command { return s.Scaffold(kleinerTemplate.Template, scaffolder.ScaffoldData{ "ProjectName": projectName, "GithubRepo": githubRepo, + "GitBranch": gitBranch, }) }, } @@ -56,8 +62,11 @@ func GenerateCommand() *cobra.Command { log.Println(err) } + var gitBranch string = "main" + generateCmd.Flags().String("project-name", projectName, "Project and binary name, current folder name by default") generateCmd.Flags().String("github-repo", githubRepo, "Github repo in form user/repo") + generateCmd.Flags().String("git-branch", gitBranch, "Git branch to refer in the readme") generateCmd.Flags().String("out", path, "Output folder") generateCmd.Flags().BoolVarP(&test, "test", "", false, "Do not write anything, write everything to stdout") diff --git a/template/README.md.tmpl b/template/README.md.tmpl index 34d7c56..b4dfdab 100644 --- a/template/README.md.tmpl +++ b/template/README.md.tmpl @@ -11,13 +11,13 @@ Download `{{ .ProjectName }}` and install into a local bin directory. Latest version: ```bash -curl -L https://raw.githubusercontent.com/{{ .GithubRepo }}/main/generated/install.sh | sh +curl -L https://raw.githubusercontent.com/{{ .GithubRepo }}/{{ .GitBranch }}/generated/install.sh | sh ``` Specific version: ```bash -curl -L https://raw.githubusercontent.com/{{ .GithubRepo }}/main/generated/install.sh | sh -s 0.0.4 +curl -L https://raw.githubusercontent.com/{{ .GithubRepo }}/{{ .GitBranch }}/generated/install.sh | sh -s 0.0.4 ``` The script will install the binary into `$HOME/bin` folder by default, you can override this by setting