project

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:        "create",
	Aliases:     nil,
	Usage:       "create .",
	Description: "create fns project",
	ArgsUsage:   "",
	Category:    "",
	Flags: []cli.Flag{
		&cli.PathFlag{
			Required: false,
			Name:     "settings",
			Value:    "",
			Usage:    "project settings file",
		},
	},
	Action: func(ctx *cli.Context) (err error) {
		projectDir := strings.TrimSpace(ctx.Args().First())
		if projectDir == "" {
			projectDir = "."
		}
		projectDir, err = filepath.Abs(projectDir)
		if err != nil {
			err = fmt.Errorf("fnc: create failed for project path is invalid, %v", err)
			return
		}
		settingsPath := ctx.Path("settings")
		g := model.Generator{}
		if settingsPath != "" {
			settingsAbsPath, settingsAbsPathErr := filepath.Abs(settingsPath)
			if settingsAbsPathErr != nil {
				err = fmt.Errorf("fnc: create project failed, absolute representation of settings file failed, %v", settingsAbsPathErr)
				return
			}
			settingsContent, readErr := ioutil.ReadFile(settingsAbsPath)
			if readErr != nil {
				err = fmt.Errorf("fnc: create project failed, read settings file failed, %v", readErr)
				return
			}
			decodeErr := yaml.Unmarshal(settingsContent, &g)
			if decodeErr != nil {
				err = fmt.Errorf("fnc: create project failed, decode settings file failed, %v", decodeErr)
				return
			}
		} else {
			goVersion := runtime.Version()
			if len(strings.Split(goVersion, ".")) > 2 {
				goVersion = goVersion[0:strings.LastIndexByte(goVersion, '.')]
			}
			g.Module.Go = goVersion

			askErr := doAsk(&g)
			if askErr != nil {
				err = fmt.Errorf("fnc: create project failed, %v", askErr)
				return
			}
		}
		g.Path = projectDir
		err = create(g)
		return
	},
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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