edit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Builder = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "builder {builder}",
	Desc:   "Edit builder file",
	Action: "Edit",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompBuilder)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := fmt.Sprintf("%s.yaml", ctx.Arg(0))
		path := config.GetDir("builders", name)
		return Do(path, config.DefaultBuilder, name, func(s string) error {
			data := []byte(s)
			var builder core.Builder
			err := yaml.Unmarshal(data, &builder)
			if err != nil {
				return errors.Trace(err, "parse yaml")
			}
			return builder.Validate()
		})
	},
})
View Source
var Config = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "config",
	Desc:   "Edit config file",
	Action: "Edit",

	RunNoContext: func() error {
		path := config.GetDir("config.toml")
		return Do(path, config.DefaultConfig, "config.toml", func(s string) error {
			data := []byte(s)
			var cfg config.Config
			err := toml.Unmarshal(data, &cfg)
			return errors.Trace(err, "parse toml")
		})
	},
})
View Source
var Job = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "job {job}",
	Desc:   "Edit job file",
	Action: "Edit",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompJob)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := fmt.Sprintf("%s.sh", ctx.Arg(0))
		path := config.GetDir("jobs", name)
		return Do(path, "", name, nil)
	},
})
View Source
var Remote = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "remote {remote}",
	Desc:   "Edit remote file",
	Action: "Edit",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompRemote)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := fmt.Sprintf("%s.toml", ctx.Arg(0))
		path := config.GetDir("remotes", name)
		return Do(path, config.DefaultRemote, name, func(s string) error {
			data := []byte(s)
			var remote core.Remote
			err := toml.Unmarshal(data, &remote)
			if err != nil {
				return errors.Trace(err, "parse toml")
			}
			err = validate.Do(&remote)
			return errors.Trace(err, "validate fields")
		})
	},
})
View Source
var Workflow = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "workflow {workflow}",
	Desc:   "Edit workflow file",
	Action: "Edit",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompWorkflow)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := fmt.Sprintf("%s.yaml", ctx.Arg(0))
		path := config.GetDir("workflows", name)
		return Do(path, config.DefaultWorkflow, name, func(s string) error {
			data := []byte(s)
			var wf core.Workflow
			err := yaml.Unmarshal(data, &wf)
			if err != nil {
				return errors.Trace(err, "parse yaml")
			}
			return validate.Do(&wf)
		})
	},
})

Functions

func Do

func Do(path, defaultContent, name string, validate func(s string) error) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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