Exemplo n.º 1
0
func main() {

	opts := optparse.New("Usage: dynamodb-marshal file1.go [file2.go ...]",
		"dynamodb-marshal 0.0.1")

	force := opts.Bool([]string{"-f", "--force"},
		"overwrite existing marshal files")

	os.Args[0] = "dynamodb-marshal"
	files := opts.Parse(os.Args)

	if len(files) == 0 {
		opts.PrintUsage()
		runtime.Exit(0)
	}

	log.AddConsoleLogger()
	for _, file := range files {
		path, err := filepath.Abs(file)
		if err != nil {
			runtime.StandardError(err)
		}
		parseFile(path, *force)
	}

	log.Wait()

}
Exemplo n.º 2
0
Arquivo: main.go Projeto: tav/bolt
func (r Registry) Main(ctx *Context, args []string) {
	opts := optparse.Parser("Usage: bolt <command-1> <command-2> ... [options]\n", "bolt 0.1")
	opts.String([]string{"--boltfile"}, "",
		"use the Boltfile at the given path", "PATH")
	opts.String([]string{"--gen"}, "",
		"save the generated executable at the given path", "PATH")
	opts.Bool([]string{"--recompile"}, false,
		"recompile the generated executable instead of using cached builds")
	noConsoleLog := opts.BoolConfig("no-console-log", false,
		"disable logging to the console [false]")
	completions := append(ctx.completions, r.Keys()...)
	opts.Completer = optparse.ListCompleter(completions...)
	opts.Parse(args)
	if len(args) == 1 {
		listing := r.Listing()
		fmt.Print(listing)
		runtime.Exit(0)
	}
	if !*noConsoleLog {
		log.AddConsoleLogger()
	}
	buf := &bytes.Buffer{}
	yaml.NormaliseID(buf, args[1])
	cmd := buf.String()
	if task, ok := r[cmd]; ok {
		task.Func.Call([]reflect.Value{reflect.ValueOf(ctx)})
	} else {
		fmt.Printf("Task not found:\n\n\t%s\n\n", args[1])
		runtime.Exit(1)
	}
}
Exemplo n.º 3
0
func main() {

	opts := optparse.Parser("Usage: genapi [options]", "0.1")

	root := opts.String(
		[]string{"-r", "--root"}, "../src/espra",
		"path to the root package directory for the app", "PATH")

	ignoreList := opts.String(
		[]string{"-i", "--ignore"}, "api.go html.go",
		"space-separated list of files/subdirectories to ignore", "LIST")

	digestFile := opts.String(
		[]string{"-d", "--digest"}, "../etc/app/version.digest",
		"path to write the digest of the API version", "PATH")

	os.Args[0] = "genapi"
	opts.Parse(os.Args)
	log.AddConsoleLogger()

	ignore := strings.Split(*ignoreList, " ")
	for i, path := range ignore {
		ignore[i] = filepath.Join(*root, path)
	}

	pkgpath := strings.Split(*root, "/")
	pkgname := pkgpath[len(pkgpath)-1]

	if err := parseDirectory(pkgname, pkgname, *root, ignore); err != nil {
		runtime.StandardError(err)
	}

	for _, method := range methods {
		log.Info("%#v", method)
	}
	log.Wait()

	_ = *digestFile

}
Exemplo n.º 4
0
// DefaultOpts processes default runtime command line options.
func DefaultOpts(name string, opts *optparse.Parser, argv []string, autoExit bool) (bool, string, string, string, bool) {

	var (
		configPath        string
		instanceDirectory string
		err               error
	)

	debug := opts.Bool([]string{"-d", "--debug"},
		"enable debug mode")

	genConfig := opts.Bool([]string{"-g", "--gen-config"},
		"show the default yaml config")

	runDirectory := opts.StringConfig("run-dir", "run",
		"the path to the run directory to store locks, pid files, etc. [run]")

	logDirectory := opts.StringConfig("log-dir", "log",
		"the path to the log directory [log]")

	logRotate := opts.StringConfig("log-rotate", "never",
		"specify one of 'hourly', 'daily' or 'never' [never]")

	noConsoleLog := opts.BoolConfig("no-console-log",
		"disable server requests being logged to the console [false]")

	extraConfig := opts.StringConfig("extra-config", "",
		"path to a YAML config file with additional options")

	// Parse the command line options.
	args := opts.Parse(argv)

	// Print the default YAML config file if the ``-g`` flag was specified.
	if *genConfig {
		opts.PrintDefaultConfigFile(name)
		Exit(0)
	}

	// Enable the console logger early.
	if !*noConsoleLog {
		log.AddConsoleLogger()
	}

	// Assume the parent directory of the config as the instance directory.
	if len(args) >= 1 {
		var statInfo os.FileInfo
		configPath, err = filepath.Abs(filepath.Clean(args[0]))
		if err != nil {
			StandardError(err)
		}
		statInfo, err = os.Stat(configPath)
		if err != nil {
			StandardError(err)
		}
		if statInfo.IsDir() {
			instanceDirectory = configPath
			Profile = "default"
		} else {
			err = opts.ParseConfig(configPath, os.Args)
			if err != nil {
				StandardError(err)
			}
			instanceDirectory, _ = filepath.Split(configPath)
			Profile = strings.Split(filepath.Base(configPath), ".")[0]
		}
	} else {
		if autoExit {
			opts.PrintUsage()
			Exit(0)
		}
		return false, "", "", "", true
	}

	// Load the extra config file with additional options if one has been
	// specified.
	if *extraConfig != "" {
		extraConfigPath, err := filepath.Abs(filepath.Clean(*extraConfig))
		if err != nil {
			StandardError(err)
		}
		extraConfigPath = JoinPath(instanceDirectory, extraConfigPath)
		err = opts.ParseConfig(extraConfigPath, os.Args)
		if err != nil {
			StandardError(err)
		}
	}

	// Create the log directory if it doesn't exist.
	logPath := JoinPath(instanceDirectory, *logDirectory)
	err = os.MkdirAll(logPath, 0755)
	if err != nil {
		StandardError(err)
	}

	// Create the run directory if it doesn't exist.
	runPath := JoinPath(instanceDirectory, *runDirectory)
	err = os.MkdirAll(runPath, 0755)
	if err != nil {
		StandardError(err)
	}

	// Setup the file and console logging.
	var rotate int

	switch *logRotate {
	case "daily":
		rotate = log.RotateDaily
	case "hourly":
		rotate = log.RotateHourly
	case "never":
		rotate = log.RotateNever
	default:
		Error("Unknown log rotation format %q", *logRotate)
	}

	_, err = log.AddFileLogger(name, logPath, rotate, log.InfoLog)
	if err != nil {
		Error("Couldn't initialise logfile: %s", err)
	}

	_, err = log.AddFileLogger("error", logPath, rotate, log.ErrorLog)
	if err != nil {
		Error("Couldn't initialise logfile: %s", err)
	}

	// Initialise the runtime -- which will run the process on multiple
	// processors if possible.
	Init()

	// Initialise the process-related resources.
	if Platform != "windows" {
		InitProcess(name, runPath)
	}

	return *debug, instanceDirectory, runPath, logPath, false

}
Exemplo n.º 5
0
func main() {

	opts := optparse.Parser("Usage: html2domly [options]", "v")

	outputFile := opts.String([]string{"-o", "--output"}, "../coffee/templates.coffee", "coffeescript file to compile to", "PATH")
	templatesSrcDir := opts.String([]string{"-i", "--input"}, "../etc/domly", "template source directory", "PATH")
	printJSON := opts.Bool([]string{"--print"}, false, "Print the JSON nicely to the output logger")

	os.Args[0] = "html2domly"
	opts.Parse(os.Args)

	log.AddConsoleLogger()

	var (
		data      []byte
		err       error
		prettyStr string
		basename  string
		pretty    bytes.Buffer
	)

	dir, err := os.Open(*templatesSrcDir)
	if err != nil {
		runtime.StandardError(err)
	}
	defer dir.Close()

	out, err := os.Create(*outputFile)
	if err != nil {
		runtime.StandardError(err)
	}
	defer out.Close()

	names, err := dir.Readdirnames(0)
	if err != nil {
		runtime.StandardError(err)
	}

	out.Write([]byte("define 'templates', (exports, root) ->\n"))

	for _, name := range names {
		if strings.HasSuffix(name, ".html") {
			basename = strings.TrimSuffix(name, ".html")
		} else {
			log.Error("file %v does not end in .html", name)
			continue
		}

		templatePath := filepath.Join(*templatesSrcDir, name)
		data, err = ui.ParseTemplate(templatePath)
		if err != nil {
			log.StandardError(err)
		} else {

			err := json.Indent(&pretty, data, ">", "  ")
			if err != nil {
				log.StandardError(err)
				log.Info("%v", data)
			} else if *printJSON {
				prettyStr = pretty.String()
				pretty.Reset()
				log.Info("%v", prettyStr)
			}
			out.Write([]byte(fmt.Sprintf("  exports['%s'] = `%s`\n", basename, data)))
			log.Info("compiled '%s'", name)
		}

	}
	out.Write([]byte("  return"))

	outPath, _ := filepath.Abs(*outputFile)
	log.Info("compiled domly written to: %v", outPath)

	log.Wait()

}