func isEmpty(path string) (bool, error) {
	if b, _ := exists(path); !b {
		return false, fmt.Errorf("%q path does not exist", path)
	}
	fi, err := os.Stat(path)
	if err != nil {
		return false, err
	}
	if fi.IsDir() {
		f, err := os.Open(path)
		defer f.Close()
		if err != nil {
			return false, err
		}
		list, _ := f.Readdir(-1)
		return len(list) == 0, nil
	}
	return fi.Size() == 0, nil
}
isEmpty checks if a given path is empty.
package cmd
import (
	"bytes"
	"fmt"
	"io"
	"os"
	"path/filepath"
	"strings"
	"text/template"
	"time"
	"github.com/spf13/viper"
)
var funcMap template.FuncMap
var projectPath = ""
var inputPath = ""
var projectBase = ""
var testWd = ""
var cmdDirs = []string{"cmd", "cmds", "command", "commands"}
func init() {
	funcMap = template.FuncMap{
		"comment": commentifyString,
	}
}
func er(msg interface{}) {
	fmt.Println("Error:", msg)
	os.Exit(-1)
}
func exists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
func ProjectPath() string {
	if projectPath == "" {
		guessProjectPath()
	}
	return projectPath
}
func getWd() (string, error) {
	if testWd == "" {
		return os.Getwd()
	}
	return testWd, nil
}
func guessCmdDir() string {
	guessProjectPath()
	if b, _ := isEmpty(projectPath); b {
		return "cmd"
	}
	files, _ := filepath.Glob(projectPath + string(os.PathSeparator) + "c*")
	for _, f := range files {
		for _, c := range cmdDirs {
			if f == c {
				return c
			}
		}
	}
	return "cmd"
}
func guessImportPath() string {
	guessProjectPath()
	if !strings.HasPrefix(projectPath, getSrcPath()) {
		er("Cobra only supports project within $GOPATH")
	}
	return filepath.ToSlash(filepath.Clean(strings.TrimPrefix(projectPath, getSrcPath())))
}
func getSrcPath() string {
	return filepath.Join(os.Getenv("GOPATH"), "src") + string(os.PathSeparator)
}
func projectName() string {
	return filepath.Base(ProjectPath())
}
func guessProjectPath() {
	if inputPath == "" {
		x, err := getWd()
		if err != nil {
			er(err)
		}
		base := filepath.Base(x)
		for _, c := range cmdDirs {
			if base == c {
				projectPath = filepath.Dir(x)
				return
			}
		}
		if projectPath == "" {
			projectPath = filepath.Clean(x)
			return
		}
	}
	srcPath := getSrcPath()
	if strings.ContainsRune(inputPath, os.PathSeparator) {
		if filepath.IsAbs(inputPath) || filepath.HasPrefix(inputPath, string(os.PathSeparator)) {
			projectPath = filepath.Clean(inputPath)
			return
		}
		count := strings.Count(inputPath, string(os.PathSeparator))
		switch count {
		case 1:
			projectPath = filepath.Join(srcPath, "github.com", inputPath)
			return
		case 2:
			projectPath = filepath.Join(srcPath, inputPath)
			return
		default:
			er("Unknown directory")
		}
	} else {
		if projectBase == "" {
			x, err := getWd()
			if err == nil {
				projectPath = filepath.Join(x, inputPath)
				return
			}
			er(err)
		} else {
			projectPath = filepath.Join(srcPath, projectBase, inputPath)
			return
		}
	}
}