File: root.go

package info (click to toggle)
golang-github-ivanpirog-coloredcobra 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 108 kB
  • sloc: makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cmd

import (
	"fmt"
	"os"

	"github.com/spf13/cobra"

	cc "github.com/ivanpirog/coloredcobra"
)

var rootCmd = &cobra.Command{
	Use:   "example",
	Short: "This is an example of using ColoreCobra library.",
	Long: "This is just an example of using the ColoredCobra library. \n" +
		"Project home: https://github.com/ivanpirog/coloredcobra",
	Example: "There is a simple example of the Examples section.\n" +
		"Just try commands:\n\n" +
		"example help\n" +
		"example help test",
	Aliases: []string{"alias1", "alias2", "alias3"},

	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("No commands given. Run 'example help' for usage help.\n" +
			"Also try commands:\n\n" +
			"example help\n" +
			"example help test")
	},
}

var (
	// Used for flags.
	flag1 string
	flag2 string
	abc   []bool
)

func Execute() {

	cc.Init(&cc.Config{
		RootCmd:       rootCmd,
		Headings:      cc.HiCyan + cc.Bold + cc.Underline,
		Commands:      cc.HiYellow + cc.Bold,
		Aliases:       cc.Bold + cc.Italic,
		CmdShortDescr: cc.HiRed,
		Example:       cc.Italic,
		ExecName:      cc.Bold,
		Flags:         cc.Bold,
		FlagsDescr:    cc.HiRed,
		FlagsDataType: cc.Italic,
	})

	rootCmd.PersistentFlags().StringVarP(&flag1, "flag", "f", "", "some flag")
	rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
	rootCmd.PersistentFlags().StringVarP(&flag2, "license", "l", "", "name of license for the project")
	rootCmd.PersistentFlags().BoolSliceVar(&abc, "zzz", []bool{true, false}, "usage of bools")

	if err := rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}