run

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "run file.yml ALL|baito [baito]...",
	Short: "Run (oneshot) the given shigoto file",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(_ *cobra.Command, args []string) error {
		l := slog.New(logger.NewSlogTextHandler(os.Stdout, &logger.SlogTextOption{
			Level:           slog.LevelInfo,
			ForceColors:     true,
			ForceFormatting: true,
			PrefixRE:        regexp.MustCompile(`^(\[.*?\])\s`),
			FullTimestamp:   true,
			TimestampFormat: "2006-01-02 15:04:05",
		}))
		log := logger.WrapSlog(l)

		shigoto, err := shigoto.Load(args[0])
		if err != nil {
			return err
		}

		var selected []runner.Runner
		for _, baito := range shigoto.Baito {
			fmt.Println("Found baito:", baito.Name())

			if len(args) <= 1 {
				continue
			}

			if args[1] == "ALL" {
				selected = append(selected, baito.Commands()...)
				continue
			}

			if slices.Contains[[]string, string](args[1:], baito.Name()) {
				selected = append(selected, baito.Commands()...)
			}
		}
		fmt.Println("---")

		chain := runner.Chain(selected...)
		chain.AttachLogger(log)
		chain.Run()
		return chain.Error()
	},
}

Command launches the validate subcommand.

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