<commit_before>package cmd

import (
	"errors"
	"fmt"
	"github.com/LastCallMedia/vagabond/config"
	"github.com/codegangsta/cli"
	"log"
	"os"
	"os/exec"
)

var CmdDiagnose = cli.Command{
	Name:   "diagnose",
	Action: runDiagnose,
}

func runDiagnose(ctx *cli.Context) {
	fmt.Println("Running diagnostics...")

	err := runDockerInstallationCheck()
	checkOrFatal(err, "Docker is not installed: %s")

	err = runDockerComposeInstallationCheck()
	checkOrFatal(err, "Docker-compose is not installed: %s")

	err = runDockerConnectionCheck()
	checkOrFatal(err, "Docker is unable to connect to the daemon: %s")

	env := config.NewEnvironment()
	env.Check()
}

func checkOrFatal(err error, msg string) {
	if err != nil {
		log.Fatal(fmt.Sprintf(msg, err))
	}
}

func runDockerInstallationCheck() (err error) {
	cmd := exec.Command("which", "docker")
	return cmd.Run()
}

func runDockerComposeInstallationCheck() (err error) {
	cmd := exec.Command("which", "docker-compose")
	return cmd.Run()
}

func runDockerConnectionCheck() (err error) {
	cmd := exec.Command("docker", "info")
	return cmd.Run()
}

func runEnvCheck() (err error) {
	envvar := os.Getenv("DOCKER_SITES_DIR")
	if "" == envvar {
		err = errors.New("$DOCKER_SITES_DIR is not defined")
		return err
	}

	envvar = os.Getenv("DOCKER_TZ")
	if "" == envvar {
		err = errors.New("$DOCKER_TZ is not defined")
		return err
	}

	return err
}
<commit_msg>Add checks for machine existence and boot status<commit_after>package cmd

import (
	"errors"
	"fmt"
	"github.com/LastCallMedia/vagabond/config"
	"github.com/codegangsta/cli"
	"log"
	"os"
	"os/exec"
	"runtime"
)

var CmdDiagnose = cli.Command{
	Name:   "diagnose",
	Action: runDiagnose,
}

func runDiagnose(ctx *cli.Context) {
	fmt.Println("Running diagnostics...")

	env := config.NewEnvironment()
	env.Check()

	err := runDockerInstallationCheck()
	checkOrFatal(err, "Docker is not installed: %s")

	err = runDockerComposeInstallationCheck()
	checkOrFatal(err, "Docker-compose is not installed: %s")

	err = runDockerConnectionCheck()
	if err != nil {
		if runtime.GOOS == "darwin" {
			// Requires machine.
			machine := env.GetMachine()
			if !machine.IsCreated() {
				log.Fatal("Docker machine is not created.")
			}
			if !machine.IsBooted() {
				log.Fatal("Docker machine is created but not booted.")
			}
		}
		log.Fatalf("Docker is unable to connect to the daemon: %s", err)
	}
}

func checkOrFatal(err error, msg string) {
	if err != nil {
		log.Fatal(fmt.Sprintf(msg, err))
	}
}

func runDockerInstallationCheck() (err error) {
	cmd := exec.Command("which", "docker")
	return cmd.Run()
}

func runDockerComposeInstallationCheck() (err error) {
	cmd := exec.Command("which", "docker-compose")
	return cmd.Run()
}

func runDockerConnectionCheck() (err error) {
	cmd := exec.Command("docker", "info")
	return cmd.Run()
}

func runEnvCheck() (err error) {
	envvar := os.Getenv("DOCKER_SITES_DIR")
	if "" == envvar {
		err = errors.New("$DOCKER_SITES_DIR is not defined")
		return err
	}

	envvar = os.Getenv("DOCKER_TZ")
	if "" == envvar {
		err = errors.New("$DOCKER_TZ is not defined")
		return err
	}

	return err
}

{'fraction_non_alphanumeric': 0.1490722968650032, 'fraction_numerical': 0.0, 'mean_word_length': 4.363636363636363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2919427', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1158, 'n_words': 270}