This commit improves the user experience of the application by adding progress bars to long-running operations. The following commands now display a progress bar: - `collect github repo` - `collect website` - `collect pwa` The underlying packages (`pkg/vcs`, `pkg/website`, and `pkg/pwa`) have been updated to support progress reporting.
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/Snider/Borg/pkg/ui"
|
|
"github.com/Snider/Borg/pkg/vcs"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// collectGithubRepoCmd represents the collect github repo command
|
|
var collectGithubRepoCmd = &cobra.Command{
|
|
Use: "repo [repository-url]",
|
|
Short: "Collect a single Git repository",
|
|
Long: `Collect a single Git repository and store it in a DataNode.`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
repoURL := args[0]
|
|
outputFile, _ := cmd.Flags().GetString("output")
|
|
|
|
bar := ui.NewProgressBar(-1, "Cloning repository")
|
|
defer bar.Finish()
|
|
|
|
dn, err := vcs.CloneGitRepository(repoURL, bar)
|
|
if err != nil {
|
|
fmt.Printf("Error cloning repository: %v\n", err)
|
|
return
|
|
}
|
|
|
|
data, err := dn.ToTar()
|
|
if err != nil {
|
|
fmt.Printf("Error serializing DataNode: %v\n", err)
|
|
return
|
|
}
|
|
|
|
err = os.WriteFile(outputFile, data, 0644)
|
|
if err != nil {
|
|
fmt.Printf("Error writing DataNode to file: %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Repository saved to %s\n", outputFile)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
collectGithubCmd.AddCommand(collectGithubRepoCmd)
|
|
collectGithubRepoCmd.PersistentFlags().String("output", "repo.dat", "Output file for the DataNode")
|
|
}
|