Files
joakim 1d87d93172 Add multi-depository support with global config
- Implement global CLI config at ~/.config/jade/config.yml
- Add jade depo commands (add, list, remove, set-default)
- Support depository short names and context-aware detection
- Remove tag_prefix config, hardcode + syntax for consistency
- Update depository resolution: flag -> context -> default
- Auto-initialize .jade/ directory structure when adding depos
- Update documentation with new multi-depository workflow
2026-01-03 16:25:23 +01:00

70 lines
1.7 KiB
Go

package engine
import (
"fmt"
"os"
"path/filepath"
)
var instance *JadeDepo
type JadeDepo struct {
Config *Config
}
func Init(depoInput string) (*JadeDepo, error) {
cfg, err := initConfig(depoInput)
if err != nil {
return nil, fmt.Errorf("failed to initialize config: %w", err)
}
jd := &JadeDepo{
Config: cfg,
}
// Initialize depository structure (already done in initConfig, but ensure it's complete)
if err := jd.initDepoStructure(); err != nil {
return nil, fmt.Errorf("failed to initialize depository structure: %w", err)
}
// Store global instance
instance = jd
return jd, nil
}
// GetInstance returns the global JadeDepo instance
func GetInstance() (*JadeDepo, error) {
if instance == nil {
return nil, fmt.Errorf("jade depository not initialized")
}
return instance, nil
}
// initDepoStructure creates the necessary directories in the depository
func (jd *JadeDepo) initDepoStructure() error {
// Create depository root if it doesn't exist
if err := os.MkdirAll(jd.Config.DepoPath, 0755); err != nil {
return fmt.Errorf("failed to create depository: %w", err)
}
// Create .jade directory for metadata
jadeDir := filepath.Join(jd.Config.DepoPath, ".jade")
if err := os.MkdirAll(jadeDir, 0755); err != nil {
return fmt.Errorf("failed to create .jade directory: %w", err)
}
// Create trash directory
trashDir := filepath.Join(jadeDir, "trash")
if err := os.MkdirAll(trashDir, 0755); err != nil {
return fmt.Errorf("failed to create trash directory: %w", err)
}
return nil
}
// GetTrashPath returns the path to the trash directory
func (jd *JadeDepo) GetTrashPath() string {
return filepath.Join(jd.Config.DepoPath, ".jade", "trash")
}