diff options
-rw-r--r-- | cmd/ponzu/main.go | 14 | ||||
-rw-r--r-- | cmd/ponzu/options.go | 24 |
2 files changed, 16 insertions, 22 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index a13dd6c..7615246 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -20,14 +20,16 @@ Options new <directory>: - Creates a new 'ponzu' in the current directory, or one supplied - as a parameter immediately following the 'new' option. Note: 'new' - depends on the program 'git' and possibly a network connection. If there is - no local repository to clone from at the local machine's $GOPATH, 'new' will - attempt to clone the 'ponzu' package from over the network. + Creates a 'ponzu' directorty, or one by the name supplied as a parameter + immediately following the 'new' option in the $GOPATH/src directory. Note: + 'new' depends on the program 'git' and possibly a network connection. If + there is no local repository to clone from at the local machine's $GOPATH, + 'new' will attempt to clone the 'github.com/bosssauce/ponzu' package from + over the network. Example: - $ ponzu new ~/Projects/my-project.dev + $ ponzu new myProject + > New ponzu project created at $GOPATH/src/myProject diff --git a/cmd/ponzu/options.go b/cmd/ponzu/options.go index 8204155..5672457 100644 --- a/cmd/ponzu/options.go +++ b/cmd/ponzu/options.go @@ -1,7 +1,6 @@ package main import ( - "bytes" "fmt" "html/template" "os" @@ -147,6 +146,10 @@ func ({{ .initial }} *{{ .name }}) MarshalEditor() ([]byte, error) { ` func newProjectInDir(path string) error { + // set path to be nested inside $GOPATH/src + gopath := os.Getenv("GOPATH") + path = filepath.Join(gopath, "src", path) + // check if anything exists at the path, ask if it should be overwritten if _, err := os.Stat(path); !os.IsNotExist(err) { fmt.Println("Path exists, overwrite contents? (y/N):") @@ -184,24 +187,13 @@ func newProjectInDir(path string) error { } func createProjInDir(path string) error { - var buf = &bytes.Buffer{} - echo := exec.Command("echo", os.Getenv("GOPATH")) - echo.Stdout = buf - err := echo.Run() - if err != nil { - return err - } - - gopath := buf.String() - gopath = gopath[:len(gopath)-1] - gopath = filepath.Join(gopath, "src") - + gopath := os.Getenv("GOPATH") repo := []string{"github.com", "bosssauce", "ponzu"} - local := filepath.Join(gopath, filepath.Join(repo...)) + local := filepath.Join(gopath, "src", filepath.Join(repo...)) network := "https://" + strings.Join(repo, "/") + ".git" // create the directory or overwrite it - err = os.MkdirAll(path, os.ModeDir|os.ModePerm) + err := os.MkdirAll(path, os.ModeDir|os.ModePerm) if err != nil { return err } @@ -237,6 +229,6 @@ func createProjInDir(path string) error { } } - fmt.Println("New project created at", path) + fmt.Println("New ponzu project created at", path) return nil } |