From b8e9b5fe5a6d7667b7929e29f1b03c16d5bfd611 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 18 Aug 2018 09:58:09 -0500 Subject: [PATCH 1/3] feat: add debug logging --- main.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/main.go b/main.go index 03ccd65..67b29e8 100644 --- a/main.go +++ b/main.go @@ -23,8 +23,31 @@ 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 @@ -32,6 +55,7 @@ func getProcfile(path string) (string, error) { return string(bytes), nil } + debugMessage(fmt.Sprintf("Reading input from file: %v", path)) f, err := os.Open(path) if err != nil { return "", err @@ -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 } @@ -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 == "" { @@ -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 @@ -233,6 +260,7 @@ func showCommand(entries []procfileEntry, envPath string, allowGetenv bool, proc func main() { parser := argparse.NewParser("procfile-parser", "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"}) @@ -268,6 +296,8 @@ func main() { return } + Loglevel = *loglevelFlag + entries, err := parseProcfile(*procfileFlag, *delimiterFlag) if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) From a24239d6bf1076940c1a114b0ecf9c37ff4ab108 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 18 Aug 2018 09:58:45 -0500 Subject: [PATCH 2/3] fix: set correct bin name --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 67b29e8..394a196 100644 --- a/main.go +++ b/main.go @@ -259,7 +259,7 @@ 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"}) From 0f0a5d0d1648961ac83c0d84f8ea697fcc52e448 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 18 Aug 2018 10:00:25 -0500 Subject: [PATCH 3/3] Release 0.3.0 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d3260bc..8c9646b 100644 --- a/Makefile +++ b/Makefile @@ -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