-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
excluded windows from travis uploading linux and darwin bins on release removed caps restriction to env vars removed osx from travis builds too fixed missing err handling for writer flush
- Loading branch information
Showing
3 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
language: go | ||
env: | ||
- GIMME_OS=linux GIMME_ARCH=amd64 | ||
- GIMME_OS=darwin GIMME_ARCH=amd64 | ||
- GIMME_OS=windows GIMME_ARCH=amd64 | ||
# - GIMME_OS=darwin GIMME_ARCH=amd64 | ||
# - GIMME_OS=windows GIMME_ARCH=amd64 | ||
sudo: required | ||
go: | ||
- 1.6.3 | ||
- 1.7 | ||
- 1.8.3 | ||
- 1.9 | ||
- tip | ||
install: | ||
- go get -d -v -t ./... | ||
script: | ||
- export GOMAXPROCS=$(nproc) GOOS=$GIMME_OS GOARCH=$GIMME_ARCH | ||
# TODO test seems to fail on non linux platforms @ travis | ||
# - go test -v -timeout=30s ./... | ||
- go test -v -timeout=30s ./... | ||
- go build -o tg ./cli/cli.go | ||
deploy: | ||
provider: releases | ||
api_key: | ||
secure: lS4Qrv2X+BRhUBUTgFPI1EfzvJDOMFDhHlNhCa1CNT4faA8HDVcLj79HUz6NenD6voT+FgV2UgmPRD/Yx+UkoTkbKAsZGf3j/XlRK3zeb8zPf7ZPulgMGKPVOeoe9S7XLtLL+/Yhu9v3BMpM+qIgto6Pqa1CJgtfh27yGZTwxLQ11rblQ2RCHSxxckZJ+/e7G7J1rR8kSReXULw2QkH9F1YW4Yp725d6v40cM9ReyuGhbBMrwZtPoTQfmasN82JMmWURLZrhvGbPGUQ0msO0xwXae6wQQ6kbn2q5j5PJzrZ8ChgyOMFYEIOFd9U8BAqaLZdbXuqkpw1vEVl59XGO6tZ/d9pQMKSO7Eo4tf+ZbR6/AlQrlWX0zJ0at62vyqLPFgB5ymArOf3xrrTmPor4KKC4X08ibGlJ0Y1HVus2lXxmfUDzdaEdWN6X8AjpHXkp8YA+PWIGi0fNCaStV7rMCeKvztX139SLkBo8aPfXb6qJa91b4u3Cud5j3JpbGEjyHxpjnTvzsdXl5dycz07Pg+qjTukufC0yUVAqYlDgdo2z+F1QSUzPyZIw30xisFfIPnguD9i//9Gw+ENrFbEaOqKqyJKOzeKk9Fxg00/mpvaf2Kfy2sFFpvO8S4d4c7lJ6CyJuf0NJ8nC4ZImpvCYyLsHNOThpObZpdDui/D+XbQ= | ||
file: tg | ||
file: | ||
- tg | ||
skip_cleanup: true | ||
on: | ||
tags: true | ||
matrix: | ||
fast_finish: true | ||
allow_failures: | ||
- go: tip | ||
exclude: | ||
- go: 1.6.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/malud/temgo/temgo" | ||
"bufio" | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
|
||
"github.com/malud/temgo/temgo" | ||
) | ||
|
||
var envVars = make(temgo.EnvVars) | ||
var inlineFlag = flag.String("i", "", "-i filename") | ||
|
||
// Initialize and filter all non upper case variables. | ||
func init() { | ||
for _, e := range os.Environ() { | ||
string := strings.Split(e, "=") | ||
if strings.Compare(string[0], strings.ToUpper(string[0])) == 0 { | ||
envVars[string[0]] = string[1] | ||
} | ||
envVars[string[0]] = string[1] | ||
} | ||
|
||
if !flag.Parsed() { | ||
flag.Parse() | ||
} | ||
} | ||
|
||
func main() { | ||
var writeErr error | ||
input := os.Stdin | ||
bytes, err := ioutil.ReadAll(input) | ||
if err != nil { | ||
_, writeErr = os.Stderr.WriteString(fmt.Sprintf("Could not read: %v", err)) | ||
var rw *bufio.ReadWriter | ||
var file *os.File | ||
if *inlineFlag != "" { | ||
var err error | ||
file, err = os.OpenFile(*inlineFlag, os.O_RDWR, 644) | ||
must(err) | ||
defer file.Close() | ||
rw = bufio.NewReadWriter(bufio.NewReader(file), bufio.NewWriter(file)) | ||
} else { | ||
rw = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)) | ||
} | ||
|
||
bytes, err := ioutil.ReadAll(rw) | ||
must(err) | ||
|
||
if temgo.ContainsVariable(bytes) { | ||
str := envVars.ReplaceVariables(bytes) | ||
_, err = os.Stdout.Write(str) | ||
if err != nil { | ||
_, writeErr = os.Stderr.WriteString(fmt.Sprintf("Could not write: %v", err)) | ||
if file != nil { | ||
truncate(file) | ||
} | ||
_, err := rw.Write(str) | ||
must(err) | ||
must(rw.Flush()) | ||
} | ||
if writeErr != nil { | ||
panic(writeErr) | ||
} | ||
|
||
// fatal | ||
func must(err error) { | ||
if err != nil { | ||
println("Err:", err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func truncate(file *os.File) { | ||
err := file.Truncate(0) | ||
must(err) | ||
_, err = file.Seek(0, 0) | ||
must(err) | ||
} |
5c439f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added inline edit #1