diff --git a/gemlog/config.go b/gemlog/config.go index 38f9f0d..ffc4285 100644 --- a/gemlog/config.go +++ b/gemlog/config.go @@ -1,13 +1,5 @@ package gemlog -import ( - "fmt" - "os" - "path/filepath" - - "gopkg.in/yaml.v3" -) - // CouchDBConfig represents the CouchDB configuration section type CouchDBConfig struct { Host string `yaml:"host"` @@ -20,25 +12,3 @@ type CouchDBConfig struct { type Config struct { CouchDB CouchDBConfig `yaml:"couchdb"` } - -// LoadConfig reads and parses the YAML configuration file from ~/.config/gemlog-cli -func LoadConfig() (*Config, error) { - homeDir, err := os.UserHomeDir() - if err != nil { - return nil, fmt.Errorf("failed to get user home directory: %w", err) - } - - configPath := filepath.Join(homeDir, ".config", "gemlog-cli", "config.yml") - - data, err := os.ReadFile(configPath) - if err != nil { - return nil, fmt.Errorf("failed to read config file %s: %w", configPath, err) - } - - var config Config - if err := yaml.Unmarshal(data, &config); err != nil { - return nil, fmt.Errorf("failed to parse YAML config: %w", err) - } - - return &config, nil -} diff --git a/gemlog/core.go b/gemlog/core.go index 07f3d10..7de38a7 100644 --- a/gemlog/core.go +++ b/gemlog/core.go @@ -1,9 +1,6 @@ package gemlog import ( - "crypto/rand" - "encoding/hex" - "fmt" "time" ) @@ -16,6 +13,7 @@ type GemlogEntry struct { Gemtxt string `json:"gemtxt"` } +// GemlogListEntry is for showing a list of gemlog entries without the main Gemtxt type GemlogListEntry struct { Title string `json:"title"` Slug string `json:"slug"` @@ -23,25 +21,3 @@ type GemlogListEntry struct { ID string `json:"id"` Rev string `json:"rev"` } - -// NewUUID generates a new UUID v4 using crypto/rand -func NewUUID() (string, error) { - uuid := make([]byte, 16) - _, err := rand.Read(uuid) - if err != nil { - return "", fmt.Errorf("failed to generate UUID: %w", err) - } - - // Set version (4) and variant bits according to RFC 4122 - uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4 - uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant bits - - // Format as standard UUID string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - return fmt.Sprintf("%s-%s-%s-%s-%s", - hex.EncodeToString(uuid[0:4]), - hex.EncodeToString(uuid[4:6]), - hex.EncodeToString(uuid[6:8]), - hex.EncodeToString(uuid[8:10]), - hex.EncodeToString(uuid[10:16]), - ), nil -} diff --git a/internal/ui/app.go b/internal/ui/app.go index 0887f3c..f3fce1c 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -120,7 +120,7 @@ func (m model) View() string { var enableLogs bool = true -func Run() { +func Run(config *gemlog.Config) { if enableLogs { f, err := tea.LogToFile("debug.log", "debug") if err != nil { @@ -133,12 +133,7 @@ func Run() { slog.SetDefault(logger) } slog.Info("Starting gemlog cli") - config, err := gemlog.LoadConfig() - if err != nil { - fmt.Printf("Error loading config: %v", err) - os.Exit(1) - } - err = gemlog.CheckDBConnection(config) + err := gemlog.CheckDBConnection(config) if err != nil { fmt.Printf("Error checking db connection: %v", err) os.Exit(1) diff --git a/internal/ui/config/config.go b/internal/ui/config/config.go new file mode 100644 index 0000000..547827a --- /dev/null +++ b/internal/ui/config/config.go @@ -0,0 +1,32 @@ +package config + +import ( + "fmt" + "os" + "path/filepath" + + gemlog "git.travisshears.com/travisshears/gemlog-cli/gemlog" + "gopkg.in/yaml.v3" +) + +// LoadConfig reads and parses the YAML configuration file from ~/.config/gemlog-cli +func LoadConfig() (*gemlog.Config, error) { + homeDir, err := os.UserHomeDir() + if err != nil { + return nil, fmt.Errorf("failed to get user home directory: %w", err) + } + + configPath := filepath.Join(homeDir, ".config", "gemlog-cli", "config.yml") + + data, err := os.ReadFile(configPath) + if err != nil { + return nil, fmt.Errorf("failed to read config file %s: %w", configPath, err) + } + + var config gemlog.Config + if err := yaml.Unmarshal(data, &config); err != nil { + return nil, fmt.Errorf("failed to parse YAML config: %w", err) + } + + return &config, nil +} diff --git a/main.go b/main.go index 9572dda..3c1c08a 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,19 @@ package main import ( + "fmt" + "os" + ui "git.travisshears.com/travisshears/gemlog-cli/internal/ui" + config "git.travisshears.com/travisshears/gemlog-cli/internal/ui/config" ) func main() { - ui.Run() + c, err := config.LoadConfig() + if err != nil { + fmt.Printf("Error loading config: %v", err) + os.Exit(1) + } + + ui.Run(c) } diff --git a/templates/default_post.gmi b/templates/default_post.gmi deleted file mode 100644 index ddb875b..0000000 --- a/templates/default_post.gmi +++ /dev/null @@ -1,12 +0,0 @@ -title: todo -date: 2025-12-31 -slug: todo -tags: cat, dog ---- - -Example text - -=> https://travisshears.com example link - -* Example list item 1 -* Example list item 2