-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from suntong/reconstruct
Reconstruct
- Loading branch information
Showing
11 changed files
with
289 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.