Borg/cmd/cat.go
google-labs-jules[bot] 21f9a9ca74 feat: Implement core data collection and Trix cube functionality
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.
2025-10-31 05:02:29 +00:00

53 lines
922 B
Go

package cmd
import (
"fmt"
"io"
"os"
"borg-data-collector/pkg/trix"
"github.com/spf13/cobra"
)
// catCmd represents the cat command
var catCmd = &cobra.Command{
Use: "cat [cube-file] [file-to-extract]",
Short: "Extract a file from a Trix cube",
Long: `Extract a file from a Trix cube and print its content to standard output.`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
cubeFile := args[0]
fileToExtract := args[1]
reader, file, err := trix.Extract(cubeFile)
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
for {
hdr, err := reader.Next()
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err)
return
}
if hdr.Name == fileToExtract {
if _, err := io.Copy(os.Stdout, reader); err != nil {
fmt.Println(err)
return
}
return
}
}
},
}
func init() {
rootCmd.AddCommand(catCmd)
}