codes

package
v1.13.6 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name: "codes",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:     "debug",
			EnvVars:  []string{"FNC_DEBUG"},
			Usage:    "print debug infos",
			Required: false,
		},
		&cli.StringFlag{
			Name:      "work",
			Aliases:   []string{"w"},
			Usage:     "set workspace file path",
			Required:  false,
			EnvVars:   []string{"FNC_WORK"},
			TakesFile: false,
		},
	},
	Aliases:     nil,
	Usage:       "fnc codes {project path}",
	Description: "scan fns project and generate fn codes",
	ArgsUsage:   "",
	Category:    "",
	Action: func(ctx *cli.Context) (err error) {
		debug := ctx.Bool("debug")
		projectDir := strings.TrimSpace(ctx.Args().First())
		if projectDir == "" {
			projectDir = "."
		}
		if !filepath.IsAbs(projectDir) {
			projectDir, err = filepath.Abs(projectDir)
			if err != nil {
				err = errors.Warning("fnc: codes failed").WithCause(err).WithMeta("dir", projectDir)
				return
			}
		}
		projectDir = filepath.ToSlash(projectDir)
		work := ctx.String("work")
		var project *forg.Project
		if work != "" {
			project, err = forg.Load(projectDir, forg.WithWorkspace(work))
		} else {
			project, err = forg.Load(projectDir)
		}
		if err != nil {
			err = errors.Warning("fnc: codes failed").WithCause(err)
			return
		}
		process, codingErr := project.Coding(ctx.Context)
		if codingErr != nil {
			err = errors.Warning("fnc: codes failed").WithCause(codingErr)
			return
		}
		results := process.Start(ctx.Context)
		for {
			result, ok := <-results
			if !ok {
				if debug {
					fmt.Println("fnc: codes finished")
				}
				break
			}
			if debug {
				fmt.Println(result, "->", fmt.Sprintf("[%d/%d]", result.UnitNo, result.UnitNum), result.Data)
			}
			if result.Error != nil {
				fmt.Println(fmt.Sprintf("%+v", result.Error))
			}
		}
		return
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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