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.
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/Snider/Borg/pkg/borg"
|
|
"github.com/Snider/Borg/pkg/github"
|
|
"github.com/Snider/Borg/pkg/vcs"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// allCmd represents the all command
|
|
var allCmd = &cobra.Command{
|
|
Use: "all [user/org]",
|
|
Short: "Collect all public repositories from a user or organization",
|
|
Long: `Collect all public repositories from a user or organization and store them in a DataNode.`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
fmt.Println(borg.GetRandomAssimilationMessage())
|
|
|
|
repos, err := github.GetPublicRepos(args[0])
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
outputDir, _ := cmd.Flags().GetString("output")
|
|
|
|
for _, repoURL := range repos {
|
|
fmt.Printf("Cloning %s...\n", repoURL)
|
|
|
|
dn, err := vcs.CloneGitRepository(repoURL)
|
|
if err != nil {
|
|
fmt.Printf("Error cloning %s: %s\n", repoURL, err)
|
|
continue
|
|
}
|
|
|
|
data, err := dn.ToTar()
|
|
if err != nil {
|
|
fmt.Printf("Error serializing DataNode for %s: %v\n", repoURL, err)
|
|
continue
|
|
}
|
|
|
|
repoName := strings.Split(repoURL, "/")[len(strings.Split(repoURL, "/"))-1]
|
|
outputFile := fmt.Sprintf("%s/%s.dat", outputDir, repoName)
|
|
err = os.WriteFile(outputFile, data, 0644)
|
|
if err != nil {
|
|
fmt.Printf("Error writing DataNode for %s to file: %v\n", repoURL, err)
|
|
continue
|
|
}
|
|
}
|
|
|
|
fmt.Println(borg.GetRandomCodeLongMessage())
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(allCmd)
|
|
allCmd.PersistentFlags().String("output", ".", "Output directory for the DataNodes")
|
|
}
|