Borg/cmd/collect_pwa.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

56 lines
1.3 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/Snider/Borg/pkg/pwa"
"github.com/spf13/cobra"
)
// collectPWACmd represents the collect pwa command
var collectPWACmd = &cobra.Command{
Use: "pwa [url]",
Short: "Collect a single PWA",
Long: `Collect a single PWA and store it in a DataNode.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
pwaURL := args[0]
outputFile, _ := cmd.Flags().GetString("output")
fmt.Println("Finding PWA manifest...")
manifestURL, err := pwa.FindManifest(pwaURL)
if err != nil {
fmt.Printf("Error finding manifest: %v\n", err)
return
}
fmt.Printf("Found manifest: %s\n", manifestURL)
fmt.Println("Downloading and packaging PWA...")
dn, err := pwa.DownloadAndPackagePWA(pwaURL, manifestURL)
if err != nil {
fmt.Printf("Error downloading and packaging PWA: %v\n", err)
return
}
pwaData, err := dn.ToTar()
if err != nil {
fmt.Printf("Error converting PWA to bytes: %v\n", err)
return
}
err = os.WriteFile(outputFile, pwaData, 0644)
if err != nil {
fmt.Printf("Error writing PWA to file: %v\n", err)
return
}
fmt.Printf("PWA saved to %s\n", outputFile)
},
}
func init() {
collectCmd.AddCommand(collectPWACmd)
collectPWACmd.PersistentFlags().String("output", "pwa.dat", "Output file for the DataNode")
}