diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ffa23fe --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release + +on: + push: + tags: # Sequence of patterns matched against refs/tags + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + release: + name: Create Release + runs-on: ubuntu-latest + outputs: + artifact_upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: true + prerelease: false + + artifacts: + needs: [ release ] + name: Build Artifacts + strategy: + matrix: + include: + - target: linux + arch: amd64 + os: ubuntu-latest + - target: freebsd + arch: amd64 + os: ubuntu-latest + - target: darwin + arch: amd64 + os: macos-latest + - target: darwin + arch: arm64 + os: macos-latest + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Build + env: + GOOS: ${{ matrix.target }} + GOARCH: ${{ matrix.arch }} + run: | + make archive GITHASH=${{ github.sha }} + - name: Upload artifact + id: upload_artifact_linux_amd64 + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release.outputs.artifact_upload_url }} + asset_path: ./target/${{ matrix.target }}_${{ matrix.arch }}/forego-${{ github.sha }}-${{ matrix.target }}-${{ matrix.arch }}.tgz + asset_name: forego-${{ github.ref_name }}-${{ matrix.target }}-${{ matrix.arch }}.tgz + asset_content_type: application/x-tgz diff --git a/.gitignore b/.gitignore index c2cf70d..7f8a427 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .env -/forego +.DS_Store + +target/ +bin/ diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json deleted file mode 100644 index 1cc516a..0000000 --- a/Godeps/Godeps.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "ImportPath": "github.com/ddollar/forego", - "GoVersion": "go1.6", - "GodepVersion": "v61", - "Packages": [ - "./..." - ], - "Deps": [ - { - "ImportPath": "github.com/daviddengcn/go-colortext", - "Rev": "3b18c8575a432453d41fdafb340099fff5bba2f7" - }, - { - "ImportPath": "github.com/subosito/gotenv", - "Comment": "v0.1.0", - "Rev": "a37a0e8fb3298354bf97daad07b38feb2d0fa263" - } - ] -} diff --git a/Godeps/Readme b/Godeps/Readme deleted file mode 100644 index 4cdaa53..0000000 --- a/Godeps/Readme +++ /dev/null @@ -1,5 +0,0 @@ -This directory tree is generated automatically by godep. - -Please do not edit. - -See https://github.com/tools/godep for more information. diff --git a/Makefile b/Makefile index a69d6f5..e20fd2a 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,59 @@ -BIN = forego -SRC = $(shell find . -name '*.go' -not -path './vendor/*') -.PHONY: all build clean lint release test +# the product we're building +NAME := forego +# the product's main package +MAIN := ./forego + +# fix our gopath +GOPATH := $(GOPATH):$(PWD) +GOOS ?= $(shell go env GOOS) +GOARCH ?= $(shell go env GOARCH) + +# build and packaging +TARGETS := $(PWD)/bin +PRODUCT := $(TARGETS)/$(NAME) + +# build and packaging for release +GITHASH := $(shell git log --pretty=format:'%h' -n 1) +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +VERSION ?= $(GITHASH) +RELEASE_TARGETS = $(PWD)/target/$(GOOS)_$(GOARCH) +RELEASE_PRODUCT = $(NAME)-$(VERSION) +RELEASE_BUILD = $(RELEASE_TARGETS)/$(RELEASE_PRODUCT) +RELEASE_BINARY = $(RELEASE_BUILD)/bin/$(NAME) +RELEASE_ARCHIVE = $(RELEASE_PRODUCT)-$(GOOS)-$(GOARCH).tgz +RELEASE_PACKAGE = $(RELEASE_TARGETS)/$(RELEASE_ARCHIVE) + +# build and install +PREFIX ?= /usr/local +LATEST ?= latest + +# sources +SRC = $(shell find $(MAIN) -name \*.go) + +.PHONY: all test clean install build archive all: build -build: $(BIN) +$(PRODUCT): $(SRC) + go build -ldflags="-X main.version=$(VERSION) -X main.githash=$(GITHASH)" -o $@ $(MAIN) + +build: $(PRODUCT) ## Build the product + +$(RELEASE_BINARY): $(SRC) + go build -ldflags="-X main.version=$(VERSION) -X main.githash=$(GITHASH)" -o $(RELEASE_BINARY) $(MAIN) -clean: - rm -f $(BIN) +$(RELEASE_PACKAGE): $(RELEASE_BINARY) + (cd $(RELEASE_TARGETS) && tar -zcf $(RELEASE_ARCHIVE) $(RELEASE_PRODUCT)) -lint: $(SRC) - go fmt +archive: $(RELEASE_PACKAGE) -release: - bin/release +install: build ## Build and install + @echo "Using sudo to install; you may be prompted for a password..." + sudo install -m 0755 $(PRODUCT) $(PREFIX)/bin/ -test: lint build - go test -v -race -cover ./... +test: ## Run tests + go test $(MAIN)/... -$(BIN): $(SRC) - go build -o $@ +clean: ## Delete the built product and any generated files + rm -rf $(TARGETS) diff --git a/README.md b/README.md index cafe174..f91e9ce 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ -## forego - - - - +## Forego [Foreman](https://github.com/ddollar/foreman) in Go. -### Installation +## Installing + +For your convenience, Forego can be installed via Homebrew. However you cannot install it along side the original Forego, from which this was forked. + +Install or upgrade the latest version thusly: -[Downloads](https://dl.equinox.io/ddollar/forego/stable) +``` +$ brew install bww/stable/forego +$ brew upgrade bww/stable/forego +``` -##### Compile from Source +Uninstall as follows: - $ go get -u github.com/ddollar/forego +``` +$ brew uninstall forego +``` ### Usage @@ -29,4 +34,4 @@ Use `forego help` to get a list of available commands, and `forego help ### License -Apache 2.0 © 2015 David Dollar +Apache 2.0 © 2015 David Dollar, 2018 Brian W. Wolter diff --git a/bin/release b/bin/release deleted file mode 100755 index 84aa1fa..0000000 --- a/bin/release +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -version=$(date +%Y%m%d%H%M%S) - -curl -s ${GITHUB_KEY_URL} -o /tmp/github.key -chmod 0400 /tmp/github.key -git tag ${version} -GIT_SSH_COMMAND='ssh -i /tmp/github.key' git push origin ${version} - -curl -s https://bin.equinox.io/c/mBWdkfai63v/release-tool-stable-linux-amd64.tgz | sudo tar xz -C /usr/local/bin -curl -s ${EQUINOX_KEY_URL} -o /tmp/equinox.key -equinox release --version=${version} --platforms="darwin_386 darwin_amd64 linux_386 linux_amd64 linux_arm linux_arm64 windows_386 windows_amd64" --channel=stable --signing-key=/tmp/equinox.key --app=${EQUINOX_APP} --token=${EQUINOX_TOKEN} diff --git a/barrier.go b/forego/barrier.go similarity index 100% rename from barrier.go rename to forego/barrier.go diff --git a/command.go b/forego/command.go similarity index 100% rename from command.go rename to forego/command.go diff --git a/config.go b/forego/config.go similarity index 100% rename from config.go rename to forego/config.go diff --git a/config_test.go b/forego/config_test.go similarity index 100% rename from config_test.go rename to forego/config_test.go diff --git a/env.go b/forego/env.go similarity index 100% rename from env.go rename to forego/env.go diff --git a/env_test.go b/forego/env_test.go similarity index 82% rename from env_test.go rename to forego/env_test.go index b52f44b..b8cb424 100644 --- a/env_test.go +++ b/forego/env_test.go @@ -3,7 +3,7 @@ package main import "testing" func TestMultipleEnvironmentFiles(t *testing.T) { - envs := []string{"fixtures/envs/.env1", "fixtures/envs/.env2"} + envs := []string{"../fixtures/envs/.env1", "../fixtures/envs/.env2"} env, err := loadEnvs(envs) if err != nil { diff --git a/error.go b/forego/error.go similarity index 100% rename from error.go rename to forego/error.go diff --git a/help.go b/forego/help.go similarity index 100% rename from help.go rename to forego/help.go diff --git a/main.go b/forego/main.go similarity index 86% rename from main.go rename to forego/main.go index 8fe5078..c6e3d67 100644 --- a/main.go +++ b/forego/main.go @@ -2,6 +2,11 @@ package main import "os" +var ( // set at compile time via the linker + version = "v0.0.0" + githash = "000000" +) + var commands = []*Command{ cmdStart, cmdRun, diff --git a/outlet.go b/forego/outlet.go similarity index 86% rename from outlet.go rename to forego/outlet.go index 596b98a..e312c30 100644 --- a/outlet.go +++ b/forego/outlet.go @@ -13,7 +13,7 @@ import ( type OutletFactory struct { Padding int - + Color bool sync.Mutex } @@ -76,18 +76,22 @@ func (of *OutletFactory) ErrorOutput(str string) { func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, isError bool) { of.Lock() defer of.Unlock() - - ct.ChangeColor(leftC, true, ct.None, false) + + if of.Color { + ct.ChangeColor(leftC, true, ct.None, false) + } formatter := fmt.Sprintf("%%-%ds | ", of.Padding) fmt.Printf(formatter, left) - if isError { - ct.ChangeColor(ct.Red, true, ct.None, true) - } else { - ct.ResetColor() + if of.Color { + if isError { + ct.ChangeColor(ct.Red, true, ct.None, true) + } else { + ct.ResetColor() + } } fmt.Println(right) - if isError { + if of.Color && isError { ct.ResetColor() } } diff --git a/process.go b/forego/process.go similarity index 100% rename from process.go rename to forego/process.go diff --git a/procfile.go b/forego/procfile.go similarity index 100% rename from procfile.go rename to forego/procfile.go diff --git a/run.go b/forego/run.go similarity index 100% rename from run.go rename to forego/run.go diff --git a/start.go b/forego/start.go similarity index 86% rename from start.go rename to forego/start.go index 59f5e47..c8a9935 100644 --- a/start.go +++ b/forego/start.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "os/exec" "os/signal" "path/filepath" "strconv" @@ -13,18 +14,24 @@ import ( "time" ) -const defaultPort = 5000 -const defaultShutdownGraceTime = 3 +const ( + defaultPort = 5000 + defaultShutdownGraceTime = 3 +) -var flagPort int -var flagConcurrency string -var flagRestart bool -var flagShutdownGraceTime int -var envs envFiles +var ( + flagPort int + flagConcurrency string + flagRestart bool + flagNoColor bool + flagExitStatusOnError int + flagShutdownGraceTime int + envs envFiles +) var cmdStart = &Command{ Run: runStart, - Usage: "start [process name] [-f procfile] [-e env] [-p port] [-c concurrency] [-r] [-t shutdown_grace_time]", + Usage: "start [process name] [-f procfile] [-e env] [-p port] [-c concurrency] [-r] [-t shutdown_grace_time] [-n] [-s status]", Short: "Start the application", Long: ` Start the application specified by a Procfile. The directory containing the @@ -58,6 +65,11 @@ The following options are available: being asked to stop. Once this grace time expires, the process is forcibly terminated. By default, it is 3 seconds. + -n Do not colorize output. + + -s status When non-zero, exit with the provided status when a managed process + exits with an error status. + If there is a file named .forego in the current directory, it will be read in the same way as an environment file, and the values of variables procfile, port, concurrency, and shutdown_grace_time used to change the corresponding default @@ -85,6 +97,8 @@ func init() { cmdStart.Flag.IntVar(&flagPort, "p", defaultPort, "port") cmdStart.Flag.StringVar(&flagConcurrency, "c", "", "concurrency") cmdStart.Flag.BoolVar(&flagRestart, "r", false, "restart") + cmdStart.Flag.BoolVar(&flagNoColor, "n", false, "suppress") + cmdStart.Flag.IntVar(&flagExitStatusOnError, "s", 0, "status") cmdStart.Flag.IntVar(&flagShutdownGraceTime, "t", defaultShutdownGraceTime, "shutdown grace time") err := readConfigFile(".forego", &flagProcfile, &flagPort, &flagConcurrency, &flagShutdownGraceTime) handleError(err) @@ -141,11 +155,11 @@ func parseConcurrency(value string) (map[string]int, error) { } type Forego struct { - outletFactory *OutletFactory - + sync.Mutex + outletFactory *OutletFactory teardown, teardownNow Barrier // signal shutting down - - wg sync.WaitGroup + wg sync.WaitGroup + status int } func (f *Forego) monitorInterrupt() { @@ -226,7 +240,19 @@ func (f *Forego) startProcess(idx, procNum int, proc ProcfileEntry, env Env, of defer f.wg.Done() defer close(finished) pipeWait.Wait() - ps.Wait() + err := ps.Wait() + if err != nil { + f.Lock() + if e, ok := err.(*exec.ExitError); ok && !e.ProcessState.Success() { + s := e.ProcessState.Sys() + if u, ok := s.(syscall.WaitStatus); ok { + if !u.Signaled() && flagExitStatusOnError > 0 { + f.status = flagExitStatusOnError + } + } + } + f.Unlock() + } }() f.wg.Add(1) @@ -276,6 +302,7 @@ func runStart(cmd *Command, args []string) { of := NewOutletFactory() of.Padding = pf.LongestProcessName(concurrency) + of.Color = !flagNoColor f := &Forego{ outletFactory: of, @@ -327,6 +354,10 @@ func runStart(cmd *Command, args []string) { } <-f.teardown.Barrier() - f.wg.Wait() + + // all other routines have completed; no need for locking + if f.status > 0 { + os.Exit(f.status) + } } diff --git a/start_test.go b/forego/start_test.go similarity index 91% rename from start_test.go rename to forego/start_test.go index b57ca5f..15a687c 100644 --- a/start_test.go +++ b/forego/start_test.go @@ -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") @@ -151,7 +151,7 @@ func TestConfigBeOverrideByForegoFile(t *testing.T) { var port = 5000 var concurrency string = "web=2" var gracetime int = 3 - err := readConfigFile("./fixtures/configs/.forego", &procfile, &port, &concurrency, &gracetime) + err := readConfigFile("../fixtures/configs/.forego", &procfile, &port, &concurrency, &gracetime) if err != nil { t.Fatalf("Cannot set default values from forego config file") @@ -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) } } diff --git a/unix.go b/forego/unix.go similarity index 100% rename from unix.go rename to forego/unix.go diff --git a/update.go b/forego/update.go similarity index 100% rename from update.go rename to forego/update.go diff --git a/util.go b/forego/util.go similarity index 100% rename from util.go rename to forego/util.go diff --git a/version.go b/forego/version.go similarity index 100% rename from version.go rename to forego/version.go diff --git a/version_test.go b/forego/version_test.go similarity index 100% rename from version_test.go rename to forego/version_test.go diff --git a/windows.go b/forego/windows.go similarity index 100% rename from windows.go rename to forego/windows.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c129923 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/bww/forego + +go 1.15 + +require ( + github.com/daviddengcn/go-colortext v1.0.0 + github.com/subosito/gotenv v1.2.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..99e0bd4 --- /dev/null +++ b/go.sum @@ -0,0 +1,8 @@ +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/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A= +github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE= +github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA= +github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= diff --git a/vendor/github.com/daviddengcn/go-colortext/.gitignore b/vendor/github.com/daviddengcn/go-colortext/.gitignore deleted file mode 100644 index 0026861..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/.gitignore +++ /dev/null @@ -1,22 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe diff --git a/vendor/github.com/daviddengcn/go-colortext/LICENSE b/vendor/github.com/daviddengcn/go-colortext/LICENSE deleted file mode 100644 index 974ec42..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2015, David Deng -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of go-colortext nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/daviddengcn/go-colortext/README.md b/vendor/github.com/daviddengcn/go-colortext/README.md deleted file mode 100644 index 6e140f1..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/README.md +++ /dev/null @@ -1,21 +0,0 @@ -go-colortext package [![GoSearch](http://go-search.org/badge?id=github.com%2Fdaviddengcn%2Fgo-colortext)](http://go-search.org/view?id=github.com%2Fdaviddengcn%2Fgo-colortext) -==================== - -This is a package to change the color of the text and background in the console, working both under Windows and other systems. - -Under Windows, the console APIs are used. Otherwise, ANSI texts are output. - -Docs: http://godoc.org/github.com/daviddengcn/go-colortext ([packages that import ct](http://go-search.org/view?id=github.com%2fdaviddengcn%2fgo-colortext)) - -Usage: -```go -Foreground(Green, false) -fmt.Println("Green text starts here...") -ChangeColor(Red, true, White, false) -fmt.Println(...) -ResetColor() -``` - -LICENSE -======= -BSD license diff --git a/vendor/github.com/daviddengcn/go-colortext/ct.go b/vendor/github.com/daviddengcn/go-colortext/ct.go deleted file mode 100644 index 4acfaac..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/ct.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -ct package provides functions to change the color of console text. - -Under windows platform, the Console api is used. Under other systems, ANSI text mode is used. -*/ -package ct - -// Color is the type of color to be set. -type Color int - -const ( - // No change of color - None = Color(iota) - Black - Red - Green - Yellow - Blue - Magenta - Cyan - White -) - -/* -ResetColor resets the foreground and background to original colors -*/ -func ResetColor() { - resetColor() -} - -// ChangeColor sets the foreground and background colors. If the value of the color is None, -// the corresponding color keeps unchanged. -// If fgBright or bgBright is set true, corresponding color use bright color. bgBright may be -// ignored in some OS environment. -func ChangeColor(fg Color, fgBright bool, bg Color, bgBright bool) { - changeColor(fg, fgBright, bg, bgBright) -} - -// Foreground changes the foreground color. -func Foreground(cl Color, bright bool) { - ChangeColor(cl, bright, None, false) -} - -// Background changes the background color. -func Background(cl Color, bright bool) { - ChangeColor(None, false, cl, bright) -} diff --git a/vendor/github.com/daviddengcn/go-colortext/ct_ansi.go b/vendor/github.com/daviddengcn/go-colortext/ct_ansi.go deleted file mode 100644 index 6b0c5bc..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/ct_ansi.go +++ /dev/null @@ -1,35 +0,0 @@ -// +build !windows - -package ct - -import ( - "fmt" -) - -func resetColor() { - fmt.Print("\x1b[0m") -} - -func changeColor(fg Color, fgBright bool, bg Color, bgBright bool) { - if fg == None && bg == None { - return - } // if - - s := "" - if fg != None { - s = fmt.Sprintf("%s%d", s, 30+(int)(fg-Black)) - if fgBright { - s += ";1" - } // if - } // if - - if bg != None { - if s != "" { - s += ";" - } // if - s = fmt.Sprintf("%s%d", s, 40+(int)(bg-Black)) - } // if - - s = "\x1b[0;" + s + "m" - fmt.Print(s) -} diff --git a/vendor/github.com/daviddengcn/go-colortext/ct_win.go b/vendor/github.com/daviddengcn/go-colortext/ct_win.go deleted file mode 100644 index 6b41644..0000000 --- a/vendor/github.com/daviddengcn/go-colortext/ct_win.go +++ /dev/null @@ -1,139 +0,0 @@ -// +build windows - -package ct - -import ( - "syscall" - "unsafe" -) - -var fg_colors = []uint16{ - 0, - 0, - foreground_red, - foreground_green, - foreground_red | foreground_green, - foreground_blue, - foreground_red | foreground_blue, - foreground_green | foreground_blue, - foreground_red | foreground_green | foreground_blue} - -var bg_colors = []uint16{ - 0, - 0, - background_red, - background_green, - background_red | background_green, - background_blue, - background_red | background_blue, - background_green | background_blue, - background_red | background_green | background_blue} - -const ( - foreground_blue = uint16(0x0001) - foreground_green = uint16(0x0002) - foreground_red = uint16(0x0004) - foreground_intensity = uint16(0x0008) - background_blue = uint16(0x0010) - background_green = uint16(0x0020) - background_red = uint16(0x0040) - background_intensity = uint16(0x0080) - - foreground_mask = foreground_blue | foreground_green | foreground_red | foreground_intensity - background_mask = background_blue | background_green | background_red | background_intensity -) - -var ( - kernel32 = syscall.NewLazyDLL("kernel32.dll") - - procGetStdHandle = kernel32.NewProc("GetStdHandle") - procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute") - procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo") - - hStdout uintptr - initScreenInfo *console_screen_buffer_info -) - -func setConsoleTextAttribute(hConsoleOutput uintptr, wAttributes uint16) bool { - ret, _, _ := procSetConsoleTextAttribute.Call( - hConsoleOutput, - uintptr(wAttributes)) - return ret != 0 -} - -type coord struct { - X, Y int16 -} - -type small_rect struct { - Left, Top, Right, Bottom int16 -} - -type console_screen_buffer_info struct { - DwSize coord - DwCursorPosition coord - WAttributes uint16 - SrWindow small_rect - DwMaximumWindowSize coord -} - -func getConsoleScreenBufferInfo(hConsoleOutput uintptr) *console_screen_buffer_info { - var csbi console_screen_buffer_info - ret, _, _ := procGetConsoleScreenBufferInfo.Call( - hConsoleOutput, - uintptr(unsafe.Pointer(&csbi))) - if ret == 0 { - return nil - } - return &csbi -} - -const ( - std_output_handle = uint32(-11 & 0xFFFFFFFF) -) - -func init() { - kernel32 := syscall.NewLazyDLL("kernel32.dll") - - procGetStdHandle = kernel32.NewProc("GetStdHandle") - - hStdout, _, _ = procGetStdHandle.Call(uintptr(std_output_handle)) - - initScreenInfo = getConsoleScreenBufferInfo(hStdout) - - syscall.LoadDLL("") -} - -func resetColor() { - if initScreenInfo == nil { // No console info - Ex: stdout redirection - return - } - setConsoleTextAttribute(hStdout, initScreenInfo.WAttributes) -} - -func changeColor(fg Color, fgBright bool, bg Color, bgBright bool) { - attr := uint16(0) - if fg == None || bg == None { - cbufinfo := getConsoleScreenBufferInfo(hStdout) - if cbufinfo == nil { // No console info - Ex: stdout redirection - return - } - attr = getConsoleScreenBufferInfo(hStdout).WAttributes - } // if - - if fg != None { - attr = attr & ^foreground_mask | fg_colors[fg] - if fgBright { - attr |= foreground_intensity - } // if - } // if - - if bg != None { - attr = attr & ^background_mask | bg_colors[bg] - if bgBright { - attr |= background_intensity - } // if - } // if - - setConsoleTextAttribute(hStdout, attr) -} diff --git a/vendor/github.com/subosito/gotenv/.env b/vendor/github.com/subosito/gotenv/.env deleted file mode 100644 index 6405eca..0000000 --- a/vendor/github.com/subosito/gotenv/.env +++ /dev/null @@ -1 +0,0 @@ -HELLO=world diff --git a/vendor/github.com/subosito/gotenv/.gitignore b/vendor/github.com/subosito/gotenv/.gitignore deleted file mode 100644 index 7c7dff2..0000000 --- a/vendor/github.com/subosito/gotenv/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.test -annotate.json diff --git a/vendor/github.com/subosito/gotenv/LICENSE b/vendor/github.com/subosito/gotenv/LICENSE deleted file mode 100644 index f64ccae..0000000 --- a/vendor/github.com/subosito/gotenv/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2013 Alif Rachmawadi - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/vendor/github.com/subosito/gotenv/README.md b/vendor/github.com/subosito/gotenv/README.md deleted file mode 100644 index 196683f..0000000 --- a/vendor/github.com/subosito/gotenv/README.md +++ /dev/null @@ -1,102 +0,0 @@ -# gotenv - -Load environment variables dynamically in Go. - -|- | - | -|---------------|----------------------------------------------------| -| Build Status | [![Build Status][drone-img]][drone-url] | -| Coverage | [![Coverage Status][coveralls-img]][coveralls-url] | -| Documentation | http://godoc.org/github.com/subosito/gotenv | - -## Installation - -```bash -$ go get github.com/subosito/gotenv -``` - -## Usage - -Store your configuration to `.env` file on your root directory of your project: - -``` -APP_ID=1234567 -APP_SECRET=abcdef -``` - -Put the gotenv package on your `import` statement: - -```go -import "github.com/subosito/gotenv" -``` - -Then somewhere on your application code, put: - -```go -gotenv.Load() -``` - -Behind the scene it will then load `.env` file and export the valid variables to the environment variables. Make sure you call the method as soon as possible to ensure all variables are loaded, say, put it on `init()` function. - -Once loaded you can use `os.Getenv()` to get the value of the variable. - -Here's the final example: - -```go -package main - -import ( - "github.com/subosito/gotenv" - "log" - "os" -) - -func init() { - gotenv.Load() -} - -func main() { - log.Println(os.Getenv("APP_ID")) // "1234567" - log.Println(os.Getenv("APP_SECRET")) // "abcdef" -} -``` - -You can also load other than `.env` file if you wish. Just supply filenames when calling `Load()`: - -```go -gotenv.Load(".env.production", "credentials") -``` - -That's it :) - -### Another Scenario - -Just in case you want to parse environment variables from any `io.Reader`, gotenv keeps its `Parse()` function as public API so you can utilize that. - -```go -// import "strings" - -pairs := gotenv.Parse(strings.NewReader("FOO=test\nBAR=$FOO")) -// gotenv.Env{"FOO": "test", "BAR": "test"} - -pairs = gotenv.Parse(strings.NewReader(`FOO="bar"`)) -// gotenv.Env{"FOO": "bar"} -``` - -Parse ignores invalid lines and returns `Env` of valid environment variables. - -### Formats - -The gotenv supports various format for defining environment variables. You can see more about it on: - -- [fixtures](./fixtures) -- [gotenv_test.go](./gotenv_test.go) - -## Notes - -The gotenv package is a Go port of [`dotenv`](https://github.com/bkeepers/dotenv) project. Most logic and regexp pattern is taken from there and aims will be compatible as close as possible. - -[drone-img]: https://drone.io/github.com/subosito/gotenv/status.png -[drone-url]: https://drone.io/github.com/subosito/gotenv/latest -[coveralls-img]: https://coveralls.io/repos/subosito/gotenv/badge.png?branch=master -[coveralls-url]: https://coveralls.io/r/subosito/gotenv?branch=master - diff --git a/vendor/github.com/subosito/gotenv/gotenv.go b/vendor/github.com/subosito/gotenv/gotenv.go deleted file mode 100644 index c7a7b09..0000000 --- a/vendor/github.com/subosito/gotenv/gotenv.go +++ /dev/null @@ -1,119 +0,0 @@ -// Package gotenv provides functionality to dynamically load the environment variables -package gotenv - -import ( - "bufio" - "io" - "os" - "regexp" - "strings" -) - -const ( - // Pattern for detecting valid line format - linePattern = `\A(?:export\s+)?([\w\.]+)(?:\s*=\s*|:\s+?)('(?:\'|[^'])*'|"(?:\"|[^"])*"|[^#\n]+)?(?:\s*\#.*)?\z` - - // Pattern for detecting valid variable within a value - variablePattern = `(\\)?(\$)(\{?([A-Z0-9_]+)\}?)` -) - -// Holds key/value pair of valid environment variable -type Env map[string]string - -/* -Load is function to load a file or multiple files and then export the valid variables which found into environment variables. -When it's called with no argument, it will load `.env` file on the current path and set the environment variables. -Otherwise, it will loop over the filenames parameter and set the proper environment variables. - - // processing `.env` - gotenv.Load() - - // processing multiple files - gotenv.Load("production.env", "credentials") - -*/ -func Load(filenames ...string) error { - if len(filenames) == 0 { - filenames = []string{".env"} - } - - for _, filename := range filenames { - f, err := os.Open(filename) - if err != nil { - return err - } - defer f.Close() - - // set environment - env := Parse(f) - for key, val := range env { - os.Setenv(key, val) - } - } - - return nil -} - -// Parse if a function to parse line by line any io.Reader supplied and returns the valid Env key/value pair of valid variables. -// It expands the value of a variable from environment variable, but does not set the value to the environment itself. -// This function is skipping any invalid lines and only processing the valid one. -func Parse(r io.Reader) Env { - env := make(Env) - scanner := bufio.NewScanner(r) - - for scanner.Scan() { - parseLine(scanner.Text(), env) - } - - return env -} - -func parseLine(s string, env Env) { - r := regexp.MustCompile(linePattern) - matches := r.FindStringSubmatch(s) - if len(matches) == 0 { - return - } - - key := matches[1] - val := matches[2] - - // determine if string has quote prefix - hq := strings.HasPrefix(val, `"`) - - // trim whitespace - val = strings.Trim(val, " ") - - // remove quotes '' or "" - rq := regexp.MustCompile(`\A(['"])(.*)(['"])\z`) - val = rq.ReplaceAllString(val, "$2") - - if hq { - val = strings.Replace(val, `\n`, "\n", -1) - // Unescape all characters except $ so variables can be escaped properly - re := regexp.MustCompile(`\\([^$])`) - val = re.ReplaceAllString(val, "$1") - } - - rv := regexp.MustCompile(variablePattern) - xv := rv.FindStringSubmatch(val) - - if len(xv) > 0 { - var replace string - var ok bool - - if xv[1] == "\\" { - replace = strings.Join(xv[2:4], "") - } else { - replace, ok = env[xv[4]] - if !ok { - replace = os.Getenv(xv[4]) - } - } - - val = strings.Replace(val, strings.Join(xv[0:1], ""), replace, -1) - } - - env[key] = val - return -}