Help us shape the future of Go! Take the 2026 Go Developer Survey

template

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Create = app.Register(&app.Command[CreateFlags, app.Empty]{
	Use:    "template [--path path] {name}",
	Desc:   "Create a template",
	Action: "Create",

	Prepare: func(cmd *cobra.Command, flags *CreateFlags) {
		cmd.Flags().StringVarP(&flags.Path, "path", "", "", "target path")
		cmd.Args = cobra.ExactArgs(1)
	},

	Run: func(ctx *app.Context[CreateFlags, app.Empty]) error {
		var err error
		path := ctx.Flags.Path
		if path == "" {
			path, err = os.Getwd()
			if err != nil {
				return errors.Trace(err, "getwd")
			}
		}

		term.PrintOperation("Finding files")
		files, err := core.FindTemplateFiles(path)
		if err != nil {
			return err
		}
		if len(files) == 0 {
			return errors.New("no file to write")
		}

		name := ctx.Arg(0)
		return core.CreateTemplate(name, files)
	},
})
View Source
var Delete = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "template {name}",
	Desc:   "Delete a template",
	Action: "Delete",

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

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := ctx.Arg(0)
		return core.DeleteTemplate(name)
	},
})
View Source
var Home = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:  "template {name}",
	Desc: "Enter a template",

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

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := ctx.Arg(0)
		path, err := core.GetTemplate(name)
		if err != nil {
			return err
		}
		fmt.Println(path)
		return nil
	},
})

Functions

This section is empty.

Types

type CreateFlags

type CreateFlags struct {
	Path string
}

Jump to

Keyboard shortcuts

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