Skip to content

Commit

Permalink
Merge https://github.com/nginx-proxy/forego into strip-output-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
binfalse committed Nov 26, 2021
2 parents 7a48111 + dc4aa1d commit a9ba6c2
Show file tree
Hide file tree
Showing 28 changed files with 122 additions and 692 deletions.
61 changes: 0 additions & 61 deletions .circleci/config.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
- name: Run tests
run: make test
19 changes: 0 additions & 19 deletions Godeps/Godeps.json

This file was deleted.

5 changes: 0 additions & 5 deletions Godeps/Readme

This file was deleted.

7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BIN = forego
SRC = $(shell find . -name '*.go' -not -path './vendor/*')
SRC = $(shell find . -name '*.go')

.PHONY: all build clean lint release test
.PHONY: all build clean lint test

all: build

Expand All @@ -13,9 +13,6 @@ clean:
lint: $(SRC)
go fmt

release:
bin/release

test: lint build
go test -v -race -cover ./...

Expand Down
10 changes: 1 addition & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
## forego

<a href="https://circleci.com/gh/ddollar/forego">
<img align="right" src="https://circleci.com/gh/ddollar/forego.svg?style=svg">
</a>

[Foreman](https://github.com/ddollar/foreman) in Go.

### Installation

[Downloads](https://dl.equinox.io/ddollar/forego/stable)

##### Compile from Source

$ go get -u github.com/ddollar/forego
$ go get -u github.com/nginx-proxy/forego

### Usage

Expand Down
12 changes: 0 additions & 12 deletions bin/release

This file was deleted.

3 changes: 1 addition & 2 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
)

var flagEnv string
var flagProcfile string

type Command struct {
Expand Down Expand Up @@ -37,7 +36,7 @@ func (c *Command) Name() string {
}

func (c *Command) Runnable() bool {
return c.Run != nil && c.Disabled != true
return c.Run != nil && !c.Disabled
}

func (c *Command) List() bool {
Expand Down
61 changes: 44 additions & 17 deletions env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@ package main
import (
"fmt"
"os"
"regexp"
"sync"

"github.com/subosito/gotenv"
)

var envEntryRegexp = regexp.MustCompile("^([A-Za-z_0-9]+)=(.*)$")
type Env struct {
m sync.Map
}

type Env map[string]string
func (e *Env) Get(key string) string {
value, ok := e.m.Load(key)
if !ok {
return ""
}
return value.(string)
}

func (e *Env) Set(key, value string) {
e.m.Store(key, value)
}

func (e *Env) Delete(key string) {
e.m.Delete(key)
}

// NewEnv makes a new environment
func NewEnv() *Env {
return &Env{sync.Map{}}
}

type envFiles []string

Expand All @@ -23,13 +44,14 @@ func (e *envFiles) Set(value string) error {
return nil
}

func loadEnvs(files []string) (Env, error) {
func loadEnvs(files []string) (*Env, error) {
if len(files) == 0 {
files = []string{".env"}
}

env := make(Env)
env := NewEnv()

// don't need to lock either environment
for _, file := range files {
tmpEnv, err := ReadEnv(file)

Expand All @@ -38,35 +60,40 @@ func loadEnvs(files []string) (Env, error) {
}

// Merge the file I just read into the env.
for k, v := range tmpEnv {
env[k] = v
}
tmpEnv.m.Range(func(key, value interface{}) bool {
env.m.Store(key, value)
return true
})
}
return env, nil
}

func ReadEnv(filename string) (Env, error) {
func ReadEnv(filename string) (*Env, error) {
env := NewEnv()

if _, err := os.Stat(filename); os.IsNotExist(err) {
return make(Env), nil
return env, nil
}

fd, err := os.Open(filename)
if err != nil {
return nil, err
}
defer fd.Close()
env := make(Env)

for key, val := range gotenv.Parse(fd) {
env[key] = val
env.Set(key, val)
}
return env, nil
}

func (e *Env) asArray() (env []string) {
for _, pair := range os.Environ() {
env = append(env, pair)
}
for name, val := range *e {
env = append(env, os.Environ()...)

e.m.Range(func(name, val interface{}) bool {
env = append(env, fmt.Sprintf("%s=%s", name, val))
}
return true
})

return
}
8 changes: 4 additions & 4 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ func TestMultipleEnvironmentFiles(t *testing.T) {
t.Fatalf("Could not read environments: %s", err)
}

if env["env1"] == "" {
t.Fatalf("$env1 should be present and is not")
if env.Get("env1") == "" {
t.Fatal("$env1 should be present and is not")
}

if env["env2"] == "" {
t.Fatalf("$env2 should be present and is not")
if env.Get("env2") == "" {
t.Fatal("$env2 should be present and is not")
}
}
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/nginx-proxy/forego

go 1.11

require (
github.com/daviddengcn/go-colortext v1.0.0
github.com/stretchr/testify v1.7.0 // indirect
github.com/subosito/gotenv v1.2.0
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
github.com/golangplus/bytes v1.0.0 h1:YQKBijBVMsBxIiXT4IEhlKR2zHohjEqPole4umyDX+c=
github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A=
github.com/golangplus/fmt v1.0.0 h1:FnUKtw86lXIPfBMc3FimNF3+ABcV+aH5F17OOitTN+E=
github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE=
github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ=
github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

type Process struct {
Command string
Env Env
Env *Env
Interactive bool

*exec.Cmd
}

func NewProcess(workdir, command string, env Env, interactive bool) (p *Process) {
func NewProcess(workdir, command string, env *Env, interactive bool) (p *Process) {
argv := ShellInvocationCommand(interactive, workdir, command)
return &Process{
command, env, interactive, exec.Command(argv[0], argv[1:]...),
Expand Down
4 changes: 2 additions & 2 deletions procfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"regexp"
)

var procfileEntryRegexp = regexp.MustCompile("^([A-Za-z0-9_-]+):\\s*(.+)$")
var procfileEntryRegexp = regexp.MustCompile(`^([A-Za-z0-9_-]+):\s*(.+)$`)

type ProcfileEntry struct {
Name string
Expand Down Expand Up @@ -68,7 +68,7 @@ func parseProcfile(r io.Reader) (*Procfile, error) {
}
}
if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("Reading Procfile: %s", err)
return nil, fmt.Errorf("reading Procfile: %s", err)
}
return pf, nil
}
Loading

0 comments on commit a9ba6c2

Please sign in to comment.