template / commit
Starting development on extras project: provide a way to pass in more properties by way of a YAML file. This will allow further templating of content.
main.go | 36 ++++++++++++++++++++++++++++++------ postscript.go | 12 +++++++----- templates/extras-template.yaml | 2 ++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index 4276b22..268b389 100644 --- a/main.go +++ b/main.go @@ -11,14 +11,16 @@ import ( ) func main() { - configFilePath := getFullPath("~/.template.yaml") var profileName string var projectName string + var configFilePath string + var extrasFilePath string app := &cli.App{ Name: "template", Usage: "create file or directory from a template", EnableBashCompletion: true, + Suggest: true, Flags: []cli.Flag{ &cli.StringFlag{ Name: "profile", @@ -37,27 +39,47 @@ func main() { Value: "", Destination: &projectName, }, + &cli.PathFlag{ + Name: "config-yaml", + Aliases: []string{"c"}, + Usage: "path to the config yaml file", + Value: "~/.template.yaml", + Destination: &configFilePath, + }, + &cli.PathFlag{ + Name: "extras-yaml", + Aliases: []string{"e"}, + Usage: "path to the extras yaml file", + Value: "~/.template-extras.yaml", + Destination: &extrasFilePath, + }, }, Action: func(context *cli.Context) error { + + fullConfigPath, err := getFullPath(configFilePath) + if err != nil { + log.Fatal(err) + } + // try and load config - config, err := loadConfig(configFilePath) + config, err := loadConfig(fullConfigPath) if err != nil { - fmt.Printf("No config present at '%v', creating and using sample config\n", configFilePath) + fmt.Printf("No config present at '%v', creating and using sample config\n", fullConfigPath) // create config and save - err := saveConfig(configFilePath, defaultConfig()) + err := saveConfig(fullConfigPath, defaultConfig()) if err != nil { return fmt.Errorf("error creating config: %v", err) } // load config - config, err = loadConfig(configFilePath) + config, err = loadConfig(fullConfigPath) if err != nil { return fmt.Errorf("error loading config: %v", err) } } else { // log successful load - fmt.Printf("Config loaded from '%v'\n", configFilePath) + fmt.Printf("Config loaded from '%v'\n", fullConfigPath) } // validate config @@ -68,6 +90,8 @@ func main() { // read args args := context.Args() + fmt.Println("args:", args) + args.Get(0) // get profile name from args // if not set explicitly, use first arg, if present diff --git a/postscript.go b/postscript.go index def2ccb..dfc2024 100644 --- a/postscript.go +++ b/postscript.go @@ -6,11 +6,12 @@ import ( ) type PostScriptPatternData struct { - Name string - Path string + Name string + Path string + Extras map[string]string } -func createPostScriptArrays(profile Profile, newName string, fullPath string) ([]string, error) { +func createPostScriptArrays(profile Profile, newName string, fullPath string, extras map[string]string) ([]string, error) { array := make([]string, 0) if profile.PostScripts == nil || len(profile.PostScripts) == 0 { @@ -18,8 +19,9 @@ func createPostScriptArrays(profile Profile, newName string, fullPath string) ([ } patternData := PostScriptPatternData{ - Name: newName, - Path: fullPath, + Name: newName, + Path: fullPath, + Extras: extras, } for _, postScriptPattern := range profile.PostScripts { diff --git a/templates/extras-template.yaml b/templates/extras-template.yaml new file mode 100644 index 0000000..b63838a --- /dev/null +++ b/templates/extras-template.yaml @@ -0,0 +1,2 @@ +value1: "1" +value2: "two"