Skip to content
Snippets Groups Projects
Commit 975c8aa5 authored by Nicola Jordan's avatar Nicola Jordan
Browse files

fixed staticchecker and linting errors, removed unused code

parent f8679957
No related branches found
No related tags found
No related merge requests found
......@@ -28,3 +28,10 @@ boilr
# IDEs related files
.idea
# generally exclude hidden files/directories
.*
# generated files while running ci locally
coverage.out
*report.json
......@@ -25,7 +25,8 @@ require (
github.com/xanzy/ssh-agent v0.2.1 // indirect
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.8.0
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
......@@ -57,6 +57,7 @@ func TemplatePath(name string) (string, error) {
return filepath.Join(Configuration.TemplateDirPath, name), nil
}
// IsTemplateDirInitialized returns existential status (boolean) of the template directory
func IsTemplateDirInitialized() (bool, error) {
return osutil.DirExists(Configuration.TemplateDirPath)
}
......
......@@ -7,7 +7,3 @@ import cli "github.com/spf13/cobra"
func GetBoolFlag(c *cli.Command, name string) bool {
return c.PersistentFlags().Lookup(name).Value.String() == "true"
}
func GetStringFlag(c *cli.Command, name string) string {
return c.PersistentFlags().Lookup(name).Value.String()
}
......@@ -47,6 +47,6 @@ func MustValidateTemplateDir() {
}
if !isInitialized {
exit.Error(fmt.Errorf("Template registry is not initialized. Please run `init` command to initialize it."))
exit.Error(fmt.Errorf("template registry is not initialized. Please run `init` command to initialize it"))
}
}
......@@ -37,7 +37,7 @@ var Rename = &cli.Command{
if ok, err := TemplateInRegistry(tmplName); err != nil {
exit.Fatal(fmt.Errorf("rename: %s", err))
} else if !ok {
exit.Fatal(fmt.Errorf("Template %q couldn't be found in the template registry", tmplName))
exit.Fatal(fmt.Errorf("template %q couldn't be found in the template registry", tmplName))
}
tmplPath, err := boilr.TemplatePath(tmplName)
......
......@@ -26,8 +26,8 @@ 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",
......@@ -51,7 +51,7 @@ var Use = &cli.Command{
}
if !templateFound {
exit.Fatal(fmt.Errorf("Template %q couldn't be found in the template registry", tmplName))
exit.Fatal(fmt.Errorf("template %q couldn't be found in the template registry", tmplName))
}
tmplPath, err := boilr.TemplatePath(tmplName)
......
......@@ -14,8 +14,6 @@ func TestUseExecutesProjectTemplate(t *testing.T) {
tmpDirPath, err := ioutil.TempDir("", "template-test")
if err != nil {
t.Fatalf("ioutil.TempDir() got error -> %v", err)
} else {
//defer os.RemoveAll(tmpDirPath)
}
if err := os.MkdirAll(filepath.Join(tmpDirPath, "input", "{{Name}}", "{{Date}}"), 0744); err != nil {
......
......@@ -10,18 +10,13 @@ import (
"github.com/Wattpad/boilr/pkg/util/tlog"
)
type templateFunc func() interface{}
// Interface contains the messages and choices from the user prompt
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 {
......@@ -86,6 +81,7 @@ func (p multipleChoicePrompt) EvaluateChoice(c string) (interface{}, error) {
return p[0], nil
}
// Func creates the appropriate prompts types
// TODO add deep pretty printer
// TODO handle TOML
func Func(defval interface{}) Interface {
......@@ -94,7 +90,7 @@ func Func(defval interface{}) Interface {
return boolPrompt(defval)
case []interface{}:
if len(defval) == 0 {
tlog.Warn(fmt.Sprintf("empty list of choices"))
tlog.Warn("empty list of choices")
return nil
}
......
......@@ -49,7 +49,7 @@ func TestNewBooleanPromptFunc(t *testing.T) {
expectedPromptMsg := "Please choose a value for \"fieldName\""
if msg != expectedPromptMsg {
t.Errorf("boolPrompt(%q).PromptMessage(%q) expected %q got %q", defval, name, expectedPromptMsg, msg)
t.Errorf("boolPrompt(%t).PromptMessage(%q) expected %q got %q", defval, name, expectedPromptMsg, msg)
}
choiceCases := []struct {
......@@ -73,7 +73,7 @@ func TestNewBooleanPromptFunc(t *testing.T) {
for _, c := range choiceCases {
val, err := boolPrompt.EvaluateChoice(c.choice)
if err != nil {
t.Errorf("boolPrompt(%q).EvaluateChoice(%q) got error %q", defval, c.choice, err)
t.Errorf("boolPrompt(%t).EvaluateChoice(%q) got error %q", defval, c.choice, err)
continue
}
......
......@@ -9,6 +9,8 @@ import (
"strings"
"text/template"
"time"
"golang.org/x/text/cases"
)
var (
......@@ -87,7 +89,7 @@ var (
"toLower": strings.ToLower,
"toUpper": strings.ToUpper,
"toTitle": strings.ToTitle,
"title": strings.Title,
"title": cases.Title,
"trimSpace": strings.TrimSpace,
"trimPrefix": strings.TrimPrefix,
......
......@@ -17,7 +17,7 @@ type Metadata struct {
// String returns the string slice form of Metadata.
func (m Metadata) String() []string {
tDelta := time.Now().Sub(time.Time(m.Created))
tDelta := time.Since(time.Time(m.Created))
return []string{m.Tag, m.Repository, units.HumanDuration(tDelta) + " ago"}
}
......@@ -55,5 +55,5 @@ func (t *JSONTime) UnmarshalJSON(b []byte) error {
// String returns the string form of JSONTime.
func (t JSONTime) String() string {
return fmt.Sprintf("%s", time.Time(t).Format(timeFormat))
return time.Time(t).Format(timeFormat)
}
......@@ -40,7 +40,7 @@ func Get(path string) (Interface, error) {
}
// TODO make context optional
ctxt, err := func(fname string) (map[string]interface{}, error) {
ctxt, _ := func(fname string) (map[string]interface{}, error) {
f, err := os.Open(fname)
if err != nil {
if os.IsNotExist(err) {
......@@ -101,7 +101,6 @@ type dirTemplate struct {
FuncMap template.FuncMap
Metadata Metadata
alignment string
ShouldUseDefaults bool
}
......
......@@ -37,11 +37,17 @@ var (
type Level uint16
const (
LevelDebug = 1 << 5
LevelFatal = 1 << 4
LevelWarn = 1 << 3
LevelError = 1 << 2
LevelInfo = 1 << 1
// LevelDebug is the debug log level
LevelDebug = 1 << 5
// LevelFatal is the fatal log level
LevelFatal = 1 << 4
// LevelWarn is the warn log level
LevelWarn = 1 << 3
// LevelError is the error log level
LevelError = 1 << 2
// LevelInfo is the info log level
LevelInfo = 1 << 1
// LevelSuccess is the success log level
LevelSuccess = 1 << 0
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment