diff --git a/cmd/easygen/main.go b/cmd/easygen/main.go new file mode 100644 index 0000000..f69c55b --- /dev/null +++ b/cmd/easygen/main.go @@ -0,0 +1,94 @@ +//////////////////////////////////////////////////////////////////////////// +// Porgram: EasyGen +// Purpose: Easy to use universal code/text generator +// Authors: Tong Sun (c) 2015, All rights reserved +//////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////// +// Program start + +package main + +import ( + "flag" + "fmt" + "os" +) + +import ( + "github.com/suntong/easygen" +) + +//////////////////////////////////////////////////////////////////////////// +// Constant and data type/structure definitions + +//////////////////////////////////////////////////////////////////////////// +// Global variables definitions + +//////////////////////////////////////////////////////////////////////////// +// Commandline definitions + +func init() { + + // set default values for command line parameters + flag.BoolVar(&easygen.Opts.HTML, "html", false, + "treat the template file as html instead of text") + flag.StringVar(&easygen.Opts.TemplateStr, "ts", "", + "template string (in text)") + flag.StringVar(&easygen.Opts.TemplateFile, "tf", "", + ".tmpl template file `name` (default: same as .yaml file)") + flag.StringVar(&easygen.Opts.ExtYaml, "ey", ".yaml", + "`extension` of yaml file") + flag.StringVar(&easygen.Opts.ExtTmpl, "et", ".tmpl", + "`extension` of template file") + flag.StringVar(&easygen.Opts.StrFrom, "rf", "", + "replace from, the from string used for the replace function") + flag.StringVar(&easygen.Opts.StrTo, "rt", "", + "replace to, the to string used for the replace function") + flag.IntVar(&easygen.Opts.Debug, "debug", 0, + "debugging `level`") + + // Now override those default values from environment variables + if len(easygen.Opts.TemplateStr) == 0 || + len(os.Getenv("EASYGEN_TS")) != 0 { + easygen.Opts.TemplateStr = os.Getenv("EASYGEN_TS") + } + if len(easygen.Opts.TemplateFile) == 0 || + len(os.Getenv("EASYGEN_TF")) != 0 { + easygen.Opts.TemplateFile = os.Getenv("EASYGEN_TF") + } + if len(easygen.Opts.ExtYaml) == 0 || + len(os.Getenv("EASYGEN_EY")) != 0 { + easygen.Opts.ExtYaml = os.Getenv("EASYGEN_EY") + } + if len(easygen.Opts.ExtTmpl) == 0 || + len(os.Getenv("EASYGEN_ET")) != 0 { + easygen.Opts.ExtTmpl = os.Getenv("EASYGEN_ET") + } + if len(easygen.Opts.StrFrom) == 0 || + len(os.Getenv("EASYGEN_RF")) != 0 { + easygen.Opts.StrFrom = os.Getenv("EASYGEN_RF") + } + if len(easygen.Opts.StrTo) == 0 || + len(os.Getenv("EASYGEN_RT")) != 0 { + easygen.Opts.StrTo = os.Getenv("EASYGEN_RT") + } + +} + +//////////////////////////////////////////////////////////////////////////// +// Main + +func main() { + flag.Usage = easygen.Usage + flag.Parse() + + // One mandatory non-flag arguments + if len(flag.Args()) < 1 { + easygen.Usage() + } + fileName := flag.Args()[0] + easygen.TFStringsInit() + + fmt.Print(easygen.Generate(easygen.Opts.HTML, fileName)) +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..bb0701a --- /dev/null +++ b/config.go @@ -0,0 +1,48 @@ +// !!! !!! +// WARNING: Code automatically generated. Editing discouraged. +// !!! !!! + +package easygen + +import ( + "flag" + "fmt" + "os" +) + +//////////////////////////////////////////////////////////////////////////// +// Constant and data type/structure definitions + +const progname = "easygen" // os.Args[0] + +// The Options struct defines the structure to hold the commandline values +type Options struct { + HTML bool // treat the template file as html instead of text + TemplateStr string // template string (in text) + TemplateFile string // .tmpl template file `name` (default: same as .yaml file) + ExtYaml string // `extension` of yaml file + ExtTmpl string // `extension` of template file + StrFrom string // replace from, the from string used for the replace function + StrTo string // replace to, the to string used for the replace function + Debug int // debugging `level` +} + +//////////////////////////////////////////////////////////////////////////// +// Global variables definitions + +// Opts holds the actual values from the command line parameters +var Opts = Options{ExtYaml: ".yaml", ExtTmpl: ".tmpl"} + +//////////////////////////////////////////////////////////////////////////// +// Commandline definitions + +// Usage function shows help on commandline usage +func Usage() { + fmt.Fprintf(os.Stderr, + "\nUsage:\n %s [flags] YamlFileName\n\nFlags:\n\n", + progname) + flag.PrintDefaults() + fmt.Fprintf(os.Stderr, + "\nYamlFileName: The name for the .yaml data and .tmpl template file\n\tOnly the name part, without extension. Can include the path as well.\n") + os.Exit(0) +} diff --git a/easygen.go b/easygen.go index 433e591..af30c27 100644 --- a/easygen.go +++ b/easygen.go @@ -7,37 +7,138 @@ //////////////////////////////////////////////////////////////////////////// // Program start -package main +package easygen import ( - "flag" + "bytes" "fmt" + ht "html/template" + "io" + "io/ioutil" + "os" + "path/filepath" + "strings" + tt "text/template" - "github.com/suntong/easygen/easygenapi" + "gopkg.in/yaml.v2" ) //////////////////////////////////////////////////////////////////////////// // Constant and data type/structure definitions +// common type for a *(text|html).Template value +type template interface { + Execute(wr io.Writer, data interface{}) error + ExecuteTemplate(wr io.Writer, name string, data interface{}) error + Name() string +} + //////////////////////////////////////////////////////////////////////////// // Global variables definitions //////////////////////////////////////////////////////////////////////////// -// Commandline definitions +// Function definitions -//////////////////////////////////////////////////////////////////////////// -// Main +// Generate2 will produce output according to the given template and driving data files +func Generate2(HTML bool, fileNameTempl string, fileName string) string { + Opts.TemplateFile = fileNameTempl + ret := Generate(HTML, fileName) + Opts.TemplateFile = "" + return ret +} + +// Generate0 will produce output according from driving data without a template file +func Generate0(HTML bool, strTempl string, fileName string) string { + Opts.TemplateStr = strTempl + ret := Generate(HTML, fileName) + Opts.TemplateStr = "" + return ret +} + +// Generate will produce output from the template according to driving data +func Generate(HTML bool, fileName string) string { + source, err := ioutil.ReadFile(fileName + Opts.ExtYaml) + checkError(err) -func main() { - flag.Usage = easygenapi.Usage - flag.Parse() + m := make(map[interface{}]interface{}) - // One mandatory non-flag arguments - if len(flag.Args()) < 1 { - easygenapi.Usage() + err = yaml.Unmarshal(source, &m) + checkError(err) + + // template file name + fileNameT := fileName + if len(Opts.TemplateFile) > 0 { + fileNameT = Opts.TemplateFile } - fileName := flag.Args()[0] - easygenapi.TFStringsInit() - fmt.Print(easygenapi.Generate(easygenapi.Opts.HTML, fileName)) + t, err := parseFiles(HTML, fileNameT+Opts.ExtTmpl) + checkError(err) + + buf := new(bytes.Buffer) + err = t.Execute(buf, m) + checkError(err) + + return buf.String() +} + +// parseFiles, initialization. By Matt Harden @gmail.com +func parseFiles(HTML bool, filenames ...string) (template, error) { + tname := filepath.Base(filenames[0]) + + // use text template + funcMapHT := ht.FuncMap{ + "minus1": minus1, + "cls2lc": cls2lc.String, + "cls2uc": cls2uc.String, + "cls2ss": cls2ss.String, + "ck2lc": ck2lc.String, + "ck2uc": ck2uc.String, + "ck2ls": ck2ls.String, + "ck2ss": ck2ss.String, + "clc2ss": clc2ss.String, + "cuc2ss": cuc2ss.String, + } + + _ = funcMapHT + + if HTML { + // use html template + t, err := ht.ParseFiles(filenames...) + //t, err := ht.New("HT").Funcs(funcMapHT).ParseFiles(filenames...) + return t, err + } + + // use text template + funcMap := tt.FuncMap{ + "eqf": strings.EqualFold, + "split": strings.Fields, + "minus1": minus1, + "replace": replace, + "replacec": replacec, + "cls2lc": cls2lc.String, + "cls2uc": cls2uc.String, + "cls2ss": cls2ss.String, + "ck2lc": ck2lc.String, + "ck2uc": ck2uc.String, + "ck2ls": ck2ls.String, + "ck2ss": ck2ss.String, + "clc2ss": clc2ss.String, + "cuc2ss": cuc2ss.String, + } + + if len(Opts.TemplateStr) > 0 { + t, err := tt.New("TT").Funcs(funcMap).Parse(Opts.TemplateStr) + return t, err + } + + t, err := tt.New(tname).Funcs(funcMap).ParseFiles(filenames...) + return t, err +} + +// Exit if error occurs +func checkError(err error) { + if err != nil { + fmt.Printf("[%s] Fatal error - %v", progname, err.Error()) + os.Exit(1) + } } diff --git a/easygen_test.go b/easygen_test.go index e319257..24ce32e 100644 --- a/easygen_test.go +++ b/easygen_test.go @@ -1,10 +1,10 @@ -package main +package easygen import ( "fmt" "testing" - "github.com/suntong/easygen/easygenapi" + "github.com/suntong/easygen" ) //////////////////////////////////////////////////////////////////////////// @@ -16,7 +16,7 @@ import ( func TestList0(t *testing.T) { t.Log("First and plainest list test") const await = "The colors are: red, blue, white, .\n" - if got := easygenapi.Generate(false, "test/list0"); got != await { + if got := easygen.Generate(false, "test/list0"); got != await { t.Errorf("Mismatch:, got '%s' instead", got) } } @@ -27,7 +27,7 @@ func TestList0(t *testing.T) { func TestList1Text(t *testing.T) { t.Log("Second test, with text template") const await = "The quoted colors are: \"red\", \"blue\", \"white\", .\n" - if got := easygenapi.Generate(false, "test/list1"); got != await { + if got := easygen.Generate(false, "test/list1"); got != await { t.Errorf("Mismatch:, got '%s' instead", got) } } @@ -35,7 +35,7 @@ func TestList1Text(t *testing.T) { func TestList1HTML(t *testing.T) { t.Log("Second test, with html template") const await = "The quoted colors are: "red", "blue", "white", .\n" - if got := easygenapi.Generate(true, "test/list1"); got != await { + if got := easygen.Generate(true, "test/list1"); got != await { t.Errorf("Mismatch:, got '%s' instead", got) } } @@ -46,13 +46,13 @@ func TestList1HTML(t *testing.T) { func TestListFunc1(t *testing.T) { t.Log("Test custom template function - minus1") const await = "red, blue, white.\n" - if got := easygenapi.Generate(false, "test/listfunc1"); got != await { + if got := easygen.Generate(false, "test/listfunc1"); got != await { t.Errorf("Mismatch:, got '%s' instead", got) } } func ExampleFunc1() { - fmt.Print(easygenapi.Generate(false, "test/listfunc1")) + fmt.Print(easygen.Generate(false, "test/listfunc1")) // Output: // red, blue, white. } @@ -61,7 +61,7 @@ func ExampleFunc1() { // list0 data + listfunc1 template // I.e.: EasyGen -tf test/listfunc1 test/list0 func ExampleList0Func1() { - fmt.Print(easygenapi.Generate2(false, "test/listfunc1", "test/list0")) + fmt.Print(easygen.Generate2(false, "test/listfunc1", "test/list0")) // Output: // red, blue, white. } @@ -70,7 +70,7 @@ func ExampleList0Func1() { // list0 data + string template // I.e.: EasyGen -ts "{{range .Colors}}{{.}}, {{end}}" test/list0 func ExampleList0StrTemplate() { - fmt.Print(easygenapi.Generate0(false, "{{range .Colors}}{{.}}, {{end}}", "test/list0")) + fmt.Print(easygen.Generate0(false, "{{range .Colors}}{{.}}, {{end}}", "test/list0")) // Output: // red, blue, white, } @@ -79,7 +79,7 @@ func ExampleList0StrTemplate() { // listfunc2 func ExampleFunc2() { - fmt.Print(easygenapi.Generate(false, "test/listfunc2")) + fmt.Print(easygen.Generate(false, "test/listfunc2")) // Output: // some-init-method 5 5 someInitMethod SomeInitMethod } @@ -89,16 +89,16 @@ func ExampleFunc2() { func ExampleTestExample() { // Ref https://groups.google.com/d/msg/golang-nuts/9jKexxD19Js/xrNAQA1ACnMJ - fmt.Println(` flags.Bool("debug", false, "Turn on debugging.")`) - fmt.Println(` viper.BindPFlag("debug", flags.Lookup("debug"))`) + fmt.Println(` flags.Bool("Debug", false, "Turn on debugging.")`) + fmt.Println(` viper.BindPFlag("Debug", flags.Lookup("Debug"))`) // Output: - // flags.Bool("debug", false, "Turn on debugging.") - // viper.BindPFlag("debug", flags.Lookup("debug")) + // flags.Bool("Debug", false, "Turn on debugging.") + // viper.BindPFlag("Debug", flags.Lookup("Debug")) } func ExampleCommandLineCobraViper() { // EasyGen commandlineCV | sed 's|^\t|&//&|; s|^$|\t//|' - fmt.Print(easygenapi.Generate(false, "test/commandlineCV")) + fmt.Print(easygen.Generate(false, "test/commandlineCV")) // Output: // // flags.Bool("debug", false, "Turn on debugging.") @@ -123,7 +123,7 @@ func ExampleCommandLineCobraViper() { func ExampleCommandLineOptInitFull() { // EasyGen commandlineCVFull | sed 's|^|\t// |;' - fmt.Print(easygenapi.Generate(false, "test/commandlineCVFull")) + fmt.Print(easygen.Generate(false, "test/commandlineCVFull")) // Output: // func init() { // @@ -141,8 +141,8 @@ func ExampleCommandLineOptInitFull() { // // flags := mainCmd.Flags() // - // flags.Bool("debug", false, "Turn on debugging.") - // viper.BindPFlag("debug", flags.Lookup("debug")) + // flags.Bool("Debug", false, "Turn on debugging.") + // viper.BindPFlag("Debug", flags.Lookup("Debug")) // // flags.String("addr", "localhost:5002", "Address of the service.") // viper.BindPFlag("addr", flags.Lookup("addr")) @@ -186,19 +186,19 @@ func ExampleVaribleNames() { // Strings Test func ExampleTestStringsCmp() { - fmt.Print(easygenapi.Generate0(false, `The {{if eq .StrTest "-AB-axxb- HTML Html html"}}eq says Yea{{else}}eq says Nay{{end}} but {{if eqf .StrTest "-AB-axxb- HTML Html html"}}eqf says Yea{{else}}eqf says Nay{{end}}.`, "test/strings0")) + fmt.Print(easygen.Generate0(false, `The {{if eq .StrTest "-AB-axxb- HTML Html html"}}eq says Yea{{else}}eq says Nay{{end}} but {{if eqf .StrTest "-AB-axxb- HTML Html html"}}eqf says Yea{{else}}eqf says Nay{{end}}.`, "test/strings0")) // Output: // The eq says Nay but eqf says Yea. } func ExampleTestStringSplit0() { - fmt.Print(easygenapi.Generate0(false, `{{split .Colorlist}}`, "test/list0")) + fmt.Print(easygen.Generate0(false, `{{split .Colorlist}}`, "test/list0")) // Output: // [red blue white] } func ExampleTestStringSplit1() { - fmt.Print(easygenapi.Generate0(false, `{{range (split .Colorlist)}}{{.}} {{end}}`, "test/list0")) + fmt.Print(easygen.Generate0(false, `{{range (split .Colorlist)}}{{.}} {{end}}`, "test/list0")) // Output: // red blue white } @@ -220,11 +220,11 @@ $ EASYGEN_RF="HTML" EASYGEN_RT='XML' easygen -ts="{{.StrTest}}, {{replacec .StrT /* func ExampleTestStrings() { // panic: runtime error: invalid memory address or nil pointer dereference [recovered] - easygenapi.Opts.StrFrom = "a(x*)b" - easygenapi.Opts.StrTo = "${1}W" - //fmt.Print(easygenapi.Generate0(false, "{{.StrTest}} {{replace .StrTest}} {{.StrTest | replace}}", "test/strings0")) - easygenapi.Opts.TemplateStr = `{{.StrTest}} {{replace .StrTest}} {{.StrTest | replace}}` - fmt.Print(easygenapi.Generate(false, "test/strings0")) + easygen.Opts.StrFrom = "a(x*)b" + easygen.Opts.StrTo = "${1}W" + //fmt.Print(easygen.Generate0(false, "{{.StrTest}} {{replace .StrTest}} {{.StrTest | replace}}", "test/strings0")) + easygen.Opts.TemplateStr = `{{.StrTest}} {{replace .StrTest}} {{.StrTest | replace}}` + fmt.Print(easygen.Generate(false, "test/strings0")) // Output: // -ab-axxb- HTML Html html -W-xxW- HTML Html html -W-xxW- HTML Html html } diff --git a/easygenapi/config.go b/easygenapi/config.go deleted file mode 100644 index 9bcfd33..0000000 --- a/easygenapi/config.go +++ /dev/null @@ -1,96 +0,0 @@ -// !!! !!! -// WARNING: Code automatically generated. Editing discouraged. -// !!! !!! - -package easygenapi - -import ( - "flag" - "fmt" - "os" -) - -//////////////////////////////////////////////////////////////////////////// -// Constant and data type/structure definitions - -const progname = "easygen" // os.Args[0] - -// The Options struct defines the structure to hold the commandline values -type Options struct { - HTML bool // treat the template file as html instead of text - TemplateStr string // template string (in text) - TemplateFile string // .tmpl template file `name` (default: same as .yaml file) - ExtYaml string // `extension` of yaml file - ExtTmpl string // `extension` of template file - StrFrom string // replace from, the from string used for the replace function - StrTo string // replace to, the to string used for the replace function - debug int // debugging `level` -} - -//////////////////////////////////////////////////////////////////////////// -// Global variables definitions - -// Opts holds the actual values from the command line parameters -var Opts Options - -//////////////////////////////////////////////////////////////////////////// -// Commandline definitions - -func init() { - - // set default values for command line parameters - flag.BoolVar(&Opts.HTML, "html", false, - "treat the template file as html instead of text") - flag.StringVar(&Opts.TemplateStr, "ts", "", - "template string (in text)") - flag.StringVar(&Opts.TemplateFile, "tf", "", - ".tmpl template file `name` (default: same as .yaml file)") - flag.StringVar(&Opts.ExtYaml, "ey", ".yaml", - "`extension` of yaml file") - flag.StringVar(&Opts.ExtTmpl, "et", ".tmpl", - "`extension` of template file") - flag.StringVar(&Opts.StrFrom, "rf", "", - "replace from, the from string used for the replace function") - flag.StringVar(&Opts.StrTo, "rt", "", - "replace to, the to string used for the replace function") - flag.IntVar(&Opts.debug, "debug", 0, - "debugging `level`") - - // Now override those default values from environment variables - if len(Opts.TemplateStr) == 0 || - len(os.Getenv("EASYGEN_TS")) != 0 { - Opts.TemplateStr = os.Getenv("EASYGEN_TS") - } - if len(Opts.TemplateFile) == 0 || - len(os.Getenv("EASYGEN_TF")) != 0 { - Opts.TemplateFile = os.Getenv("EASYGEN_TF") - } - if len(Opts.ExtYaml) == 0 || - len(os.Getenv("EASYGEN_EY")) != 0 { - Opts.ExtYaml = os.Getenv("EASYGEN_EY") - } - if len(Opts.ExtTmpl) == 0 || - len(os.Getenv("EASYGEN_ET")) != 0 { - Opts.ExtTmpl = os.Getenv("EASYGEN_ET") - } - if len(Opts.StrFrom) == 0 || - len(os.Getenv("EASYGEN_RF")) != 0 { - Opts.StrFrom = os.Getenv("EASYGEN_RF") - } - if len(Opts.StrTo) == 0 || - len(os.Getenv("EASYGEN_RT")) != 0 { - Opts.StrTo = os.Getenv("EASYGEN_RT") - } - -} - -// Usage function shows help on commandline usage -func Usage() { - fmt.Fprintf(os.Stderr, - "\nUsage:\n %s [flags] YamlFileName\n\nFlags:\n\n", - progname) - flag.PrintDefaults() - fmt.Fprintf(os.Stderr, - "\nYamlFileName: The name for the .yaml data and .tmpl template file\n\tOnly the name part, without extension. Can include the path as well.\n") - os.Exit(0) -} diff --git a/easygenapi/easygenapi.go b/easygenapi/easygenapi.go deleted file mode 100644 index ac8a241..0000000 --- a/easygenapi/easygenapi.go +++ /dev/null @@ -1,144 +0,0 @@ -//////////////////////////////////////////////////////////////////////////// -// Porgram: EasyGen -// Purpose: Easy to use universal code/text generator -// Authors: Tong Sun (c) 2015, All rights reserved -//////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////// -// Program start - -package easygenapi - -import ( - "bytes" - "fmt" - ht "html/template" - "io" - "io/ioutil" - "os" - "path/filepath" - "strings" - tt "text/template" - - "gopkg.in/yaml.v2" -) - -//////////////////////////////////////////////////////////////////////////// -// Constant and data type/structure definitions - -// common type for a *(text|html).Template value -type template interface { - Execute(wr io.Writer, data interface{}) error - ExecuteTemplate(wr io.Writer, name string, data interface{}) error - Name() string -} - -//////////////////////////////////////////////////////////////////////////// -// Global variables definitions - -//////////////////////////////////////////////////////////////////////////// -// Function definitions - -// Generate2 will produce output according to the given template and driving data files -func Generate2(HTML bool, fileNameTempl string, fileName string) string { - Opts.TemplateFile = fileNameTempl - ret := Generate(HTML, fileName) - Opts.TemplateFile = "" - return ret -} - -// Generate0 will produce output according from driving data without a template file -func Generate0(HTML bool, strTempl string, fileName string) string { - Opts.TemplateStr = strTempl - ret := Generate(HTML, fileName) - Opts.TemplateStr = "" - return ret -} - -// Generate will produce output from the template according to driving data -func Generate(HTML bool, fileName string) string { - source, err := ioutil.ReadFile(fileName + Opts.ExtYaml) - checkError(err) - - m := make(map[interface{}]interface{}) - - err = yaml.Unmarshal(source, &m) - checkError(err) - - // template file name - fileNameT := fileName - if len(Opts.TemplateFile) > 0 { - fileNameT = Opts.TemplateFile - } - - t, err := parseFiles(HTML, fileNameT+Opts.ExtTmpl) - checkError(err) - - buf := new(bytes.Buffer) - err = t.Execute(buf, m) - checkError(err) - - return buf.String() -} - -// parseFiles, initialization. By Matt Harden @gmail.com -func parseFiles(HTML bool, filenames ...string) (template, error) { - tname := filepath.Base(filenames[0]) - - // use text template - funcMapHT := ht.FuncMap{ - "minus1": minus1, - "cls2lc": cls2lc.String, - "cls2uc": cls2uc.String, - "cls2ss": cls2ss.String, - "ck2lc": ck2lc.String, - "ck2uc": ck2uc.String, - "ck2ls": ck2ls.String, - "ck2ss": ck2ss.String, - "clc2ss": clc2ss.String, - "cuc2ss": cuc2ss.String, - } - - _ = funcMapHT - - if HTML { - // use html template - t, err := ht.ParseFiles(filenames...) - //t, err := ht.New("HT").Funcs(funcMapHT).ParseFiles(filenames...) - return t, err - } - - // use text template - funcMap := tt.FuncMap{ - "eqf": strings.EqualFold, - "split": strings.Fields, - "minus1": minus1, - "replace": replace, - "replacec": replacec, - "cls2lc": cls2lc.String, - "cls2uc": cls2uc.String, - "cls2ss": cls2ss.String, - "ck2lc": ck2lc.String, - "ck2uc": ck2uc.String, - "ck2ls": ck2ls.String, - "ck2ss": ck2ss.String, - "clc2ss": clc2ss.String, - "cuc2ss": cuc2ss.String, - } - - if len(Opts.TemplateStr) > 0 { - t, err := tt.New("TT").Funcs(funcMap).Parse(Opts.TemplateStr) - return t, err - } - - t, err := tt.New(tname).Funcs(funcMap).ParseFiles(filenames...) - return t, err -} - -// Exit if error occurs -func checkError(err error) { - if err != nil { - fmt.Printf("[%s] Fatal error - %v", progname, err.Error()) - os.Exit(1) - } -} diff --git a/test/commandlineCVFull.yaml b/test/commandlineCVFull.yaml index 6914b4a..2db0921 100644 --- a/test/commandlineCVFull.yaml +++ b/test/commandlineCVFull.yaml @@ -2,7 +2,7 @@ CmdMain: mainCmd CmdPrefix: DISPATCH Options: - - Name: debug + - Name: Debug Type: Bool Value: false Usage: Turn on debugging. diff --git a/test/commandlineFlag.yaml b/test/commandlineFlag.yaml index 4e0a698..5884c92 100644 --- a/test/commandlineFlag.yaml +++ b/test/commandlineFlag.yaml @@ -62,7 +62,7 @@ Options: Value: '""' Usage: "replace to, the to string used for the replace function" - - Name: debug + - Name: Debug Type: int Flag: debug Value: 0 diff --git a/easygenapi/tf-minus1.go b/tf-minus1.go similarity index 93% rename from easygenapi/tf-minus1.go rename to tf-minus1.go index beeb59a..67160bc 100644 --- a/easygenapi/tf-minus1.go +++ b/tf-minus1.go @@ -1,4 +1,4 @@ -package easygenapi +package easygen //========================================================================== // template function diff --git a/easygenapi/tf-strings.go b/tf-strings.go similarity index 97% rename from easygenapi/tf-strings.go rename to tf-strings.go index 213e9ea..0128b57 100644 --- a/easygenapi/tf-strings.go +++ b/tf-strings.go @@ -1,4 +1,4 @@ -package easygenapi +package easygen import "regexp" diff --git a/easygenapi/tf-varcaser.go b/tf-varcaser.go similarity index 98% rename from easygenapi/tf-varcaser.go rename to tf-varcaser.go index a03df62..31255b6 100644 --- a/easygenapi/tf-varcaser.go +++ b/tf-varcaser.go @@ -1,4 +1,4 @@ -package easygenapi +package easygen import ( "github.com/danverbraganza/varcaser/varcaser"