File: command.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (2)
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
package command

import (
	"fmt"
	"io"
	"strings"

	"github.com/onsi/ginkgo/v2/formatter"
	"github.com/onsi/ginkgo/v2/types"
)

type Command struct {
	Name          string
	Flags         types.GinkgoFlagSet
	Usage         string
	ShortDoc      string
	Documentation string
	DocLink       string
	Command       func(args []string, additionalArgs []string)
}

func (c Command) Run(args []string, additionalArgs []string) {
	args, err := c.Flags.Parse(args)
	if err != nil {
		AbortWithUsage(err.Error())
	}

	c.Command(args, additionalArgs)
}

func (c Command) EmitUsage(writer io.Writer) {
	fmt.Fprintln(writer, formatter.F("{{bold}}"+c.Usage+"{{/}}"))
	fmt.Fprintln(writer, formatter.F("{{gray}}%s{{/}}", strings.Repeat("-", len(c.Usage))))
	if c.ShortDoc != "" {
		fmt.Fprintln(writer, formatter.Fiw(0, formatter.COLS, c.ShortDoc))
		fmt.Fprintln(writer, "")
	}
	if c.Documentation != "" {
		fmt.Fprintln(writer, formatter.Fiw(0, formatter.COLS, c.Documentation))
		fmt.Fprintln(writer, "")
	}
	if c.DocLink != "" {
		fmt.Fprintln(writer, formatter.Fi(0, "{{bold}}Learn more at:{{/}} {{cyan}}{{underline}}http://onsi.github.io/ginkgo/#%s{{/}}", c.DocLink))
		fmt.Fprintln(writer, "")
	}
	flagUsage := c.Flags.Usage()
	if flagUsage != "" {
		fmt.Fprintf(writer, formatter.F(flagUsage))
	}
}