commands

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActionsCommand = &cli.Command{
	Name:  "actions",
	Usage: "fsm actions",
	Subcommands: []*cli.Command{
		ActionsGenCommand,
		ActionsDocCommand,
	},
}
View Source
var ActionsDocCommand = &cli.Command{
	Name:  "doc",
	Usage: "generates action doc",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "output",
			Aliases:  []string{"o"},
			Usage:    "output file name",
			Required: true,
		},
		&cli.StringFlag{
			Name:     "transitions",
			Aliases:  []string{"t"},
			Usage:    "path to file with transitions",
			Required: true,
		},
	},
	Action: func(c *cli.Context) error {
		if c.IsSet("transitions") {
			path, err := filepath.Abs(c.String("transitions"))
			if err != nil {
				return err
			}

			if err := c.Set("transitions", path); err != nil {
				return cli.NewExitError(err, 1)
			}
		}

		if err := ActionDocGenerate(c.String("transitions"), c.String("output")); err != nil {
			return cli.NewExitError(err, 1)
		}

		return nil
	},
}
View Source
var ActionsGenCommand = &cli.Command{
	Name:  "gen",
	Usage: "generates fsm actions",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "template",
			Aliases:  []string{"tpl"},
			Usage:    "template for action",
			Required: true,
		},
		&cli.StringFlag{
			Name:     "output_dir",
			Aliases:  []string{"o"},
			Usage:    "output dir",
			Required: true,
		},
		&cli.StringFlag{
			Name:     "transitions",
			Aliases:  []string{"t"},
			Usage:    "path to file with transitions",
			Required: true,
		},
	},
	Action: func(c *cli.Context) error {
		if c.IsSet("transitions") {
			path, err := filepath.Abs(c.String("transitions"))
			if err != nil {
				return err
			}

			if err := c.Set("transitions", path); err != nil {
				return cli.NewExitError(err, 1)
			}
		}

		if c.IsSet("template") {
			path, err := filepath.Abs(c.String("template"))
			if err != nil {
				return err
			}

			if err := c.Set("template", path); err != nil {
				return cli.NewExitError(err, 1)
			}
		}

		tpl, err := ioutil.ReadFile(c.String("template"))
		if err != nil {
			return cli.NewExitError(err, 1)
		}

		if err := actionsGenerate(c.String("transitions"), c.String("output_dir"), string(tpl)); err != nil {
			return cli.NewExitError(err, 1)
		}

		return nil
	},
}
View Source
var GenCommand = &cli.Command{
	Name:  "gen",
	Usage: "generates fsm",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:        "package",
			Aliases:     []string{"p"},
			Usage:       "package where struct is located",
			DefaultText: "default is current dir(.)",
			Value:       ".",
		},
		&cli.StringFlag{
			Name:     "struct",
			Aliases:  []string{"s"},
			Usage:    "struct name",
			Required: true,
		},
		&cli.StringFlag{
			Name:     "field",
			Aliases:  []string{"f"},
			Usage:    "state field of struct",
			Required: true,
		},
		&cli.StringFlag{
			Name:        "output",
			Aliases:     []string{"o"},
			Usage:       "output file name",
			DefaultText: "default srcdir/<struct>_fsm.go",
		},
		&cli.StringFlag{
			Name:    "transitions",
			Aliases: []string{"t"},
			Usage:   "path to file with transitions",
		},
		&cli.BoolFlag{
			Name:    "noGenerate",
			Aliases: []string{"g"},
			Usage:   "don't put //go:generate instruction to the generated code",
		},
		&cli.StringFlag{
			Name:    "graph-output",
			Aliases: []string{"a"},
			Usage:   "path to transition graph file in dot format",
		},
	},
	Action: func(c *cli.Context) error {
		if c.IsSet("transitions") {
			path, err := filepath.Abs(c.String("transitions"))
			if err != nil {
				return err
			}

			if err := c.Set("transitions", path); err != nil {
				return cli.NewExitError(err, 1)
			}
		}

		if c.IsSet("graph-output") {
			path, err := filepath.Abs(c.String("graph-output"))
			if err != nil {
				return err
			}

			if err := c.Set("graph-output", path); err != nil {
				return cli.NewExitError(err, 1)
			}
		}

		path, err := filepath.Abs(c.String("package"))
		if err != nil {
			return cli.NewExitError(err, 1)
		}

		if err := c.Set("package", path); err != nil {
			return cli.NewExitError(err, 1)
		}

		if err := genAction(c); err != nil {
			return cli.NewExitError(err, 1)
		}

		return nil
	},
}

Functions

func ActionDocGenerate

func ActionDocGenerate(trFile, output string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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