cmd

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "ngc",
	Short: "A tool for initializing a new Go project",
	Long: `ngc is a tool for initializing a new Go project.  It creates a dockerfile and Makefile 
appropriate for your project.`,

	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("ngc executed")
		fmt.Println(ProjectPath())
		data := make(map[string]string)
		data["ProjectPath"] = guessImportPath()
		data["DockerImage"] = DockerImage()
		data["GithubRepo"] = strings.Replace(guessImportPath(), "github.com/", "", -1)

		dockerfile := filepath.Join(getSrcPath(), "github.com", "bketelsen", "ngc", "templates", "Dockerfile.tmpl")
		rt, err := template.ParseFiles(dockerfile)
		if err != nil {
			fmt.Println(errors.Wrap(err, "reading dockerfile template"))
			return
		}
		rm, err := os.Create(filepath.Join(ProjectPath(), "Dockerfile"))
		if err != nil {
			fmt.Println("create dockerfile: ", err)
			return
		}
		defer rm.Close()
		err = rt.Execute(rm, data)
		if err != nil {
			fmt.Print("execute dockerfile template: ", err)
			return
		}

		makefile := filepath.Join(getSrcPath(), "github.com", "bketelsen", "ngc", "templates", "Makefile.tmpl")
		rt, err = template.ParseFiles(makefile)
		if err != nil {
			fmt.Println(errors.Wrap(err, "reading makefile template"))
			return
		}
		rm, err = os.Create(filepath.Join(ProjectPath(), "Makefile"))
		if err != nil {
			fmt.Println("create Makefile: ", err)
			return
		}
		defer rm.Close()
		err = rt.Execute(rm, data)
		if err != nil {
			fmt.Print("execute makefile template: ", err)
			return
		}

		main := filepath.Join(getSrcPath(), "github.com", "bketelsen", "ngc", "templates", "main.go.tmpl")
		rt, err = template.ParseFiles(main)
		if err != nil {
			fmt.Println(errors.Wrap(err, "reading makefile template"))
			return
		}
		rm, err = os.Create(filepath.Join(ProjectPath(), "main.go"))
		if err != nil {
			fmt.Println("create main.go: ", err)
			return
		}
		defer rm.Close()
		err = rt.Execute(rm, data)
		if err != nil {
			fmt.Print("execute main template: ", err)
			return
		}

		envrc := filepath.Join(getSrcPath(), "github.com", "bketelsen", "ngc", "templates", "envrc.tmpl")
		rt, err = template.ParseFiles(envrc)
		if err != nil {
			fmt.Println(errors.Wrap(err, "reading envrc template"))
			return
		}
		rm, err = os.Create(filepath.Join(ProjectPath(), ".envrc"))
		if err != nil {
			fmt.Println("create envrc: ", err)
			return
		}
		defer rm.Close()
		err = rt.Execute(rm, data)
		if err != nil {
			fmt.Print("execute envrc template: ", err)
			return
		}

		gr := filepath.Join(getSrcPath(), "github.com", "bketelsen", "ngc", "templates", "goreleaser.yml.tmpl")
		rt, err = template.ParseFiles(gr)
		if err != nil {
			fmt.Println(errors.Wrap(err, "reading goreleaser template"))
			return
		}
		rm, err = os.Create(filepath.Join(ProjectPath(), ".goreleaser.yml"))
		if err != nil {
			fmt.Println("create goreleaser: ", err)
			return
		}
		defer rm.Close()
		err = rt.Execute(rm, data)
		if err != nil {
			fmt.Print("execute goreleaser template: ", err)
			return
		}
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func DockerImage

func DockerImage() string

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func ProjectPath

func ProjectPath() string

Types

This section is empty.

Jump to

Keyboard shortcuts

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