Borg/cmd/collect_github_repo.go
google-labs-jules[bot] 4e5257ce4a feat: Add Terminal Isolation Matrix feature
This change introduces the "Terminal Isolation Matrix", a new output format that creates a runc-compatible container bundle. This allows for the collected files to be run in an isolated environment. A --format flag has been added to all collect commands to support this new format.
2025-11-02 12:39:46 +00:00

68 lines
1.7 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/Snider/Borg/pkg/matrix"
"github.com/Snider/Borg/pkg/ui"
"github.com/Snider/Borg/pkg/vcs"
"github.com/spf13/cobra"
)
// collectGithubRepoCmd represents the collect github repo command
var collectGithubRepoCmd = &cobra.Command{
Use: "repo [repository-url]",
Short: "Collect a single Git repository",
Long: `Collect a single Git 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")
format, _ := cmd.Flags().GetString("format")
bar := ui.NewProgressBar(-1, "Cloning repository")
defer bar.Finish()
dn, err := vcs.CloneGitRepository(repoURL, bar)
if err != nil {
fmt.Printf("Error cloning repository: %v\n", err)
return
}
var data []byte
if format == "matrix" {
matrix, err := matrix.FromDataNode(dn)
if err != nil {
fmt.Printf("Error creating matrix: %v\n", err)
return
}
data, err = matrix.ToTar()
if err != nil {
fmt.Printf("Error serializing matrix: %v\n", err)
return
}
} else {
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() {
collectGithubCmd.AddCommand(collectGithubRepoCmd)
collectGithubRepoCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode")
collectGithubRepoCmd.PersistentFlags().String("format", "datanode", "Output format (datanode or matrix)")
}