Skip to content
Snippets Groups Projects
Commit e1a0702c authored by Tamer Tas's avatar Tamer Tas
Browse files

Fix nits with execution

parent 6193026a
No related branches found
No related tags found
No related merge requests found
......@@ -152,7 +152,8 @@ func newSlice(name string, choices []string) func() interface{} {
}
}
// New returns a prompt closure when executed asks for user input and returns result.
// New returns a prompt closure when executed asks for
// user input and has a default value that returns result.
func New(name string, defval interface{}) func() interface{} {
// TODO use reflect package
switch defval := defval.(type) {
......
......@@ -8,6 +8,7 @@ import (
"path/filepath"
"github.com/tmrts/tmplt/pkg/util/exit"
"github.com/tmrts/tmplt/pkg/util/osutil"
)
const (
......@@ -34,6 +35,7 @@ func TemplatePath(name string) (string, error) {
func init() {
homeDir := os.Getenv("HOME")
if homeDir == "" {
// FIXME is this really necessary?
exit.Error(fmt.Errorf("environment variable ${HOME} should be set"))
}
......@@ -42,6 +44,17 @@ func init() {
// Read .config/tmplt/config.json if exists
// TODO use defaults if config.json doesn't exist
hasConfig, err := osutil.FileExists(Configuration.FilePath)
if err != nil {
exit.Error(err)
}
if !hasConfig {
// TODO report the absence of config.json
//tlog.Debug("Couldn't find %s user configuration", ConfigFileName)
return
}
buf, err := ioutil.ReadFile(Configuration.FilePath)
if err != nil {
exit.Error(err)
......
......@@ -25,6 +25,12 @@ func Error(err error) {
os.Exit(CodeError)
}
func GoodEnough(fmtStr string, s ...interface{}) {
tlog.Debug(fmt.Sprintf(fmtStr, s...))
os.Exit(CodeOK)
}
func OK(fmtStr string, s ...interface{}) {
tlog.Success(fmt.Sprintf(fmtStr, s...))
......
......@@ -25,6 +25,7 @@ func coloredPrintMsg(icon string, msg string, iC color.Attribute, mC color.Attri
color.New(color.Bold, iC).SprintFunc()(msg))
}
// TODO add log levels
func Debug(msg string) {
coloredPrintMsg(DebugMark, msg, color.FgYellow, color.FgYellow)
}
......
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