fuzzyworld

template / commit

Starting work on patterns and generating new file/folder names.

d026838a2cb2be5b53a0de172fe95ab0c7476028 · Pavel Safronov · 2022-09-21 17:20:53 -0700 · parents 4a7361b0a6aa

Starting work on patterns and generating new file/folder names.
 config.go | 17 +++++++++++++----
 main.go   | 15 ++++++++++++++-
 new.go    | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/config.go b/config.go
index 115748e..93680c3 100644
--- a/config.go
+++ b/config.go
@@ -14,8 +14,16 @@ const (
 )
 
 type Profile struct {
-	Path string
-	Type ProfileType
+	Path        string
+	Type        ProfileType
+	NamePattern string
+	// ReplacementStrings map[string][]string
+	// FileTemplatePath string
+}
+
+type PatternInfo struct {
+	DistinctDate string
+	Name         string
 }
 
 type Config struct {
@@ -26,8 +34,9 @@ func defaultConfig() Config {
 	return Config{
 		Profiles: map[string]Profile{
 			"default": {
-				Path: "C:/DailyNotes",
-				Type: FileType,
+				Path:        "C:/DailyNotes",
+				Type:        FileType,
+				NamePattern: "{{date}}.md",
 			},
 			"blog": {
 				Path: "~/Dropbox/Blog",
diff --git a/main.go b/main.go
index c76a9bd..47060b6 100644
--- a/main.go
+++ b/main.go
@@ -12,6 +12,7 @@ import (
 func main() {
 	defaultProfileName := "default"
 	var profileName string
+	var projectName string
 
 	app := &cli.App{
 		Name:                 "template",
@@ -27,20 +28,30 @@ func main() {
 				// Required:    true,
 				// EnvVars: []string{"TEMPLATE_PROFILE"},
 			},
+			&cli.StringFlag{
+				Name:        "name",
+				Aliases:     []string{"n"},
+				Usage:       "name of the project to create",
+				Value:       "",
+				Destination: &projectName,
+			},
 		},
 		Action: func(context *cli.Context) error {
+			// get profile name from args
 			if profileName == defaultProfileName && context.Args().Len() > 0 {
 				profileName = context.Args().Get(0)
 			}
 			message := fmt.Sprintf("Profile: %v", profileName)
 			fmt.Println(message)
 
+			// construct config file path
 			userProfile, err := os.UserHomeDir()
 			if err != nil {
 				processError(err, "Getting user home dir")
 			}
-
 			configFilePath := filepath.Join(userProfile, ".template.yaml")
+
+			// try and load config
 			config, err := loadConfig(configFilePath)
 			if err != nil {
 				fmt.Printf("No config present at '%v', creating and using sample config", configFilePath)
@@ -58,10 +69,12 @@ func main() {
 					processError(err, "Error while loading")
 				}
 			} else {
+				// log successful load
 				fmt.Printf("Config loaded from '%v'", configFilePath)
 				fmt.Println()
 			}
 
+			// find profile by name
 			profile, ok := config.Profiles[profileName]
 			if ok {
 				fmt.Println("Found profile!")
diff --git a/new.go b/new.go
new file mode 100644
index 0000000..038293d
--- /dev/null
+++ b/new.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+	"fmt"
+	"os"
+)
+
+func processProfile(profile Profile, name string, cwd string) error {
+	files, err := os.ReadDir(cwd)
+	if err != nil {
+		return err
+	}
+
+	var useDirs bool
+	switch profile.Type {
+	case FileType:
+		useDirs = false
+	case FolderType:
+		useDirs = true
+	default:
+		return fmt.Errorf("Unknown profile type: %v", profile.Type)
+	}
+
+	var entities []string
+	for _, file := range files {
+		isDir := file.IsDir()
+		if isDir == useDirs {
+			entities = append(entities, file.Name())
+		}
+	}
+
+	patternInfo := PatternInfo{}
+
+	return nil
+}
+
+// func getNextEntry(name string, existingNames []string, profile Profile) string {
+// 	profile.
+// }