diff --git a/Makefile b/Makefile index 0a43d8f72..7ed03c2cf 100755 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ release: echo "--- 🚀 Releasing it" "$(CURDIR)/scripts/release.sh" -test: deps install +test: deps installv3 @echo "--- ✅ Running tests" @if [ -f coverage.txt ]; then rm coverage.txt; fi; @echo "mode: count" > coverage.txt diff --git a/command/install.go b/command/install.go index c66b78f19..ddee672b7 100644 --- a/command/install.go +++ b/command/install.go @@ -9,7 +9,8 @@ import ( "github.com/spf13/cobra" ) -var libDir = "" +var libDir string +var force bool var installCmd = &cobra.Command{ Use: "install", Short: "Check required tools", @@ -20,12 +21,13 @@ var installCmd = &cobra.Command{ // Run the installer i, err := installer.NewInstaller() - // if libDir != "" { log.Println("[INFO] set lib dir target to", libDir) i.SetLibDir(libDir) } + i.Force(force) + if err != nil { log.Println("[ERROR] Your Pact library installation is out of date and we were unable to download a newer one for you:", err) os.Exit(1) @@ -39,6 +41,7 @@ var installCmd = &cobra.Command{ } func init() { - installCmd.Flags().StringVarP(&libDir, "libDir", "d", "", "Target directory to install the library") + installCmd.Flags().BoolVarP(&force, "force", "f", false, "Force a new installation") + installCmd.Flags().StringVarP(&libDir, "libDir", "d", "/usr/local/lib", "Target directory to install the library") RootCmd.AddCommand(installCmd) } diff --git a/command/root.go b/command/root.go index 87b58e864..139e25c88 100644 --- a/command/root.go +++ b/command/root.go @@ -39,10 +39,6 @@ func init() { // will be global for your application. RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", true, "verbose output") RootCmd.PersistentFlags().StringVarP(&logLevel, "logLevel", "l", "INFO", "Set the logging level (DEBUG, INFO, ERROR)") - - // Cobra also supports local flags, which will only run - // when this action is called directly. - RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } func setLogLevel(verbose bool, level string) { diff --git a/v3/installer/installer.go b/v3/installer/installer.go index 22a59839b..ca53dbb0a 100644 --- a/v3/installer/installer.go +++ b/v3/installer/installer.go @@ -35,6 +35,7 @@ type Installer struct { arch string fs afero.Fs libDir string + force bool } type installerConfig func(*Installer) error @@ -69,14 +70,21 @@ func (i *Installer) SetLibDir(dir string) { i.libDir = dir } +// Force installs over the top +func (i *Installer) Force(force bool) { + i.force = force +} + // CheckInstallation checks installation of all of the required libraries // and downloads if they aren't present func (i *Installer) CheckInstallation() error { // Check if files exist // --> Check versions of existing installed files - if err := i.checkPackageInstall(); err == nil { - return nil + if !i.force { + if err := i.checkPackageInstall(); err == nil { + return nil + } } // Check if override package path exists @@ -234,7 +242,6 @@ var osToExtension = map[string]string{ } type packageInfo struct { - packageName string libName string version string semverRange string