Skip to content

Commit

Permalink
Default to ~/go when gopath is unavailable, attempt to resolve cp bug…
Browse files Browse the repository at this point in the history
… in makefile (#22)
  • Loading branch information
KyleBanks committed Mar 22, 2017
1 parent a5b8070 commit 64b4102
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 22 deletions.
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
VERSION = 0.1.0
VERSION = 0.1.1

INSTALL_PKG = ./cmd/goggles

APP_FOLDER = ./bin/goggles.app
BIN = ./bin
APP_NAME = Goggles.app
APP_FOLDER = $(BIN)/$(APP_NAME)
APP_STATIC_FOLDER = $(APP_FOLDER)/Contents/MacOS/static
LOG_FILE = ~/Library/Logs/goggles.log

BUNDLE_ID = com.kylewbanks.goggles
BUNDLE_NAME = Goggles

# Runs goggles and opens the logs.
#
# This is the default command.
Expand All @@ -22,23 +27,32 @@ gulp:

# Cleans any built artifacts.
clean:
@rm -rf $(APP_FOLDER)
@rm -rf $(BIN)
@rm -f $(LOG_FILE)
.PHONY: clean

# Builds goggles to the ./bin directory.
build: | clean gulp
@mkdir -p bin/
@go build -v -o bin/goggles $(INSTALL_PKG)
@gallium-bundle bin/goggles --output $(APP_FOLDER)
@gallium-bundle bin/goggles \
--output $(APP_FOLDER) \
--identifier $(BUNDLE_ID) \
--name $(BUNDLE_NAME)
@mkdir -p $(APP_STATIC_FOLDER)
@cp -r ./_static/ $(APP_STATIC_FOLDER)
@cp -a ./_static/. $(APP_STATIC_FOLDER)
@rm -rf $(APP_STATIC_FOLDER)/node_modules
.PHONY: build

# Builds a release bundle.
release: | build
@cd $(BIN) ; \
zip -r -y goggles.$(VERSION).zip $(APP_NAME)
.PHONY: release

# Runs the goggles application.
run.goggles: | build
@pkill goggles || true
@pkill Goggles || true
@open $(APP_FOLDER)
.PHONY: run

Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@

![Goggles Demo](./demo.gif)

## Features

- Browse and search local packages
- View package documentation
- Open the project folder in Finder or Terminal
- Open the project repository in your browser
- Displays badges for GoDoc, Goreportcard, and Travis.CI (if .travis.yml is present)

## Install

### Stable

Grab the latest release from the [Releases](https://github.com/KyleBanks/goggles/releases) page.

**Note:** It is currently a known issue that Goggles can only be run via the command-line with `open Goggles.app`, simply double-clicking `Goggles.app` has issues finding your $GOPATH.
**Note:** If you have a custom `$GOPATH` it's currently a known issue that Goggles must be run via the command-line with `open Goggles.app`, simply double-clicking `Goggles.app` will only work with the default of `$HOME/go`.

### From Source

Expand Down
2 changes: 2 additions & 0 deletions cmd/goggles/goggles.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func init() {
}

func startServer() {
log.Printf("$GOPATH=%v, srcdir=%v", sys.Gopath(), sys.Srcdir())

p := provider{goggles.Service{}}
api := server.New(p, filepath.Dir(os.Args[0]))
addr := fmt.Sprintf(":%v", port)
Expand Down
6 changes: 3 additions & 3 deletions pkg/sys/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ var DefaultRunner Runner = CmdRunner{}

// Runner defines a type that can run system commands.
type Runner interface {
Run(string, ...string) error
Run(string, ...string) ([]byte, error)
}

// CmdRunner runs system commands.
type CmdRunner struct{}

// Run executes a system command.
func (CmdRunner) Run(cmd string, args ...string) error {
return exec.Command(cmd, args...).Run()
func (CmdRunner) Run(cmd string, args ...string) ([]byte, error) {
return exec.Command(cmd, args...).CombinedOutput()
}
6 changes: 4 additions & 2 deletions pkg/sys/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ func TestCmdRunner_Run(t *testing.T) {
var r CmdRunner

// Expect an error
err := r.Run("fake command", "this", "will", "fail")
_, err := r.Run("fake command", "this", "will", "fail")
if err == nil {
t.Fatal("Expected error, got nil")
}

// Expect success
err = r.Run("echo", "hi")
out, err := r.Run("echo", "hi")
if err != nil {
t.Fatal(err)
} else if string(out) != "hi\n" {
t.Fatalf("Unexpected output, expected=%v, got=%v", "hi", string(out))
}
}
12 changes: 10 additions & 2 deletions pkg/sys/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var (
cmdOpenFileExplorer = []string{"open"}
cmdOpenTerminal = []string{"open", "-a", "Terminal"}
cmdOpenBrowser = []string{"open"}

defaultGoPath = os.ExpandEnv("$HOME/go")
)

// OpenFileExplorer opens the system file explorer application to the
Expand Down Expand Up @@ -49,7 +51,13 @@ func Srcdir() string {
return filepath.Join(Gopath(), srcDirName)
}

// Gopath returns the $GOPATH environment variable.
// Gopath returns the $GOPATH environment variable, defaulting to $HOME/go
// if the environment variable is not set.
func Gopath() string {
return os.Getenv(gopathEnv)
gopath := os.Getenv(gopathEnv)
if len(gopath) == 0 {
gopath = defaultGoPath
}

return gopath
}
23 changes: 15 additions & 8 deletions pkg/sys/sys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
)

type mockRunner struct {
runFn func(string, ...string) error
runFn func(string, ...string) ([]byte, error)
}

func (m mockRunner) Run(cmd string, args ...string) error { return m.runFn(cmd, args...) }
func (m mockRunner) Run(cmd string, args ...string) ([]byte, error) { return m.runFn(cmd, args...) }

func Test_OpenFileExplorer(t *testing.T) {
expect := []string{"/foo/bar/gopath", "src", "github.com/foo/bar"}
Expand All @@ -19,10 +19,10 @@ func Test_OpenFileExplorer(t *testing.T) {
var gotCmd string
var gotPath string
DefaultRunner = mockRunner{
runFn: func(cmd string, args ...string) error {
runFn: func(cmd string, args ...string) ([]byte, error) {
gotCmd = cmd
gotPath = args[0]
return nil
return nil, nil
},
}

Expand All @@ -42,10 +42,10 @@ func Test_OpenTerminal(t *testing.T) {
var gotCmd string
var gotArgs []string
DefaultRunner = mockRunner{
runFn: func(cmd string, args ...string) error {
runFn: func(cmd string, args ...string) ([]byte, error) {
gotCmd = cmd
gotArgs = args
return nil
return nil, nil
},
}

Expand All @@ -72,10 +72,10 @@ func Test_OpenBrowser(t *testing.T) {
var gotCmd string
var gotURL string
DefaultRunner = mockRunner{
runFn: func(cmd string, args ...string) error {
runFn: func(cmd string, args ...string) ([]byte, error) {
gotCmd = cmd
gotURL = args[0]
return nil
return nil, nil
},
}

Expand Down Expand Up @@ -108,9 +108,16 @@ func Test_Srcdir(t *testing.T) {
}

func Test_Gopath(t *testing.T) {
// GOPATH avaiable
expect := "/foo/bar/path"
os.Setenv("GOPATH", expect)
if Gopath() != expect {
t.Fatalf("Unexpected Gopath, expected=%v, got=%v", expect, Gopath())
}

// Default
expect = defaultGoPath
os.Setenv("GOPATH", "")
if Gopath() != expect {
t.Fatalf("Unexpected Gopath, expected=%v, got=%v", expect, Gopath())
}
Expand Down

0 comments on commit 64b4102

Please sign in to comment.