Coder Social home page Coder Social logo

go-commander's Introduction

go-commander

view examples

go-commander

Quick start

package main

import (
	"flag"
	"fmt"
	commander2 "github.com/pefish/go-commander"
	go_config "github.com/pefish/go-config"
	"log"
)


type TestSubCommand struct {

}

func (t TestSubCommand) DecorateFlagSet(flagSet *flag.FlagSet) error {
	flagSet.String("test", "haha", "")
	return nil
}

func (t TestSubCommand) Start() error {
	fmt.Println(go_config.Config.MustGetString("test"))
	fmt.Println(go_config.Config.MustGetString("testtest"))
	return nil
}

func main() {
	commander := commander2.NewCommander("test", "v0.0.1", "")
	commander.RegisterSubcommand("test", TestSubCommand{})
	commander.RegisterDefaultSubcommand(TestSubCommand{})
	commander.RegisterFnToSetCommonFlags(func(flagSet *flag.FlagSet) {
		flagSet.String("testtest", "", "path to config file")
	})
	err := commander.Run()
	if err != nil {
		log.Fatal(err)
	}
}
go run ./_example/main.go -test=76573 -testtest=11

Document

doc

默认包含的选项

  • version。打印版本信息
  • log-level。设置日志打印级别
  • config。设置配置文件的位置,默认值是GO_CONFIG环境变量。(命令行选项 > 环境变量 > 配置文件)
  • secret-file。设置secret配置文件的位置,默认值是GO_SECRET环境变量。
  • enable-pprof。是否启用pprof分析工具
  • pprof-address。pprof分析工具的监听地址

支持3中配置输入:

  1. 命令行选项
  2. 环境变量
  3. 配置文件

优先级是:命令行选项 > 环境变量 > 配置文件 > 默认值

注意:环境变量传递配置项时,-使用_代替,例如TEST_TEST将会代替test-test,也会代替test_test

Security Vulnerabilities

If you discover a security vulnerability, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

License

This project is licensed under the Apache License.

go-commander's People

Contributors

pefish avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.