projectcmd

package
v0.0.0-...-c75f131 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CmdProject = &cobra.Command{
	Use:     "create",
	Short:   "Create a new project based on the preset project",
	Long:    "Create a new project based on the preset project.",
	Example: "mangokit create helloworld github.com/xxx/helloworld",
	Run: func(cmd *cobra.Command, args []string) {
		projectDir := ""
		projectName := ""
		if len(args) < 2 {
			prompt1 := &survey.Input{
				Message: "What is project dir name",
				Help:    "Create project dir name",
			}

			err := survey.AskOne(prompt1, &projectDir)
			if err != nil || projectDir == "" {
				return
			}

			prompt2 := &survey.Input{
				Message: "What is project name or go mod name",
				Help:    "Input go mod name",
			}

			err = survey.AskOne(prompt2, &projectName)
			if err != nil || projectName == "" {
				return
			}
		} else {
			projectDir = args[0]
			projectName = args[1]
		}

		dir, err := os.Getwd()
		if err != nil {
			color.Red("get current work dir failed: %v", err)
			return
		}

		project := ProjectGenerator{
			DirName:     projectDir,
			ProjectName: projectName,
			BaseDir:     filepath.Join(dir, projectDir),
			RepoUrl:     repoUrl,
			Branch:      branch,
		}

		ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
		defer cancel()
		if err = project.Generate(ctx); err != nil {
			color.Red("generate project failed")
		}
	},
}

Functions

This section is empty.

Types

type ProjectGenerator

type ProjectGenerator struct {
	DirName     string
	ProjectName string
	BaseDir     string
	RepoUrl     string
	Branch      string
}

func (*ProjectGenerator) CloneRepo

func (p *ProjectGenerator) CloneRepo(ctx context.Context) error

func (*ProjectGenerator) Generate

func (p *ProjectGenerator) Generate(ctx context.Context) error

func (*ProjectGenerator) GetGoModName

func (p *ProjectGenerator) GetGoModName() (string, error)

func (*ProjectGenerator) GitInit

func (p *ProjectGenerator) GitInit() error

func (*ProjectGenerator) GoModInit

func (p *ProjectGenerator) GoModInit() error

func (*ProjectGenerator) ModifyFiles

func (p *ProjectGenerator) ModifyFiles() error

func (*ProjectGenerator) ModifyGoImports

func (p *ProjectGenerator) ModifyGoImports(oldModule string) error

Jump to

Keyboard shortcuts

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