package cli import ( "fmt" "github.com/spf13/cobra" "larc.wejust.rest/larc/internal/convert" ) /* CLI commands for larc <-> git conversion. * - larc2git: export larc repository to git format * - git2larc: import git repository to larc format */ // Larc2GitCmd creates the larc2git command func Larc2GitCmd() *cobra.Command { cmd := &cobra.Command{ Use: "larc2git ", Short: "Export larc repository to git format", Long: `Export a larc repository to git format. Converts larc revisions to git commits, preserving: - Commit history and messages - Branch structure (port -> main) - File contents and permissions - Author information and timestamps The git repository will be created at the destination path.`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { verbose, _ := cmd.Flags().GetBool("verbose") larcPath := args[0] gitPath := args[1] fmt.Printf("Exporting larc repository to git...\n") fmt.Printf(" Source: %s\n", larcPath) fmt.Printf(" Destination: %s\n", gitPath) if err := convert.ExportToGit(larcPath, gitPath, verbose); err != nil { return fmt.Errorf("export failed: %w", err) } return nil }, } cmd.Flags().BoolP("verbose", "v", false, "verbose output") return cmd } // Git2LarcCmd creates the git2larc command func Git2LarcCmd() *cobra.Command { cmd := &cobra.Command{ Use: "git2larc ", Short: "Import git repository to larc format", Long: `Import a git repository to larc format. Converts git commits to larc revisions, with: - Sequential revision numbering (r1, r2, ...) - Flat tree structure - Branch conversion (main/master -> port) - xxhash64 blob hashing with zstd compression The larc repository will be created at the destination path.`, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { verbose, _ := cmd.Flags().GetBool("verbose") gitPath := args[0] larcPath := args[1] fmt.Printf("Importing git repository to larc...\n") fmt.Printf(" Source: %s\n", gitPath) fmt.Printf(" Destination: %s\n", larcPath) if err := convert.ImportFromGit(gitPath, larcPath, verbose); err != nil { return fmt.Errorf("import failed: %w", err) } return nil }, } cmd.Flags().BoolP("verbose", "v", false, "verbose output") return cmd } // ConvertCmd creates a parent command for conversion utilities func ConvertCmd() *cobra.Command { cmd := &cobra.Command{ Use: "convert", Short: "Convert between larc and git repositories", Long: `Convert between larc and git repository formats. Subcommands: larc2git Export larc repository to git git2larc Import git repository to larc Example usage: larc convert larc2git ./my-larc-repo ./my-git-repo larc convert git2larc ./my-git-repo ./my-larc-repo`, } cmd.AddCommand(Larc2GitCmd()) cmd.AddCommand(Git2LarcCmd()) return cmd }