summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-23 17:24:20 +0300
committerPaul Buetow <paul@buetow.org>2025-06-23 17:24:20 +0300
commit60691a6fb610cb7f7290d6ab3a26bc74f95af611 (patch)
tree8c6fb5cc4f3907c14bbc6258ed8eac85041acf05 /internal
parent97e0151ba6a260195ced76ab69d3e3bd58ba68fc (diff)
Add configuration file support with organization list
- Create config package with JSON parsing support - Define Organization struct with host and name - Add config file auto-detection in common locations - Add --config/-c flag for custom config path - Add --list-orgs flag to display configured organizations - Create example configuration file - Add comprehensive .gitignore Configuration supports multiple git organizations for future sync functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
new file mode 100644
index 0000000..91c107a
--- /dev/null
+++ b/internal/config/config.go
@@ -0,0 +1,83 @@
+package config
+
+import (
+ "encoding/json"
+ "fmt"
+ "os"
+ "path/filepath"
+)
+
+// Organization represents a git organization with its host and name
+type Organization struct {
+ Host string `json:"host"`
+ Name string `json:"name"`
+}
+
+// Config holds the application configuration
+type Config struct {
+ Organizations []Organization `json:"organizations"`
+}
+
+// Load reads and parses the configuration file
+func Load(path string) (*Config, error) {
+ // Expand home directory if needed
+ if path[:2] == "~/" {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return nil, fmt.Errorf("failed to get home directory: %w", err)
+ }
+ path = filepath.Join(home, path[2:])
+ }
+
+ // Read config file
+ data, err := os.ReadFile(path)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read config file: %w", err)
+ }
+
+ // Parse JSON
+ var cfg Config
+ if err := json.Unmarshal(data, &cfg); err != nil {
+ return nil, fmt.Errorf("failed to parse config: %w", err)
+ }
+
+ // Validate configuration
+ if err := cfg.Validate(); err != nil {
+ return nil, fmt.Errorf("invalid configuration: %w", err)
+ }
+
+ return &cfg, nil
+}
+
+// Validate checks if the configuration is valid
+func (c *Config) Validate() error {
+ if len(c.Organizations) == 0 {
+ return fmt.Errorf("no organizations configured")
+ }
+
+ for i, org := range c.Organizations {
+ if org.Host == "" {
+ return fmt.Errorf("organization %d: missing host", i)
+ }
+ if org.Name == "" {
+ return fmt.Errorf("organization %d: missing name", i)
+ }
+ }
+
+ return nil
+}
+
+// GetGitURL returns the git URL for an organization
+func (o *Organization) GetGitURL() string {
+ return fmt.Sprintf("%s:%s", o.Host, o.Name)
+}
+
+// FindOrganization finds an organization by host
+func (c *Config) FindOrganization(host string) *Organization {
+ for _, org := range c.Organizations {
+ if org.Host == host {
+ return &org
+ }
+ }
+ return nil
+} \ No newline at end of file