Skip to content
Permalink
Browse files

Simplifying CLI args

  • Loading branch information...
Depado committed Oct 24, 2018
1 parent 7648a3c commit 41ee7b7ebcfc5103392cf98e9e61cec614c8a69c
Showing with 20 additions and 24 deletions.
  1. +10 −12 README.md
  2. +6 −7 cmd/flags.go
  3. +2 −3 provider/git.go
  4. +1 −1 provider/http.go
  5. +1 −1 provider/local.go
@@ -115,6 +115,8 @@ Projectmpl supports various provider to download the templates. It supports
or using a local directory.

```
projectmpl is a boilerplate engine
Usage:
projectmpl [renderer] <options> [flags]
projectmpl [command]
@@ -126,17 +128,13 @@ Available Commands:
Flags:
-c, --commands execute the after commands (make sure you know what it does)
--git.depth int depth of git clone in case of git provider (default 1)
--git.key string private key to use to clone the template if needed
-h, --help help for projectmpl
--log.format string one of text or json (default "text")
--log.level string one of debug, info, warn, error or fatal (default "info")
--log.line enable filename and line in logs
-o, --output string output directory of rendered template (default "output")
--password string password for auth if needed
--template.keep do not delete the template when operation is complete
-k, --keep do not delete the template when operation is complete
-o, --output string output directory (default "output")
-p, --path string specify if the template is actually stored in a sub-directory of the downloaded file
--template.output string specify output directory for the template
--template.path string specify if the template is actually stored in a sub-directory of the downloaded file
--user string user for auth if needed
Use "projectmpl [command] --help" for more information about a command.
```

## Commands
@@ -158,9 +156,9 @@ which defines where the template should be downloaded/cloned.

```sh
$ # Clone the repository and execute the template that is located in _example/license
$ projectmpl git@github.com:Depado/projectmpl.git --template.path _example/license
$ # Clone the template and render it in a specific directory
$ projectmpl git@github.com:Depado/projectmpl.git --template.path _example/cleanarch --template.keep --template.output "template" -o myamazingproject
$ projectmpl git@github.com:Depado/projectmpl.git --path _example/license
$ # Clone the template in a specific directory, render it in a specific directory and keep the template
$ projectmpl git@github.com:Depado/projectmpl.git --path _example/cleanarch --keep --template.output "template" -o myamazingproject
$ # Reuse the downloaded template and allow final commands
$ projectmpl template/ -c -o myotherproject
```
@@ -11,15 +11,14 @@ import (
// AddRendererFlags adds a set of flags to make the use of the program more
// flexible
func AddRendererFlags(c *cobra.Command) {
c.PersistentFlags().StringP("output", "o", "output", "output directory of rendered template")
c.PersistentFlags().Int("git.depth", 1, "depth of git clone in case of git provider")
c.PersistentFlags().String("git.key", "", "private key to use to clone the template if needed")
c.PersistentFlags().String("user", "", "user for auth if needed")
c.PersistentFlags().String("password", "", "password for auth if needed")
c.PersistentFlags().StringP("output", "o", "output", "output directory")
c.PersistentFlags().StringP("path", "p", "", "specify if the template is actually stored in a sub-directory of the downloaded file")
c.PersistentFlags().BoolP("commands", "c", false, "execute the after commands (make sure you know what it does)")
c.PersistentFlags().Bool("template.keep", false, "do not delete the template when operation is complete")
c.PersistentFlags().BoolP("keep", "k", false, "do not delete the template when operation is complete")
c.PersistentFlags().Int("git.depth", 1, "depth of git clone in case of git provider")
c.PersistentFlags().String("template.output", "", "specify output directory for the template")
c.PersistentFlags().String("template.path", "", "specify if the template is actually stored in a sub-directory of the downloaded file")
// c.PersistentFlags().String("user", "", "user for auth if needed")
// c.PersistentFlags().String("password", "", "password for auth if needed")
if err := viper.BindPFlags(c.PersistentFlags()); err != nil {
logrus.WithError(err).WithField("step", "AddLoggerFlags").Fatal("Couldn't bind flags")
}
@@ -3,10 +3,9 @@ package provider
import (
"path/filepath"

"github.com/Depado/projectmpl/utils"
"github.com/spf13/viper"
git "gopkg.in/src-d/go-git.v4"

"github.com/Depado/projectmpl/utils"
)

type gitp struct {
@@ -41,7 +40,7 @@ func (g gitp) Fetch() (string, error) {
}
s.DoneStop("Done cloning in", utils.Green.Sprint(outdir))

return filepath.Join(outdir, viper.GetString("template.path")), nil
return filepath.Join(outdir, viper.GetString("path")), nil
}

func (gitp) UsesTmp() bool {
@@ -57,7 +57,7 @@ func (h httpp) Fetch() (string, error) {
}
s.DoneStop("Donwloaded and extracted template in", utils.Green.Sprint(outdir))

return filepath.Join(outdir, viper.GetString("template.path")), nil
return filepath.Join(outdir, viper.GetString("path")), nil
}

func (httpp) Name() string {
@@ -18,7 +18,7 @@ func NewLocalProvider(in string) Provider {
}

func (l local) Fetch() (string, error) {
return filepath.Join(l.Path, viper.GetString("template.path")), nil
return filepath.Join(l.Path, viper.GetString("path")), nil
}

func (local) UsesTmp() bool {

0 comments on commit 41ee7b7

Please sign in to comment.
You can’t perform that action at this time.