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

play

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:    "play [-b builder] {play}",
	Desc:   "Create a playground",
	Action: "Create",

	Prepare: func(cmd *cobra.Command, flags *CreateFlags) {
		cmd.Flags().StringVarP(&flags.Builder, "builder", "b", "", "builder name")
		cmd.RegisterFlagCompletionFunc("builder", app.Comp(app.CompBuilder))

		cmd.Flags().StringSliceVarP(&flags.Template, "template", "t", nil, "template to use")
		cmd.RegisterFlagCompletionFunc("template", app.Comp(app.CompTemplate))

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

	Run: func(ctx *app.Context[CreateFlags, app.Empty]) error {
		var err error
		builder := core.DefaultBuilder
		if ctx.Flags.Builder != "" {
			builder, err = core.GetBuilder(ctx.Flags.Builder)
			if err != nil {
				return err
			}
		}

		if len(ctx.Flags.Template) > 0 {
			builder.Templates = append(builder.Templates, ctx.Flags.Template...)
		}

		rootDir := config.Get().Playground
		repo, err := core.NewLocalRepository(rootDir, ctx.Arg(0))
		if err != nil {
			return err
		}
		err = builder.Prepare(nil, repo)
		if err != nil {
			return err
		}

		err = builder.Execute()
		if err != nil {
			return err
		}

		fmt.Println(repo.Path)
		return nil
	},
})
View Source
var Delete = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "play {name}",
	Desc:   "Delete a playground",
	Action: "Delete",

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

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		rootDir := config.Get().Playground
		repo, err := core.SelectLocalRepository(rootDir, ctx.Arg(0))
		if err != nil {
			return err
		}
		term.ConfirmExit("Do you want to remove %s", repo.Path)
		return os.RemoveAll(repo.Path)
	},
})
View Source
var Home = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:  "play [name]",
	Desc: "Enter a playground",

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

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		rootDir := config.Get().Playground
		repo, err := core.SelectLocalRepository(rootDir, ctx.Arg(0))
		if err != nil {
			return err
		}
		fmt.Println(repo.Path)
		return nil
	},
})
View Source
var List = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "play",
	Desc:   "List playgrounds",
	Action: "List",

	RunNoContext: func() error {
		repos, err := list()
		if err != nil {
			return err
		}
		for _, repo := range repos {
			fmt.Println(repo.Name)
		}
		return nil
	},
})

Functions

This section is empty.

Types

type CreateFlags

type CreateFlags struct {
	Builder  string
	Template []string
}

Jump to

Keyboard shortcuts

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