cmdconfig

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 2 Imported by: 0

README

cmdconfig

package main

import (
	cmdconfig "github.com/PengShaw/go-common/cmd-config"
	"github.com/spf13/cobra"
	"os"
)

var rootCmd = &cobra.Command{
	Use:   "root",
	Short: "root cmd",
}

var subCmd = &cobra.Command{
	Use:   "sub",
	Short: "sub cmd",
	Run: func(cmd *cobra.Command, args []string) {
		println("run sub cmd")
	},
}

type config struct {
	host string
}

func main() {
	cmdconfig.SetConfigFlag(rootCmd)
	rootCmd.AddCommand(subCmd)

	var c config
	if err := cmdconfig.GetConfig(&c); err != nil {
		os.Exit(1)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig

func GetConfig(configs interface{}) error

GetConfig to struct, configs should be the point of config struct

func SetConfigFlag

func SetConfigFlag(cmd *cobra.Command)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL