mage

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cli.Command{
	Name:  "mage",
	Usage: "mage install",
	Action: func(ctx *cli.Context) error {
		cmds := exec.Command("mage", "-l")
		cmds.Stderr = os.Stderr
		out, err := cmds.Output()
		if err != nil {
			return err
		}

		scan := bufio.NewScanner(bytes.NewBuffer(out))

		var targets []string
		for scan.Scan() {
			line := scan.Text()
			if strings.HasPrefix(line, "Targets:") {
				continue
			}
			line = strings.TrimSpace(line)
			targets = append(targets, line)
		}

		templates := &promptui.SelectTemplates{
			Label:    "{{.}}",
			Active:   promptui.IconSelect + " {{.}}",
			Inactive: "  {{.|faint}}",
			Selected: promptui.IconGood + " {{.}}",
		}

		size := maxSize
		if len(targets) < size {
			size = len(targets)
		}

		prompt := promptui.Select{
			Label:             "Select a mage target:",
			Items:             targets,
			Templates:         templates,
			HideHelp:          true,
			Size:              size,
			Searcher:          searcher(targets),
			StartInSearchMode: true,
		}

		_, result, err := prompt.Run()

		if err != nil {
			return err
		}

		result = strings.Split(result, " ")[0]

		fmt.Printf("mage %s\n", result)

		os.Args = append(os.Args, result)
		os.Exit(mage.Main())
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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