Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BIN = forego
SRC = $(shell find . -name '*.go' -not -path './vendor/*')
VERSION = dev

.PHONY: all build clean lint release test

Expand All @@ -20,4 +21,4 @@ test: lint build
go test -v -race -cover ./...

$(BIN): $(SRC)
go build -o $@
go build -ldflags "-X main.Version=$(VERSION)" -o $@
21 changes: 12 additions & 9 deletions outlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

type OutletFactory struct {
Padding int
LeftFormatter string

sync.Mutex
}
Expand Down Expand Up @@ -77,17 +77,20 @@ func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, i
of.Lock()
defer of.Unlock()

ct.ChangeColor(leftC, true, ct.None, false)
formatter := fmt.Sprintf("%%-%ds | ", of.Padding)
fmt.Printf(formatter, left)
if colorize {
ct.ChangeColor(leftC, true, ct.None, false)
}
fmt.Printf(of.LeftFormatter, left)

if isError {
ct.ChangeColor(ct.Red, true, ct.None, true)
} else {
ct.ResetColor()
if colorize {
if isError {
ct.ChangeColor(rightC, true, ct.None, true)
} else {
ct.ResetColor()
}
}
fmt.Println(right)
if isError {
if colorize && isError {
ct.ResetColor()
}
}
6 changes: 5 additions & 1 deletion start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"sync"
"syscall"
"time"

"golang.org/x/crypto/ssh/terminal"
)

const defaultPort = 5000
Expand All @@ -21,6 +23,7 @@ var flagConcurrency string
var flagRestart bool
var flagShutdownGraceTime int
var envs envFiles
var colorize bool

var cmdStart = &Command{
Run: runStart,
Expand Down Expand Up @@ -88,6 +91,7 @@ func init() {
cmdStart.Flag.IntVar(&flagShutdownGraceTime, "t", defaultShutdownGraceTime, "shutdown grace time")
err := readConfigFile(".forego", &flagProcfile, &flagPort, &flagConcurrency, &flagShutdownGraceTime)
handleError(err)
colorize = os.Getenv("NO_COLOR") == "" && terminal.IsTerminal(int(os.Stdout.Fd()))
}

func readConfigFile(config_path string, flagProcfile *string, flagPort *int, flagConcurrency *string, flagShutdownGraceTime *int) error {
Expand Down Expand Up @@ -275,7 +279,7 @@ func runStart(cmd *Command, args []string) {
handleError(err)

of := NewOutletFactory()
of.Padding = pf.LongestProcessName(concurrency)
of.LeftFormatter = fmt.Sprintf("%%-%ds | ", pf.LongestProcessName(concurrency))

f := &Forego{
outletFactory: of,
Expand Down
8 changes: 4 additions & 4 deletions start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestPortFromEnv(t *testing.T) {
os.Setenv("PORT", "4000")
port, err = basePort(env)
if err != nil {
t.Fatal("Can not get port: %s", err)
t.Fatalf("Can not get port: %s", err)
}
if port != 4000 {
t.Fatal("Base port should be 4000")
Expand Down Expand Up @@ -162,14 +162,14 @@ func TestConfigBeOverrideByForegoFile(t *testing.T) {
}

if port != 15000 {
t.Fatal("port should be 15000, got %d", port)
t.Fatalf("port should be 15000, got %d", port)
}

if concurrency != "foo=2,bar=3" {
t.Fatal("concurrency should be 'foo=2,bar=3', got %s", concurrency)
t.Fatalf("concurrency should be 'foo=2,bar=3', got %s", concurrency)
}

if gracetime != 30 {
t.Fatal("gracetime should be 3, got %d", gracetime)
t.Fatalf("gracetime should be 3, got %d", gracetime)
}
}
4 changes: 2 additions & 2 deletions unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func ShellInvocationCommand(interactive bool, root, command string) []string {
if interactive {
shellArgument = "-ic"
}
shellCommand := fmt.Sprintf("cd \"%s\"; source .profile 2>/dev/null; exec %s", root, command)
return []string{"sh", shellArgument, shellCommand}
shellCommand := fmt.Sprintf("cd \"$1\" || exit 66; test -f .profile && . ./.profile; exec %s", command)
return []string{"/bin/sh", shellArgument, shellCommand, "sh", root}
}

func (p *Process) PlatformSpecificInit() {
Expand Down