Skip to content

Commit

Permalink
Merge pull request #11 from josegonzalez/master
Browse files Browse the repository at this point in the history
Release 0.3.0
  • Loading branch information
josegonzalez authored Aug 18, 2018
2 parents 17a9b04 + 0f0a5d0 commit 53ea0ee
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER = josegonzalez
MAINTAINER_NAME = Jose Diaz-Gonzalez
REPOSITORY = go-procfile-util
HARDWARE = $(shell uname -m)
BASE_VERSION ?= 0.2.0
BASE_VERSION ?= 0.3.0
IMAGE_NAME ?= $(MAINTAINER)/$(REPOSITORY)
PACKAGECLOUD_REPOSITORY ?= dokku/dokku-betafish

Expand Down
32 changes: 31 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,39 @@ const portEnvVar = "PORT"
// Version contains the procfile-util version
var Version string

// Loglevel stores the current app log level
var Loglevel = "info"

func logMessage(message string, level string) {
if level == "info" {
fmt.Println(message)
return
}

if Loglevel == "debug" {
fmt.Fprintf(os.Stderr, fmt.Sprintf("%v\n", message))
}
}

func debugMessage(message string) {
logMessage(message, "debug")
}

func infoMessage(message string) {
logMessage(message, "info")
}

func getProcfile(path string) (string, error) {
if !termutil.Isatty(os.Stdin.Fd()) {
debugMessage("Reading input from stdin")
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return "", err
}
return string(bytes), nil
}

debugMessage(fmt.Sprintf("Reading input from file: %v", path))
f, err := os.Open(path)
if err != nil {
return "", err
Expand Down Expand Up @@ -66,6 +90,7 @@ func parseProcfile(path string, delimiter string) ([]procfileEntry, error) {

params := re.FindStringSubmatch(line)
if len(params) != 3 {
debugMessage(fmt.Sprintf("No matching params in line: %v", line))
continue
}

Expand Down Expand Up @@ -106,6 +131,7 @@ func expandEnv(e procfileEntry, envPath string, allowEnv bool, defaultPort strin
}

if allowEnv {
debugMessage("Allowing getenv variable expansion")
expandFunc = func(key string) string {
value := os.Getenv(key)
if value == "" {
Expand All @@ -127,6 +153,7 @@ func expandEnv(e procfileEntry, envPath string, allowEnv bool, defaultPort strin
return "", err
}

debugMessage("Allowing .env variable expansion")
expandFunc = func(key string) string {
if val, ok := env[key]; ok {
return val
Expand Down Expand Up @@ -232,7 +259,8 @@ func showCommand(entries []procfileEntry, envPath string, allowGetenv bool, proc
}

func main() {
parser := argparse.NewParser("procfile-parser", "A procfile parsing tool")
parser := argparse.NewParser("procfile-util", "A procfile parsing tool")
loglevelFlag := parser.Selector("l", "loglevel", []string{"info", "debug"}, &argparse.Options{Default: "info", Help: "loglevel to use"})
procfileFlag := parser.String("P", "procfile", &argparse.Options{Default: "Procfile", Help: "path to a procfile"})
delimiterFlag := parser.String("D", "delimiter", &argparse.Options{Default: ":", Help: "delimiter in use within procfile"})
versionFlag := parser.Flag("v", "version", &argparse.Options{Help: "show version"})
Expand Down Expand Up @@ -268,6 +296,8 @@ func main() {
return
}

Loglevel = *loglevelFlag

entries, err := parseProcfile(*procfileFlag, *delimiterFlag)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
Expand Down

0 comments on commit 53ea0ee

Please sign in to comment.