<commit_before>package util

import (
	"boshlite/configuration"
	termcolor "boshlite/terminalcolor"
	"fmt"
	"log"
	"os/exec"
)

func Execute(bash string, sudo bool) (out []byte, err error) {
  if sudo {
	  out, err = exec.Command("sudo", "bash", "-c", bash).Output()
  } else {
	  out, err = exec.Command("bash", "-c", bash).Output()
  }
	return
}

func RouteCmd(config configuration.Configuration) (routecmd string) {
 	switch config.OStype {
	case "Darwin":
		routecmd = "route delete -net " + config.IpRange + " " + config.Gateway + " > /dev/null 2>&1;"
		routecmd += "route add -net " + config.IpRange + " " + config.Gateway
	case "Linux":
		routecmd = "route add -net " + config.IpRange + " gw " + config.Gateway
	default:
		log.Fatal("Not supported OS detected")
	}
  return
}

func Addroute(config configuration.Configuration) {
	routecmd := RouteCmd(config)

	out, err := Execute(routecmd, true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", out)
}


type CheckVersion struct {
  name string
  cmd_exist string
  cmd_version string
  expect_version string
}

func BuildSanitymap() []CheckVersion {
  check_map := []CheckVersion{
    {
      "Vagrant",
      "which vagrant",
      "vagrant -v|cut -d' ' -f2",
      "1.3.4",
    },
    {
      "BOSH CLI",
      "which bosh",
      "bosh -v|cut -d' ' -f2",
      "1.5.0.pre.1525",
    },
    {
      "Spiff",
      "which spiff",
      "spiff --version|cut -d' ' -f3",
      "0.0.0",
    },
    {
      "Go CF Cli",
      "which gcf",
      "gcf --version|cut -d' ' -f3",
      "6.0.0.rc1-SHA",
    },
    
  }
  return check_map
}

func SoftCheck() {
  sanity_map := BuildSanitymap()
  for _, check := range sanity_map {
    fmt.Printf("Checking %s...\n", termcolor.Colorize(check.name, termcolor.Cyan, false))
    _, err := Execute(check.cmd_exist, false) 
    if  err != nil {
      fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] No " + check.name + " found in your path"))
    } else {
      fmt.Printf("%s\n", termcolor.SuccessColor("  Found " + check.name + " installed"))
      out, err := Execute(check.cmd_version, false)
      if err!= nil {
        fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] Not able to determine your " + check.name + " version"))
      }

      // create a string stip the newline
      cur_version := string(out[:len(string(out))-1])
      if cur_version < check.expect_version {
        fmt.Printf("%s\n", termcolor.WarnColor("  [Warnning] Detect " + check.name + " version (" + cur_version + ") lower than expected (" + check.expect_version + ")" ))
      } else {
        fmt.Printf("%s\n", termcolor.SuccessColor("  Detect " + check.name + " version (" + cur_version + ") fulfill expected version (" + check.expect_version + ")" ))
      }
    }
  }
}

<commit_msg>add vagrant plugin check and more stable version check<commit_after>package util

import (
	"boshlite/configuration"
	termcolor "boshlite/terminalcolor"
	"fmt"
	"log"
	"os/exec"
)

func Execute(bash string, sudo bool) (out []byte, err error) {
  if sudo {
	  out, err = exec.Command("sudo", "bash", "-c", bash).Output()
  } else {
	  out, err = exec.Command("bash", "-c", bash).Output()
  }
	return
}

func RouteCmd(config configuration.Configuration) (routecmd string) {
 	switch config.OStype {
	case "Darwin":
		routecmd = "route delete -net " + config.IpRange + " " + config.Gateway + " > /dev/null 2>&1;"
		routecmd += "route add -net " + config.IpRange + " " + config.Gateway
	case "Linux":
		routecmd = "route add -net " + config.IpRange + " gw " + config.Gateway
	default:
		log.Fatal("Not supported OS detected")
	}
  return
}

func Addroute(config configuration.Configuration) {
	routecmd := RouteCmd(config)

	out, err := Execute(routecmd, true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", out)
}


type CheckVersion struct {
  name string
  cmd_exist string
  cmd_version string
  expect_version string
}

func BuildSanitymap() []CheckVersion {
  check_map := []CheckVersion{
    {
      "Vagrant",
      "which vagrant",
      "vagrant -v|cut -d' ' -f2",
      "1.3.4",
    },
    {
      "Vagrant fusion plugin",
      "vagrant plugin list|grep vagrant-vmware-fusion",
      "vagrant plugin list|grep vagrant-vmware-fusion|cut -d' ' -f2|cut -d'(' -f2|cut -d')' -f1",
      "2.1.0",
    },
    {
      "BOSH CLI",
      "which bosh",
      "bosh -v|cut -d' ' -f2",
      "1.5.0.pre.1525",
    },
    {
      "Spiff",
      "which spiff",
      "spiff --version|cut -d' ' -f3",
      "0.0.0",
    },
    {
      "Go CF Cli",
      "which gcf",
      "gcf --version|cut -d' ' -f3",
      "6.0.0.rc1-SHA",
    },
  }
  return check_map
}

func SoftCheck() {
  sanity_map := BuildSanitymap()
  for _, check := range sanity_map {
    fmt.Printf("Checking %s...\n", termcolor.Colorize(check.name, termcolor.Cyan, false))
    _, err := Execute(check.cmd_exist, false) 
    if  err != nil {
      fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] No " + check.name + " found in your path"))
    } else {
      fmt.Printf("%s\n", termcolor.SuccessColor("  Found " + check.name + " installed"))
      out, err := Execute(check.cmd_version, false)
      if err!= nil {
        fmt.Printf("%s\n", termcolor.FailureColor("  [ERROR] Not able to determine your " + check.name + " version"))
      }

      // create a string stip the newline
      var cur_version string
      if len(string(out))>1 {
        cur_version = string(out[:len(string(out))-1])
      } else {
        cur_version = "NIL" 
      }
      if cur_version == "NIL" {
        fmt.Printf("%s\n", termcolor.WarnColor("  [Warnning] " + check.name + " version unknown, try install " + check.expect_version + " or newer"))
      } else if cur_version < check.expect_version {
        fmt.Printf("%s\n", termcolor.WarnColor("  [Warnning] Detect " + check.name + " version (" + cur_version + ") lower than expected (" + check.expect_version + ")" ))
      } else {
        fmt.Printf("%s\n", termcolor.SuccessColor("  Detect " + check.name + " version (" + cur_version + ") fulfill expected version (" + check.expect_version + ")" ))
      }
    }
  }
}


{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.008995747464834806, 'mean_word_length': 2.668266346730654, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6580837', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2164, 'n_words': 495}