vgo - take named directory or current wd

This commit is contained in:
jharshman 2019-01-30 00:20:25 -08:00 committed by Steve Francia
parent 04af6aed80
commit e993d53002
2 changed files with 14 additions and 4 deletions

View file

@ -47,9 +47,11 @@ Init will not use an existing directory with contents.`,
er(err)
}
// todo:
// if . use current directory
// else create named directory and set wd to that
if len(args) > 0 {
if args[0] != "." {
wd = fmt.Sprintf("%s/%s", wd, args[0])
}
}
project := &Project{
AbsolutePath: wd,

View file

@ -30,6 +30,14 @@ type Project struct {
func (p *Project) Create() error {
// check if AbsolutePath exists
if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) {
// create directory
if err := os.Mkdir(p.AbsolutePath, 0754); err != nil {
return err
}
}
// create main.go
mainFile, err := os.Create(fmt.Sprintf("%s/main.go", p.AbsolutePath))
if err != nil {
@ -45,7 +53,7 @@ func (p *Project) Create() error {
// create cmd/root.go
if _, err = os.Stat(fmt.Sprintf("%s/cmd", p.AbsolutePath)); os.IsNotExist(err) {
os.Mkdir("cmd", 0751)
os.Mkdir(fmt.Sprintf("%s/cmd", p.AbsolutePath), 0751)
}
rootFile, err := os.Create(fmt.Sprintf("%s/cmd/root.go", p.AbsolutePath))
if err != nil {