Initial commit
This commit is contained in:
commit
309b240cdc
12 changed files with 738 additions and 0 deletions
69
cmd/root.go
Normal file
69
cmd/root.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue