Borg/cmd/collect.go
google-labs-jules[bot] bd65eefcd3 refactor: Use DataNode for repository collection
This commit refactors the repository collection functionality to use the new `DataNode` package instead of the old `trix` package.

The `collect` and `all` commands have been updated to use the new `vcs` package, which clones Git repositories and packages them into a `DataNode`. The `trix` package and its related commands (`cat`, `ingest`) have been removed.
2025-10-31 21:03:26 +00:00

47 lines
1 KiB
Go

package cmd
import (
"fmt"
"os"
"borg-data-collector/pkg/vcs"
"github.com/spf13/cobra"
)
// collectCmd represents the collect command
var collectCmd = &cobra.Command{
Use: "collect [repository-url]",
Short: "Collect a single repository",
Long: `Collect a single repository and store it in a DataNode.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
repoURL := args[0]
outputFile, _ := cmd.Flags().GetString("output")
dn, err := vcs.CloneGitRepository(repoURL)
if err != nil {
fmt.Printf("Error cloning repository: %v\n", err)
return
}
data, err := dn.ToTar()
if err != nil {
fmt.Printf("Error serializing DataNode: %v\n", err)
return
}
err = os.WriteFile(outputFile, data, 0644)
if err != nil {
fmt.Printf("Error writing DataNode to file: %v\n", err)
return
}
fmt.Printf("Repository saved to %s\n", outputFile)
},
}
func init() {
rootCmd.AddCommand(collectCmd)
collectCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode")
}