Go 命令行应用开发包:Odin

jopen 10年前

Odin 是一个 Go 语言开发包,用于帮助构建自文档的命令行应用。

支持Value类型

Value Type Basic Definition Method Pointer Defintion Method
bool DefineBoolFlag DefineBoolFlagVar
float64 DefineFloat64Flag DefineFloat64FlagVar
int DefineIntFlag DefineIntFlagVar
int64 DefineInt64Flag DefineInt64FlagVar
string DefineStringFlag DefineStringFlagVar
time.Duration DefineDurationFlag DefineDurationFlagVar
uint DefineUintFlag DefineUintFlagVar
uint64 DefineUint64Flag DefineUint64FlagVar

Flags also support aliases: aliases are always defined as a rune to limit them to one character.

FlagAlias(alias rune, flagName string) 

支持:

  • 必要参数 Required Parameters

  • 类型标志和选项解析 Typed Flag/Option Parsing

  • 标志别名 Flag Aliasing

  • 子命令 DSL 用于创建完整的 CLI 应用

示例:

package main     import (      "fmt"         "github.com/jwaldrip/odin/cli"  )     // CLI is the odin CLI  var CLI = NewCLI("0.0.1", "my cli", func(c cli.Command){      if c.Flag("gopher").Get() == true {          fmt.Println("IT IS JUST GOPHERTASTIC!!!")      } else {          fmt.Println("It is just fine")      }  })     func init(){      CLI.DefineBoolFlag("gopher", false, "is it gophertastic?")      CLI.FlagAlias('g', "gopher")  }     func main(){      CLI.Start()  }

项目主页:http://www.open-open.com/lib/view/home/1412073086640