forked from mirror/cobra
vgo - take named directory or current wd
This commit is contained in:
parent
04af6aed80
commit
e993d53002
|
@ -47,9 +47,11 @@ Init will not use an existing directory with contents.`,
|
||||||
er(err)
|
er(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo:
|
if len(args) > 0 {
|
||||||
// if . use current directory
|
if args[0] != "." {
|
||||||
// else create named directory and set wd to that
|
wd = fmt.Sprintf("%s/%s", wd, args[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
project := &Project{
|
project := &Project{
|
||||||
AbsolutePath: wd,
|
AbsolutePath: wd,
|
||||||
|
|
|
@ -30,6 +30,14 @@ type Project struct {
|
||||||
|
|
||||||
func (p *Project) Create() error {
|
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
|
// create main.go
|
||||||
mainFile, err := os.Create(fmt.Sprintf("%s/main.go", p.AbsolutePath))
|
mainFile, err := os.Create(fmt.Sprintf("%s/main.go", p.AbsolutePath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,7 +53,7 @@ func (p *Project) Create() error {
|
||||||
|
|
||||||
// create cmd/root.go
|
// create cmd/root.go
|
||||||
if _, err = os.Stat(fmt.Sprintf("%s/cmd", p.AbsolutePath)); os.IsNotExist(err) {
|
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))
|
rootFile, err := os.Create(fmt.Sprintf("%s/cmd/root.go", p.AbsolutePath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue