Permalink
Browse files

Merge pull request #2 from matttproud/cleanups/improve-usability

Enhance error reporting and documentation.
  • Loading branch information...
2 parents 46dfb95 + 085aac4 commit f65fd4ef69ddf9024b50445f3b5c31830609e85b @dougm committed Apr 30, 2013
Showing with 61 additions and 17 deletions.
  1. +16 −2 README.md
  2. +1 −1 go-flycheck.el
  3. +44 −14 main.go
View
@@ -7,9 +7,15 @@ multi-file packages and _test.go files. Support for os/arch specific
### Setup
- 1. If needed, update your **$PATH** to include go installed binaries, for example:
+ 1. If needed, update your **${PATH}** to include Go installed binaries, for example:
- `export PATH=$PATH:$GOPATH/bin`
+ `export PATH=${PATH}:${GOPATH}/bin`
+
+ Depending on your Emacs workflow (e.g., windowing system environment), it may be required to explicitly set
+the following items:
+ 1. ``(setenv "GOPATH" "/path/to/gopath")``
+ 2. ``(setenv "PATH" (concat (getenv "PATH") ":" "/extra/path/element"))``
+ 3. ``(setq exec-path (append exec-path (list (expand-file-name "/another/thing"))))``
2. Install goflymake:
@@ -37,3 +43,11 @@ multi-file packages and _test.go files. Support for os/arch specific
We probably shouldn't need the `goflymake` program, the `go` tool could
be tweaked to support the flymake style of syntax checking.
Maybe there is already a better way, but I couldn't find one.
+
+### Troubleshooting
+
+The ``goflymake`` command includes forensic information to assist in debugging
+anomalies, which will assist you in tracking down the problem.
+
+If worst comes to worst, the [Flymake Troubleshooting Guide](http://www.gnu.org/software/emacs/manual/html_node/flymake/Troubleshooting.html)
+is definitely helpful.
View
@@ -20,7 +20,7 @@
"A Go syntax and style checker using the go utility.
See URL `https://github.com/dougm/goflymake'."
- :command '("goflymake" "flycheck-" source-inplace)
+ :command '("goflymake" "-prefix=flycheck-" source-inplace)
:error-patterns '(("^\\(?1:.*\\):\\(?2:[0-9]+\\): \\(?4:.*\\)$" error))
:modes 'go-mode)
View
58 main.go
@@ -1,41 +1,59 @@
package main
import (
+ "flag"
"fmt"
"go/build"
+ "log"
"os"
"os/exec"
"path"
"strings"
)
+const (
+ testSuffix = "_test.go"
+)
+
+var (
+ prefix = flag.String("prefix", "flymake_", "The prefix for generated Flymake artifacts.")
+
+ testArguments = []string{"test", "-c"}
+ buildArguments = []string{"build", "-o", "/dev/null"}
+)
+
func main() {
- prefix := "flymake_"
- file := os.Args[len(os.Args)-1]
- sdir := path.Dir(file)
- base := path.Base(file)
+ flag.Parse()
+ goflymakeArguments := flag.Args()
- if len(os.Args) == 3 {
- prefix = os.Args[1]
+ if len(goflymakeArguments) != 1 {
+ log.Fatalf("%s %ssome_file.go", path.Base(os.Args[0]), *prefix)
}
- orig := base[len(prefix):]
+ file := goflymakeArguments[0]
+ base := path.Base(file)
+
+ if !strings.HasPrefix(base, *prefix) {
+ log.Fatalf("%s lacks the appropriate filename prefix %s", base, *prefix)
+ }
+ orig := base[len(*prefix):]
isTest := false
- var args []string
+ var goArguments []string
- if strings.HasSuffix(orig, "_test.go") {
+ if strings.HasSuffix(orig, testSuffix) {
isTest = true
// shame there is no '-o' option
- args = append(args, "test", "-c")
+ goArguments = append(goArguments, testArguments...)
} else {
- args = append(args, "build", "-o", "/dev/null")
+ goArguments = append(goArguments, buildArguments...)
}
+ sdir := path.Dir(file)
pkg, err := build.ImportDir(sdir, build.AllowBinary)
if err != nil {
- args = append(args, file)
+ goArguments = append(goArguments, file)
} else {
var files []string
files = append(files, pkg.GoFiles...)
@@ -48,16 +66,28 @@ func main() {
if f == orig {
continue
}
- args = append(args, f)
+ goArguments = append(goArguments, f)
}
}
- cmd := exec.Command("go", args...)
+ cmd := exec.Command("go", goArguments...)
out, err := cmd.CombinedOutput()
fmt.Print(string(out))
if err != nil {
+ banner := strings.Repeat("*", 80)
+
+ log.Println(banner)
+ log.Println("Encountered a problem:", err)
+ log.Println("goflymake ARGUMENTS:", os.Args)
+ log.Println("Go ARGUMENTS:", goArguments)
+ log.Println("ENVIRONMENT VARIABLES")
+ log.Println("PATH:", os.Getenv("PATH"))
+ log.Println("GOPATH", os.Getenv("GOPATH"))
+ log.Println("GOROOT", os.Getenv("GOROOT"))
+ log.Println(banner)
+
os.Exit(1)
}
}

0 comments on commit f65fd4e

Please sign in to comment.