Exemple #1
0
func NewLoggerFromFlags() Logger {
	args := cli.Parse()

	var silent, verbose bool

	for _, o := range args.Options {
		switch o {
		case "-s":
			silent = true
		case "-v":
			verbose = true
		}
	}

	level := LogNormal
	if silent {
		level = LogSilent
	} else if verbose {
		level = LogVerbose
	}

	return NewConsoleLogger(level)
}
Exemple #2
0
func main() {
	defer func() {
		p := recover()
		if p != nil {
			if err, ok := p.(error); ok {
				fmt.Println(err.Error())
				os.Exit(1)
			}

			fmt.Println(p)
			os.Exit(1)
		}
	}()

	args := cli.Parse()
	if len(args.Inputs) == 0 {
		Panic("Usage: %s <cmd> <args>\n", args.Cmd)
	}

	logger := log.NewLoggerFromFlags()

	switch args.Cmd {
	case "pack":
		if len(args.Inputs) < 1 {
			Panic("Usage: %s pack <pkg-path>\n", args.Cmd)
		}

		pkgname := args.Inputs[0]
		paths := utils.NewPaths(pkgname)

		outfile, err := paths.CreateOutputFile()
		if err != nil {
			panic(err)
		}
		defer outfile.Close()

		logger.Logv("Packing %s", pkgname)

		packer := pack.NewPackCmd(logger, paths, outfile)
		err = packer.Run()
		if err != nil {
			panic(err)
		}

		logger.Logv("Written %s", paths.GoblFilename)
	case "install":
		if len(args.Inputs) < 1 {
			Panic("Usage: %s install <gobl-file>\n", args.Cmd)
		}

		fname := args.Inputs[0]
		logger.Logv("Installing %s", fname)

		installer := install.NewInstallCmd(logger, fname)
		err := installer.Run()
		if err != nil {
			panic(err)
		}

		logger.Logv("Installed %s", fname)
	default:
		panic("Unknown cmd: " + args.Cmd)
	}
}