Borg/cmd/collect_git.go
google-labs-jules[bot] c68626985e feat: Add go.work, update module path, and add examples
This commit introduces several maintenance improvements to the repository.

- A `go.work` file has been added to define the workspace and make the project easier to work with.
- The module path in `go.mod` has been updated to use a GitHub URL, and all import paths have been updated accordingly.
- `examples` and `docs` directories have been created.
- The `examples` directory contains scripts that demonstrate the tool's functionality.
- The `docs` directory contains documentation for the project.
- Tests have been added to the `pkg/github` package following the `_Good`, `_Bad`, `_Ugly` convention.
- The missing `pkg/borg` package has been added to resolve a build error.
2025-10-31 22:15:05 +00:00

47 lines
1 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/Snider/Borg/pkg/vcs"
"github.com/spf13/cobra"
)
// collectGitCmd represents the collect git command
var collectGitCmd = &cobra.Command{
Use: "git [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")
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() {
collectCmd.AddCommand(collectGitCmd)
collectGitCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode")
}