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.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Snider/Borg/pkg/website"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// collectWebsiteCmd represents the collect website command
|
|
var collectWebsiteCmd = &cobra.Command{
|
|
Use: "website [url]",
|
|
Short: "Collect a single website",
|
|
Long: `Collect a single website and store it in a DataNode.`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
websiteURL := args[0]
|
|
outputFile, _ := cmd.Flags().GetString("output")
|
|
depth, _ := cmd.Flags().GetInt("depth")
|
|
|
|
dn, err := website.DownloadAndPackageWebsite(websiteURL, depth)
|
|
if err != nil {
|
|
fmt.Printf("Error downloading and packaging website: %v\n", err)
|
|
return
|
|
}
|
|
|
|
websiteData, err := dn.ToTar()
|
|
if err != nil {
|
|
fmt.Printf("Error converting website to bytes: %v\n", err)
|
|
return
|
|
}
|
|
|
|
err = os.WriteFile(outputFile, websiteData, 0644)
|
|
if err != nil {
|
|
fmt.Printf("Error writing website to file: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Website saved to %s\n", outputFile)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
collectCmd.AddCommand(collectWebsiteCmd)
|
|
collectWebsiteCmd.PersistentFlags().String("output", "website.dat", "Output file for the DataNode")
|
|
collectWebsiteCmd.PersistentFlags().Int("depth", 2, "Recursion depth for downloading")
|
|
}
|