From 732e4db0d43f782e8b3b576c433db2b811171386 Mon Sep 17 00:00:00 2001 From: jharshman Date: Wed, 30 Jan 2019 01:33:04 -0800 Subject: [PATCH] vgo - trim some uneeded data from struct --- cobra/cmd/add.go | 9 ++++----- cobra/cmd/project.go | 12 +++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cobra/cmd/add.go b/cobra/cmd/add.go index ca19cb71..806a7cc5 100644 --- a/cobra/cmd/add.go +++ b/cobra/cmd/add.go @@ -16,7 +16,6 @@ package cmd import ( "fmt" "os" - "path" "unicode" "github.com/spf13/cobra" @@ -60,10 +59,10 @@ Example: cobra add server -> resulting in a new cmd/server.go`, CmdParent: parentName, Project: &Project{ AbsolutePath: fmt.Sprintf("%s/cmd", wd), - AppName: path.Base(packageName), - PkgName: packageName, - Legal: getLicense(), - Copyright: copyrightLine(), + //AppName: path.Base(packageName), + //PkgName: packageName, + Legal: getLicense(), + Copyright: copyrightLine(), }, } diff --git a/cobra/cmd/project.go b/cobra/cmd/project.go index fe9ea319..9b56e849 100644 --- a/cobra/cmd/project.go +++ b/cobra/cmd/project.go @@ -91,7 +91,17 @@ func (p *Project) createLicenseFile() error { } func (c *Command) Create() error { - return nil + cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.Project.AbsolutePath, c.CmdName)) + if err != nil { + return err + } + defer cmdFile.Close() + + commandTemplate := template.Must(template.New("sub").Parse(string(tpl.AddCommandTemplate()))) + err = commandTemplate.Execute(cmdFile, c.Project.AbsolutePath) + if err != nil { + return err + } } // NewProject returns Project with specified project name.