This commit introduces a TDD testing framework for the `collect` commands and resolves a build failure. - A `TDD/` directory has been added to house tests for the `collect` commands. - An environment variable `BORG_PLEXSUS=0` has been implemented to enable a mock mode, which prevents external network calls during testing. - The `collect` commands have been updated to use the command's output streams, allowing for output capturing in tests. - A `pkg/mocks` package has been added to provide mock implementations for testing. - The `.gitignore` file has been updated to exclude generated `.datanode` files. - The "flag redefined" build error has been fixed by refactoring the root command initialization in `cmd/root.go` to prevent duplicate flag definitions.
32 lines
986 B
Go
32 lines
986 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"log/slog"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func NewRootCmd() *cobra.Command {
|
|
rootCmd := &cobra.Command{
|
|
Use: "borg-data-collector",
|
|
Short: "A tool for collecting and managing data.",
|
|
Long: `Borg Data Collector is a command-line tool for cloning Git repositories,
|
|
packaging their contents into a single file, and managing the data within.`,
|
|
}
|
|
rootCmd.AddCommand(allCmd)
|
|
rootCmd.AddCommand(collectCmd)
|
|
rootCmd.AddCommand(serveCmd)
|
|
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "Enable verbose logging")
|
|
return rootCmd
|
|
}
|
|
|
|
// RootCmd represents the base command when called without any subcommands
|
|
var RootCmd = NewRootCmd()
|
|
|
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
func Execute(log *slog.Logger) error {
|
|
RootCmd.SetContext(context.WithValue(context.Background(), "logger", log))
|
|
return RootCmd.Execute()
|
|
}
|