run

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Workflow = app.Register(&app.Command[WorkflowFlags, app.Empty]{
	Use:    "workflow [-y] [-c] {workflow}",
	Desc:   "Run workflow",
	Action: "Run",

	Prepare: func(cmd *cobra.Command, flags *WorkflowFlags) {
		cmd.Flags().BoolVarP(&flags.Current, "current", "c", false, "run workflow on current repo")
		cmd.Flags().BoolVarP(&flags.Edit, "edit", "e", false, "edit repo to run")
		cmd.Flags().StringVarP(&flags.LogPath, "log-path", "", "", "log file path")

		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompWorkflow)
	},

	Run: func(ctx *app.Context[WorkflowFlags, app.Empty]) error {
		wf, err := core.GetWorkflow(ctx.Arg(0))
		if err != nil {
			return err
		}
		store, err := core.NewRepositoryStorage()
		if err != nil {
			return err
		}
		store.ReadOnly()

		if ctx.Flags.Current {
			return workflowRunCurrent(store, wf)
		}

		if wf.Select == nil {
			term.Print("nothing to do")
			return nil
		}

		items, err := wf.Select.Match(store)
		if err != nil {
			return err
		}
		if len(items) == 0 {
			term.Print("no repo selected")
			return nil
		}
		if ctx.Flags.Edit {
			items, err = term.EditItems(config.Get().Editor, items,
				func(item *core.WorkflowMatchItem) string {
					return item.Path
				})
			if err != nil {
				return err
			}
		}

		repoWord := english.Plural(len(items), "repo", "repos")
		term.ConfirmExit("Do you want to run workflow %s for %s", ctx.Arg(0), repoWord)

		return workflowRun(ctx, wf.Jobs, items)
	},
})

Functions

This section is empty.

Types

type WorkflowFlags

type WorkflowFlags struct {
	Edit bool

	Current bool

	LogPath string
}

Jump to

Keyboard shortcuts

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