cmd

package
v0.0.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "newgo",
	Short: "A tool for initializing a new Go project",
	Long: `newgo 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("newgo 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", "ngp", "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", "ngp", "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
		}

	},
}

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