cmd

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2020 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// DefaultConfFile default configuration file path
	DefaultConfFile = "gbb.json"
)

Variables

View Source
var RootCmd = &cobra.Command{
	Use: "gbb",
	Long: `Go project compilation assistant.
Copyright (c) 2016-2020, voidint. All rights reserved.`,

	Run: func(cmd *cobra.Command, args []string) {
		begin := time.Now()

		if gopts.ConfigFile == DefaultConfFile {
			gopts.ConfigFile = filepath.Join(wd, "gbb.json")
		}

		if !util.FileExist(gopts.ConfigFile) {
			genConfigFile(gopts.ConfigFile)
			return
		}
		conf, err := config.Load(gopts.ConfigFile)
		if err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
			os.Exit(-1)
			return
		}
		conf.Debug = gopts.Debug
		conf.All = gopts.All

		if conf.Version != Version {
			gt, err := util.VersionGreaterThan(Version, conf.Version)
			if err != nil {
				fmt.Fprintln(os.Stderr, err.Error())
				os.Exit(-1)
				return
			}

			if gt {
				fmt.Printf("Warning: The gbb.json file needs to be upgraded.\n\n")
				genConfigFile(gopts.ConfigFile)
			} else {

				fmt.Printf("Warning: This program needs to be upgraded by `go get -u -v github.com/voidint/gbb`\n\n")
			}
			return
		}

		defer func() {
			fmt.Printf("Time Used: %.2fs\n", time.Now().Sub(begin).Seconds())
		}()

		if err := tool.Build(conf, wd); err != nil {
			fmt.Fprintln(os.Stderr, err.Error())
			os.Exit(-1)
			return
		}
	},
}

RootCmd represents the base command when called without any subcommands

View Source
var (
	// Version 版本号
	Version = "0.6.1"
)

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

type CleanOptions added in v0.6.1

type CleanOptions struct {
	I bool // go clean -i
	N bool // go clean -n
	R bool // go clean -r
	X bool // go clean -x
}

CleanOptions clean sub-command options

type GlobalOptions added in v0.6.1

type GlobalOptions struct {
	All        bool
	Debug      bool
	ConfigFile string
}

GlobalOptions global options

Jump to

Keyboard shortcuts

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