azure_migrate/cmd/root.go

70 lines
1.4 KiB
Go
Raw Normal View History

2026-03-22 09:43:45 +00:00
package cmd
import (
"github.com/spf13/cobra"
"vix.ro/sonix/azure_migrate/internal/config"
"vix.ro/sonix/azure_migrate/internal/migrator"
)
var (
cfgFile string
rootCmd = &cobra.Command{
Use: "forgejo-migrator",
Short: "Mirror repositories from Azure DevOps to Forgejo",
Long: `A CLI tool to migrate Git repositories including LFS from Azure DevOps to Forgejo.`,
}
)
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", ".env", "config file (default is .env)")
rootCmd.AddCommand(migrateCmd)
rootCmd.AddCommand(listCmd)
}
func initConfig() {
if err := config.Load(cfgFile); err != nil {
panic(err)
}
}
func Execute() error {
return rootCmd.Execute()
}
var migrateCmd = &cobra.Command{
Use: "migrate",
Short: "Start migration process",
RunE: func(cmd *cobra.Command, args []string) error {
dryRun, _ := cmd.Flags().GetBool("dry-run")
cfg := config.Get()
cfg.DryRun = dryRun
m, err := migrator.New(cfg)
if err != nil {
return err
}
return m.Run()
},
}
var listCmd = &cobra.Command{
Use: "list",
Short: "List available Azure repositories",
RunE: func(cmd *cobra.Command, args []string) error {
cfg := config.Get()
m, err := migrator.New(cfg)
if err != nil {
return err
}
return m.ListRepositories()
},
}
func init() {
migrateCmd.Flags().BoolP("dry-run", "d", false, "Show what would be migrated without making changes")
}