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
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.jnss.me/joakim/jadedepo/internal/engine"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var depoCmd = &cobra.Command{
|
||||
Use: "depo",
|
||||
Short: "Manage depositories",
|
||||
}
|
||||
|
||||
var depoAddCmd = &cobra.Command{
|
||||
Use: "add <name> [path]",
|
||||
Short: "Add a depository",
|
||||
Long: "Register a new depository with a short name. If path is not provided, uses current working directory.",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Run: depoAdd,
|
||||
}
|
||||
|
||||
var depoListCmd = &cobra.Command{
|
||||
Use: "list",
|
||||
Short: "List all depositories",
|
||||
Run: depoList,
|
||||
}
|
||||
|
||||
var depoRemoveCmd = &cobra.Command{
|
||||
Use: "remove <name>",
|
||||
Short: "Remove a depository",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: depoRemove,
|
||||
}
|
||||
|
||||
var depoSetDefaultCmd = &cobra.Command{
|
||||
Use: "set-default <name>",
|
||||
Short: "Set the default depository",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: depoSetDefault,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(depoCmd)
|
||||
depoCmd.AddCommand(depoAddCmd)
|
||||
depoCmd.AddCommand(depoListCmd)
|
||||
depoCmd.AddCommand(depoRemoveCmd)
|
||||
depoCmd.AddCommand(depoSetDefaultCmd)
|
||||
}
|
||||
|
||||
func depoAdd(cmd *cobra.Command, args []string) {
|
||||
name := args[0]
|
||||
var path string
|
||||
|
||||
if len(args) == 2 {
|
||||
path = args[1]
|
||||
} else {
|
||||
// Use current working directory
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting current directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
path = cwd
|
||||
}
|
||||
|
||||
// Make path absolute
|
||||
absPath, err := filepath.Abs(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error resolving path: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Add depository
|
||||
if err := engine.AddDepository(name, absPath); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error adding depository: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Added depository '%s' at %s\n", name, absPath)
|
||||
}
|
||||
|
||||
func depoList(cmd *cobra.Command, args []string) {
|
||||
depos, defaultDepo, err := engine.ListDepositories()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error listing depositories: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(depos) == 0 {
|
||||
fmt.Println("No depositories configured")
|
||||
fmt.Println("Add one with: jade depo add <name> [path]")
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Depositories:")
|
||||
for name, path := range depos {
|
||||
if name == defaultDepo {
|
||||
fmt.Printf(" * %s -> %s (default)\n", name, path)
|
||||
} else {
|
||||
fmt.Printf(" %s -> %s\n", name, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func depoRemove(cmd *cobra.Command, args []string) {
|
||||
name := args[0]
|
||||
|
||||
if err := engine.RemoveDepository(name); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error removing depository: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Removed depository '%s'\n", name)
|
||||
}
|
||||
|
||||
func depoSetDefault(cmd *cobra.Command, args []string) {
|
||||
name := args[0]
|
||||
|
||||
if err := engine.SetDefaultDepository(name); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error setting default depository: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Set '%s' as default depository\n", name)
|
||||
}
|
||||
Reference in New Issue
Block a user