Skip to content

Commit

Permalink
Merge pull request #21 from Ilyes512/feature/fix-goreportcard-reports
Browse files Browse the repository at this point in the history
Feature/fix goreportcard reports
  • Loading branch information
Ilyes512 committed Nov 10, 2018
2 parents 7490e48 + 6708319 commit fd7ae9f
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 46 deletions.
27 changes: 13 additions & 14 deletions boilr.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package main

import (
"fmt"
"github.com/Ilyes512/boilr/pkg/boilr"
"github.com/Ilyes512/boilr/pkg/cmd"
"github.com/Ilyes512/boilr/pkg/util/exit"
"github.com/Ilyes512/boilr/pkg/util/osutil"
"fmt"
"github.com/Ilyes512/boilr/pkg/boilr"
"github.com/Ilyes512/boilr/pkg/cmd"
"github.com/Ilyes512/boilr/pkg/util/exit"
"github.com/Ilyes512/boilr/pkg/util/osutil"
)

func main() {
if exists, err := osutil.DirExists(boilr.Configuration.TemplateDirPath); ! exists {
if err := osutil.CreateDirs(boilr.Configuration.TemplateDirPath); err != nil {
exit.Error(fmt.Errorf("tried to initialise your template directory, but it has failed: %s", err))
}
} else if err != nil {
exit.Error(fmt.Errorf("failed to init: %s", err))
}
if exists, err := osutil.DirExists(boilr.Configuration.TemplateDirPath); !exists {
if err := osutil.CreateDirs(boilr.Configuration.TemplateDirPath); err != nil {
exit.Error(fmt.Errorf("tried to initialise your template directory, but it has failed: %s", err))
}
} else if err != nil {
exit.Error(fmt.Errorf("failed to init: %s", err))
}

cmd.Run()
cmd.Run()
}

1 change: 1 addition & 0 deletions pkg/boilr/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TemplatePath(name string) (string, error) {
return filepath.Join(Configuration.TemplateDirPath, name), nil
}

// IsTemplateDirInitialized returns true when the template dir is already initialized.
func IsTemplateDirInitialized() (bool, error) {
return osutil.DirExists(Configuration.TemplateDirPath)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/bash_completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"os"
"path/filepath"

cli "github.com/spf13/cobra"
"github.com/Ilyes512/boilr/pkg/boilr"
"github.com/Ilyes512/boilr/pkg/util/exit"
"github.com/Ilyes512/boilr/pkg/util/osutil"
cli "github.com/spf13/cobra"
)

func configureBashCompletion() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var Delete = &cli.Command{
Use: "delete <template-tag>",
Short: "Delete a project template from the template registry",
Run: func(c *cli.Command, args []string) {
MustValidateVarArgs(args, validate.Argument{"template-path", validate.AlphanumericExt})
MustValidateVarArgs(args, validate.Argument{Name: "template-path", Validate: validate.AlphanumericExt})

MustValidateTemplateDir()

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var Download = &cli.Command{
// FIXME Half-Updates leave messy templates
Run: func(cmd *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"template-repo", validate.UnixPath},
{"template-tag", validate.AlphanumericExt},
{Name: "template-repo", Validate: validate.UnixPath},
{Name: "template-tag", Validate: validate.AlphanumericExt},
})

MustValidateTemplateDir()
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ func GetBoolFlag(c *cli.Command, name string) bool {
return c.PersistentFlags().Lookup(name).Value.String() == "true"
}

// GetStringFlag retrieves the named string command-line
// flag given the command that contains it.
func GetStringFlag(c *cli.Command, name string) string {
return c.PersistentFlags().Lookup(name).Value.String()
}
2 changes: 1 addition & 1 deletion pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package cmd
import (
"fmt"

cli "github.com/spf13/cobra"
"github.com/Ilyes512/boilr/pkg/boilr"
"github.com/Ilyes512/boilr/pkg/util/exit"
"github.com/Ilyes512/boilr/pkg/util/osutil"
cli "github.com/spf13/cobra"
)

// Init contains the cli-command for initializing the local template
Expand Down
7 changes: 2 additions & 5 deletions pkg/cmd/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ func serializeMetadata(tag string, repo string, targetDir string) error {

enc := json.NewEncoder(f)

t := template.Metadata{tag, repo, template.NewTime()}
if err := enc.Encode(&t); err != nil {
return err
}
t := template.Metadata{Tag: tag, Repository: repo, Created: template.NewTime()}

return nil
return enc.Encode(&t)
}
14 changes: 3 additions & 11 deletions pkg/cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,15 @@ import (
"github.com/Ilyes512/boilr/pkg/util/validate"
)

func renameTemplate(oldPath, newPath string) error {
if err := os.Rename(oldPath, newPath); err != nil {
return err
}

return nil
}

// Rename contains the cli-command for renaming templates in the template registry.
var Rename = &cli.Command{
Hidden: true,
Use: "rename <old-template-tag> <new-template-tag>",
Short: "Rename a project template",
Run: func(c *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"old-template-tag", validate.UnixPath},
{"new-template-tag", validate.UnixPath},
{Name: "old-template-tag", Validate: validate.UnixPath},
{Name: "new-template-tag", Validate: validate.UnixPath},
})

MustValidateTemplateDir()
Expand All @@ -50,7 +42,7 @@ var Rename = &cli.Command{
exit.Fatal(fmt.Errorf("rename: %s", err))
}

if err := renameTemplate(tmplPath, newTmplPath); err != nil {
if err := os.Rename(tmplPath, newTmplPath); err != nil {
exit.Error(fmt.Errorf("rename: %s", err))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var Save = &cli.Command{
Short: "Save a local project template to template registry",
Run: func(c *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"template-path", validate.UnixPath},
{"template-tag", validate.AlphanumericExt},
{Name: "template-path", Validate: validate.UnixPath},
{Name: "template-tag", Validate: validate.AlphanumericExt},
})

MustValidateTemplateDir()
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ func TemplateInRegistry(name string) (bool, error) {
return ok, nil
}

// TODO add --use-cache flag to execute a template from previous answers to prompts
// Use contains the cli-command for using templates located in the local template registry.
// TODO add --use-cache flag to execute a template from previous answers to prompts
var Use = &cli.Command{
Use: "use <template-tag> <target-dir>",
Short: "Execute a project template in the given directory",
Run: func(cmd *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"template-tag", validate.UnixPath},
{"target-dir", validate.UnixPath},
{Name: "template-tag", Validate: validate.UnixPath},
{Name: "target-dir", Validate: validate.UnixPath},
})

MustValidateTemplateDir()
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cmd
import (
"errors"

cli "github.com/spf13/cobra"
"github.com/Ilyes512/boilr/pkg/util/exit"
"github.com/Ilyes512/boilr/pkg/util/validate"
cli "github.com/spf13/cobra"
)

var (
Expand All @@ -19,7 +19,7 @@ var Validate = &cli.Command{
Short: "Validate a local project template",
Run: func(_ *cli.Command, args []string) {
MustValidateArgs(args, []validate.Argument{
{"template-path", validate.UnixPath},
{Name: "template-path", Validate: validate.UnixPath},
})

templatePath := args[0]
Expand Down
6 changes: 2 additions & 4 deletions pkg/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import (

type templateFunc func() interface{}

// Interface for prompts.
type Interface interface {
// PromptMessage returns a proper prompt message for the given field with the given default value.
PromptMessage(string) string
EvaluateChoice(string) (interface{}, error)
}

type Chain struct {
Prompts []Interface
}

type strPrompt string

func (p strPrompt) PromptMessage(name string) string {
Expand Down Expand Up @@ -86,6 +83,7 @@ func (p multipleChoicePrompt) EvaluateChoice(c string) (interface{}, error) {
return p[0], nil
}

// Func creates template functions for prompts.
// TODO add deep pretty printer
// TODO handle TOML
func Func(defval interface{}) Interface {
Expand Down
1 change: 1 addition & 0 deletions pkg/util/tlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
// Level is a 16-bit set holding the enabled log levels.
type Level uint16

// All available error levels.
const (
LevelDebug = 1 << 5
LevelFatal = 1 << 4
Expand Down

0 comments on commit fd7ae9f

Please sign in to comment.