Exemplo n.º 1
0
Arquivo: main.go Projeto: go-stay/stay
	"github.com/metakeule/config"
)

var (
	cfg               = config.MustNew("config", "1.10.0", "a multiplattform and multilanguage configuration tool")
	optionProgram     = cfg.NewString("program", "the program where the options belong to (must be a config compatible program)", config.Required, config.Shortflag('p'))
	optionLocations   = cfg.NewBool("locations", "the locations where the options are currently set", config.Shortflag('l'))
	cfgSet            = cfg.MustCommand("set", "set an option").Skip("locations")
	optionSetKey      = cfgSet.NewString("option", "the option that should be set", config.Required, config.Shortflag('o'))
	optionSetValue    = cfgSet.NewString("value", "the value the option should be set to", config.Required, config.Shortflag('v'))
	optionSetPathType = cfgSet.NewString("type", "the type of the config path where the value should be set. valid values are global,user and local", config.Shortflag('t'), config.Required)
	cfgGet            = cfg.MustCommand("get", "get the current value of an option").Skip("locations")
	optionGetKey      = cfgGet.NewString("option", "the option that should be get, if not set, all options that are set are returned", config.Shortflag('o'))
	cfgPath           = cfg.MustCommand("path", "show the paths for the configuration files").Skip("locations")
	optionPathType    = cfgPath.NewString("type", "the type of the config path. valid values are global,user,local and all", config.Shortflag('t'), config.Default("all"))
)

func GetVersion(cmdpath string) (string, error) {
	cmd := exec.Command(cmdpath, "--version")
	out, err := cmd.Output()
	if err != nil {
		return "", err
	}
	// fmt.Printf("version: %#v\n", string(out))
	v := strings.Split(strings.TrimSpace(string(out)), " ")
	if len(v) != 3 {
		return "", fmt.Errorf("%s --version returns invalid result: %#v", cmdpath, string(out))
	}
	return strings.TrimSpace(v[2]), nil
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: go-stay/stay
	"github.com/metakeule/config"
	"github.com/metakeule/scaffold"
	"lib"
	"os"
	"path/filepath"
	"strings"
)

var (
	name        = "stay"
	version     = "1.0"
	description = `stay is a tool that complements the stay library specification for Go libraries
as defined at http://github.com/go-stay/spec`

	cfg    = config.MustNew(name, version, description)
	argDir = cfg.NewString("dir", "directory path of the library package", config.Default("."), config.Shortflag('d'))

	checkCmd       = cfg.MustCommand("check", "checks if a package conforms to the spec")
	argSkipImports = checkCmd.NewBool("noimports", "don't complain if there are non conforming imports", config.Default(false))
	argSkipExports = checkCmd.NewBool("noexports", "don't complain if there are non conforming exported symbols", config.Default(false))
	argSkipParams  = checkCmd.NewBool("noparams", "don't complain if there are non conforming parameters", config.Default(false))
	argSkipNames   = checkCmd.NewBool("nonames", "don't complain if there are non conforming names of exported symbols", config.Default(false))

	createCmd       = cfg.MustCommand("create", "creates a package structure for a library")
	argPkgName      = createCmd.NewString("name", "name of the package", config.Required)
	argPkgIsCommand = createCmd.NewBool("command", "flag telling that the package contains a command", config.Default(false))
)

func check(dir string) (err error) {
	var options []lib.Option
	if argSkipParams.Get() {
Exemplo n.º 3
0
Arquivo: main.go Projeto: go-stay/stay
	"github.com/metakeule/config"
	"github.com/metakeule/scaffold"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
)

var (
	cfg = config.MustNew("scaffold", "1.4",
		`scaffold creates files and directories based on a template and json input.
Complete documentation at http://godoc.org/gopkg.in/metakeule/scaffold.v1`)

	templateArg     = cfg.NewString("template", "the file where the template resides", config.Required, config.Shortflag('t'))
	templatePathArg = cfg.NewString("path", "the path to look for template files, the different directories must be separated with a colon (:)")
	dirArg          = cfg.NewString("dir", "directory that is the target/root of the file creations", config.Default("."))
	verboseArg      = cfg.NewBool("verbose", "show verbose messages", config.Default(false), config.Shortflag('v'))
	headCmd         = cfg.MustCommand("head", "shows the head section of the given template").Skip("dir")
	testCmd         = cfg.MustCommand("test", "makes a test run without creating any files")

	FileNotFound = errors.New("template file not found")
)

func findInDir(path, file string) bool {
	if verboseArg.Get() {
		println("looking for ", filepath.Join(path, file))
	}
	fullPath, err := filepath.Abs(filepath.Join(path, file))
	if err != nil {
		return false
	}
Exemplo n.º 4
0
Arquivo: main.go Projeto: go-stay/stay
package main

import (
	"fmt"
	"os"

	"github.com/metakeule/config"
)

var (
	cfg = config.MustNew("example", "0.0.1", "example is an example app for config")

	extra  = cfg.NewBool("extra", "extra is just a first \ntest option as a bool    ", config.Shortflag('x'), config.Default(false))
	second = cfg.NewString("second", "second is the second option and a string", config.Shortflag('s'), config.Default("2nd"))

	project = cfg.MustCommand("project", "example project sub command")

	projectName = project.NewString("name", "name of the project")
)

func main() {

	err := cfg.Run()

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
	}

	if extra.Get() {
		fmt.Println("extra is true")
	} else {