๐Ÿข cmd [](https://godoc.org/github.com/RTradeLtd/cmd) [](https://travis-ci.com/RTradeLtd/cmd) [](https://codecov.io/gh/RTradeLtd/cmd) [](https://goreportcard.com/report/github.com/RTradeLtd/cmd)

February 29, 2020 ยท View on GitHub

Deprecated: This is no longer maintained, and all projects will eventually be migrated to urfave/cli. It is recommend that you use urfave/cli as opposed to cmd as it is a much more extensible, and feature complete system.

๐Ÿข cmd GoDoc Build Status codecov Go Report Card

Package cmd provides a microframework for building CLI tools integrated with Temporal configuration.

It is extremely lightweight, with only a single dependency - package config, which contains Temporal's configuration definitions.

Usage


import (
  "github.com/RTradeLtd/cmd"
  "github.com/RTradeLtd/config"
)

// define commands
var commands = map[string]cmd.Cmd{
  "api": cmd.Cmd{
    Blurb:       "start Temporal api server",
    Description: "Start the API service used to interact with Temporal. Run with DEBUG=true to enable debug messages.",
    Action: func(cfg config.TemporalConfig, args map[string]string) { /* ... */ },
  },
  "queue": cmd.Cmd{
    Blurb:         "execute commands for various queues",
    Description:   "Interact with Temporal's various queue APIs",
    ChildRequired: true,
    Children: map[string]cmd.Cmd{
      "ipns-entry": cmd.Cmd{
        Blurb:       "IPNS entry creation queue",
        Description: "Listens to requests to create IPNS records",
        Action: func(cfg config.TemporalConfig, args map[string]string) { /* ... */ },
      },
    },
  },
}

// entrypoint
func main() {
  // create app
  temporal := cmd.New(commands, cmd.Config{
    Name:     "Temporal",
    ExecName: "temporal",
    Version:  Version,
    Desc:     "Temporal is an easy-to-use interface into distributed and decentralized storage technologies for personal and enterprise use cases.",
  })

  // run no-config commands. exit if a command was executed
  if exit := temporal.PreRun(os.Args[1:]); exit == cmd.CodeOK {
    os.Exit(0)
  }

  // load config
  tCfg, _ := config.LoadConfig("path/to/config")

  // load arguments
  flags := map[string]string{ /* ... */ }

  // execute
  os.Exit(temporal.Run(*tCfg, flags, os.Args[1:]))
}