mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
vgo - take named directory or current wd
This commit is contained in:
parent
04af6aed80
commit
e993d53002
2 changed files with 14 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue