Пример #1
0
func (command *Xlsx2Yaml) Execute(context *console.Context) error {
	if command.filePath == "" {
		if context.FlagSet().NArg() == 1 {
			command.filePath = context.FlagSet().Arg(0)
		} else {
			return fmt.Errorf("need input file")
		}
	}
	rawArray, err := kmgExcel.XlsxFile2Array(command.filePath)
	if err != nil {
		return err
	}
	output, err := command.formatOutput(rawArray)
	if err != nil {
		return err
	}
	outByte, err := kmgYaml.Marshal(output)
	if err != nil {
		return err
	}
	_, err = context.Stdout.Write(outByte)
	if err != nil {
		return err
	}
	return nil
}
Пример #2
0
func (command *GoTest) findRootPath(context *console.Context) (root string, err error) {
	if context.FlagSet().NArg() == 1 {
		command.moduleName = context.FlagSet().Arg(0)
	}
	if command.dir != "" {
		root = command.dir
		exist, err := kmgFile.FileExist(root)
		if err != nil {
			return "", err
		}
		if !exist {
			return "", fmt.Errorf("[GoTest] dir path:[%s] not found", root)
		}
		return root, nil
	}
	if command.moduleName != "" {
		//TODO 处理多个GOPATH的问题,从GOPATH里面找到这个模块
		root = filepath.Join(command.gopath, "src", command.moduleName)
		exist, err := kmgFile.FileExist(root)
		if err != nil {
			return "", err
		}
		if !exist {
			return "", fmt.Errorf("[GoTest] module name:[%s] not found", command.moduleName)
		}
		return root, nil
	}
	if root == "" {
		root, err = os.Getwd()
		if err != nil {
			return
		}
	}
	return
}
Пример #3
0
func (command *GoCrossCompile) Execute(context *console.Context) (err error) {
	if len(context.Args) <= 2 {
		return fmt.Errorf("need gofile parameter")
	}
	targetFile := context.FlagSet().Arg(0)
	kmgc, err := kmgConfig.LoadEnvFromWd()
	if err != nil {
		return
	}
	targetName := kmgFile.GetFileBaseWithoutExt(targetFile)
	if command.outputPath == "" {
		command.outputPath = filepath.Join(kmgc.ProjectPath, "bin")
	}
	for _, target := range kmgc.CrossCompileTarget {
		fileName := targetName + "_" + target.GetGOOS() + "_" + target.GetGOARCH()
		if target.GetGOOS() == "windows" {
			fileName = fileName + ".exe"
		}
		outputFilePath := filepath.Join(command.outputPath, fileName)
		cmd := kmgCmd.NewStdioCmd(context, "go", "build", "-o", outputFilePath, targetFile)
		kmgCmd.SetCmdEnv(cmd, "GOOS", target.GetGOOS())
		kmgCmd.SetCmdEnv(cmd, "GOARCH", target.GetGOARCH())
		kmgCmd.SetCmdEnv(cmd, "GOPATH", kmgc.GOPATHToString())
		err = cmd.Run()
		if err != nil {
			return err
		}
	}
	return
}