Skip to content

Commit

Permalink
feat: allow force install of the lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 14, 2021
1 parent c2a41e8 commit 5c95dc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions command/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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)
}
4 changes: 0 additions & 4 deletions command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions v3/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Installer struct {
arch string
fs afero.Fs
libDir string
force bool
}

type installerConfig func(*Installer) error
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -234,7 +242,6 @@ var osToExtension = map[string]string{
}

type packageInfo struct {
packageName string
libName string
version string
semverRange string
Expand Down

0 comments on commit 5c95dc0

Please sign in to comment.