This commit introduces the core functionality of the Borg Data Collector. - Adds the `collect` command to clone a single Git repository and store it in a Trix cube. - Adds the `collect all` command to clone all public repositories from a GitHub user or organization. - Implements the Trix cube as a `tar` archive. - Adds the `ingest` command to add files to a Trix cube. - Adds the `cat` command to extract files from a Trix cube. - Integrates Borg-themed status messages for a more engaging user experience.
56 lines
1 KiB
Go
56 lines
1 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"borg-data-collector/pkg/borg"
|
|
"borg-data-collector/pkg/trix"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// ingestCmd represents the ingest command
|
|
var ingestCmd = &cobra.Command{
|
|
Use: "ingest [cube-file] [file-to-add]",
|
|
Short: "Add a file to a Trix cube",
|
|
Long: `Add a file to a Trix cube. If the cube file does not exist, it will be created.`,
|
|
Args: cobra.ExactArgs(2),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
cubeFile := args[0]
|
|
fileToAdd := args[1]
|
|
|
|
var cube *trix.Cube
|
|
var err error
|
|
|
|
if _, err := os.Stat(cubeFile); os.IsNotExist(err) {
|
|
cube, err = trix.NewCube(cubeFile)
|
|
} else {
|
|
cube, err = trix.AppendToCube(cubeFile)
|
|
}
|
|
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
defer cube.Close()
|
|
|
|
content, err := os.ReadFile(fileToAdd)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
err = cube.AddFile(fileToAdd, content)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
fmt.Println(borg.GetRandomCodeShortMessage())
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(ingestCmd)
|
|
}
|