template / commit
A few small changes:
.vscode/launch.json | 8 +-- config.go | 152 ---------------------------------------------------- default_config.go | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ extras.go | 5 ++ main.go | 2 +- 5 files changed, 157 insertions(+), 157 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index addb872..031cf0a 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -41,7 +41,7 @@ "request": "launch", "mode": "auto", "program": ".", - "args": ["daily", "--default-config"] + "args": ["daily"] }, { "name": "Run: template work", @@ -49,10 +49,10 @@ "request": "launch", "mode": "auto", "program": ".", - "args": ["work", "--default-config"] + "args": ["work"] }, { - "name": "Run: template --profile work --project testProj", + "name": "Run: template --profile work --project testProj --default-config", "type": "go", "request": "launch", "mode": "auto", @@ -71,7 +71,7 @@ "request": "launch", "mode": "auto", "program": ".", - "args": ["note", "whoa", "--default-config"] + "args": ["note", "whoa"] }, { "name": "Run: template test blah", diff --git a/config.go b/config.go index dab0302..8058844 100644 --- a/config.go +++ b/config.go @@ -12,158 +12,6 @@ type Config struct { Profiles []Profile } -func defaultConfig() Config { - return Config{ - Profiles: []Profile{ - { - Name: "daily", - Description: "Creates a MD file in ~/Dropbox/DailyNotes folder in the format YYYY-MM-DD[-vX].md", - Path: "~/Dropbox/DailyNotes", - Type: FileType, - NamePatterns: []string{ - "{{$version := getVersion}}" + - "{{.Year}}-{{.Month}}-{{.Day}}" + - "{{if (gt $version 1)}}v{{$version}}{{end}}" + - ".md", - }, - FileTemplate: `# {{.Year}}-{{.Month}}-{{.Day}} - -Today's notes - -## Todo - -1. [ ] Check email -2. [ ] Check chat -3. [ ] Check calendar -4. [ ] Check yesterday's notes -5. [ ] Have fun! - `, - ScriptShell: "pwsh", - PostScripts: []string{ - "code . \"{{.Path}}\"", - }, - }, - { - Name: "note", - Description: "Creates a MD file in ~/Dropbox/Notes in the format YYYY-MM-DD[-ProjectName][-vVersion].md", - OS: "All", - Path: "~/Dropbox/Notes", - IsDefault: true, - Type: FileType, - NamePatterns: []string{ - "{{$version := getVersion}}" + - "{{.Year}}-{{.Month}}-{{.Day}}" + - "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + - "{{if (gt $version 1)}}n{{$version}}{{end}}" + - ".md", - }, - ScriptShell: "pwsh", - PostScripts: []string{ - "code \"{{.Path}}\"", - }, - }, - { - Name: "blog", - Description: "Creates a MD file in the ~/Dropbox/Blog folder in the format YYYY-MM-DD[-ProjectName][-vVersion].md", - OS: "All", - Path: "~/Dropbox/Blog", - FileTemplatePath: "~/.templates/blog-template.md", - Type: FileType, - NamePatterns: []string{ - "{{$version := getVersion}}" + - "{{.Year}}-{{.Month}}-{{.Day}}" + - "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + - "{{if (gt $version 1)}}v{{$version}}{{end}}" + - ".md", - }, - ScriptShell: "pwsh", - PostScripts: []string{ - "code . \"{{.Name}}\"", - }, - }, - { - Name: "work", - Description: "Creates a folder in the c:/work folder in the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", - OS: "Windows", - Path: "C:/work", - Type: FolderType, - NamePatterns: []string{ - "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}-{{.Second}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - }, - ScriptShell: "pwsh", - PostScripts: []string{ - "explorer \"{{.Path}}\"", - }, - }, - { - Name: "folder", - Description: "Creates a folder in the current folder in the format YYYY-MM-DD[-ProjectName][-vVersion]", - Type: FolderType, - ScriptShell: "pwsh", - PostScripts: []string{}, - NamePatterns: []string{ - "{{$version := getVersion}}" + - "{{.Year}}-{{.Month}}-{{.Day}}" + - "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + - "{{if (gt $version 1)}}-n{{$version}}{{end}}", - }, - }, - { - Name: "create-react-app", - Type: FolderType, - Description: "Creates a folder in the current folder in the format create-react-app[-ProjectName][-vVersion], runs `npx create-react-app` to initialize the folder, and opens the folder in VSCode", - ScriptShell: "pwsh", - NamePatterns: []string{ - "{{$version := getVersion}}" + - "create-react-app" + - "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + - "{{if (gt $version 1)}}-n{{$version}}{{end}}", - }, - PostScripts: []string{ - "npx create-react-app .", - "code .", - }, - }, - { - Name: "git", - Description: "Creates a folder in the c:/code folder in the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", - OS: "Windows", - Path: "C:/code", - Type: FolderType, - NamePatterns: []string{ - "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}-{{.Second}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - }, - ScriptShell: "pwsh", - PostScripts: []string{ - "git init", - "code \"{{.Path}}\"", - }, - }, - { - Name: "test", - Description: "Echoes the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", - Type: ScriptType, - NamePatterns: []string{ - "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", - }, - ScriptShell: "pwsh", - PostScripts: []string{ - "echo \"Name={{.Name}}\"", - "echo \"Path={{.Path}}\"", - "echo \"Value1={{.Extras.value1}}\"", - "echo \"Value2={{.Extras.value2}}\"", - }, - }, - }, - } -} - func validateConfig(config Config) error { if config.Profiles == nil || len(config.Profiles) == 0 { return fmt.Errorf("no profiles found") diff --git a/default_config.go b/default_config.go new file mode 100644 index 0000000..d8d0f0d --- /dev/null +++ b/default_config.go @@ -0,0 +1,147 @@ +package main + +func defaultConfig() Config { + return Config{ + Profiles: []Profile{ + { + Name: "daily", + Description: "Creates a MD file in ~/Dropbox/DailyNotes folder in the format YYYY-MM-DD[-vX].md", + Path: "~/Dropbox/DailyNotes", + Type: FileType, + NamePatterns: []string{"{{.Year}}-{{.Month}}-{{.Day}}.md"}, + FileTemplate: `# {{.Year}}-{{.Month}}-{{.Day}} + +Today's notes + +## Todo + +1. [ ] Check email +2. [ ] Check chat +3. [ ] Check calendar +4. [ ] Check yesterday's notes +5. [ ] Have fun!`, + ScriptShell: "pwsh", + PostScripts: []string{ + "code . \"{{.Path}}\"", + }, + }, + { + Name: "note", + Description: "Creates a MD file in ~/Dropbox/Notes in the format YYYY-MM-DD[-ProjectName][-vVersion].md", + OS: "All", + Path: "~/Dropbox/Notes", + IsDefault: true, + Type: FileType, + NamePatterns: []string{ + "{{$version := getVersion}}" + + "{{.Year}}-{{.Month}}-{{.Day}}" + + "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + + "{{if (gt $version 1)}}n{{$version}}{{end}}" + + ".md", + }, + ScriptShell: "pwsh", + PostScripts: []string{ + "code \"{{.Path}}\"", + }, + }, + { + Name: "blog", + Description: "Creates a MD file in the ~/Dropbox/Blog folder in the format YYYY-MM-DD[-ProjectName][-vVersion].md", + OS: "All", + Path: "~/Dropbox/Blog", + FileTemplatePath: "~/.templates/blog-template.md", + Type: FileType, + NamePatterns: []string{ + "{{$version := getVersion}}" + + "{{.Year}}-{{.Month}}-{{.Day}}" + + "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + + "{{if (gt $version 1)}}v{{$version}}{{end}}" + + ".md", + }, + ScriptShell: "pwsh", + PostScripts: []string{ + "code . \"{{.Name}}\"", + }, + }, + { + Name: "work", + Description: "Creates a folder in the c:/work folder in the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", + OS: "Windows", + Path: "C:/work", + Type: FolderType, + NamePatterns: []string{ + "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}-{{.Second}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + }, + ScriptShell: "pwsh", + PostScripts: []string{ + "explorer \"{{.Path}}\"", + }, + }, + { + Name: "folder", + Description: "Creates a folder in the current folder in the format YYYY-MM-DD[-ProjectName][-vVersion]", + Type: FolderType, + ScriptShell: "pwsh", + PostScripts: []string{}, + NamePatterns: []string{ + "{{$version := getVersion}}" + + "{{.Year}}-{{.Month}}-{{.Day}}" + + "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + + "{{if (gt $version 1)}}-n{{$version}}{{end}}", + }, + }, + { + Name: "create-react-app", + Type: FolderType, + Description: "Creates a folder in the current folder in the format create-react-app[-ProjectName][-vVersion], runs `npx create-react-app` to initialize the folder, and opens the folder in VSCode", + ScriptShell: "pwsh", + NamePatterns: []string{ + "{{$version := getVersion}}" + + "create-react-app" + + "{{if .ProjectName}}-{{.ProjectName}}{{end}}" + + "{{if (gt $version 1)}}-n{{$version}}{{end}}", + }, + PostScripts: []string{ + "npx create-react-app .", + "code .", + }, + }, + { + Name: "git", + Description: "Creates a folder in the c:/code folder in the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", + OS: "Windows", + Path: "C:/code", + Type: FolderType, + NamePatterns: []string{ + "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + "{{.Year}}-{{.Month}}-{{.Day}}-{{.Hour}}-{{.Minute}}-{{.Second}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + }, + ScriptShell: "pwsh", + PostScripts: []string{ + "git init", + "code \"{{.Path}}\"", + }, + }, + { + Name: "test", + Description: "Echoes the format YYYY-MM-DD[-hh][-mm][-ss][-ProjectName]", + Type: ScriptType, + NamePatterns: []string{ + "{{.Year}}-{{.Month}}-{{.Day}}{{if .ProjectName}}-{{.ProjectName}}{{end}}", + }, + ScriptShell: "pwsh", + PostScripts: []string{ + "echo \"Name={{.Name}}\"", + "echo \"Path={{.Path}}\"", + "echo \"Value1={{.Extras.value1}}\"", + "echo \"Value2={{.Extras.value2}}\"", + }, + }, + }, + } +} diff --git a/extras.go b/extras.go index d7a0293..2ecd856 100644 --- a/extras.go +++ b/extras.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "gopkg.in/yaml.v3" @@ -11,6 +12,10 @@ func loadExtras(path string) (map[string]string, error) { file, error := os.ReadFile(path) if error != nil { + if os.IsNotExist(error) { + fmt.Printf("extras file %s does not exist, extras not being used\n", path) + return emptyMap, nil + } return emptyMap, error } diff --git a/main.go b/main.go index c0ea6ab..84a850c 100644 --- a/main.go +++ b/main.go @@ -107,7 +107,7 @@ func main() { // extra features extras, err := loadExtras(extrasFilePath) if err != nil { - return nil + return fmt.Errorf("error loading extras from %v: %w", extrasFilePath, err) } // list profiles