Skip to content

Commit

Permalink
Merge pull request #10 from josegonzalez/master
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
josegonzalez authored Jul 29, 2018
2 parents a156417 + 3285be9 commit 17a9b04
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ MAINTAINER = josegonzalez
MAINTAINER_NAME = Jose Diaz-Gonzalez
REPOSITORY = go-procfile-util
HARDWARE = $(shell uname -m)
BASE_VERSION ?= 0.1.2
BASE_VERSION ?= 0.2.0
IMAGE_NAME ?= $(MAINTAINER)/$(REPOSITORY)
PACKAGECLOUD_REPOSITORY ?= dokku/dokku-betafish

ifeq ($(CIRCLE_BRANCH),release)
VERSION ?= $(BASE_VERSION)
DOCKER_VERSION = $(VERSION)
else
VERSION = $(shell echo "${BASE_VERSION}")build+$(shell git rev-parse --short HEAD)
DOCKER_VERSION = $(shell echo "${BASE_VERSION}")build-$(shell git rev-parse --short HEAD)
endif

version:
Expand Down Expand Up @@ -123,7 +125,7 @@ deps:
dep ensure -vendor-only

docker-image:
docker build --rm -q -f Dockerfile.hub -t $(IMAGE_NAME):$(VERSION) .
docker build --rm -q -f Dockerfile.hub -t $(IMAGE_NAME):$(DOCKER_VERSION) .

release: build
go get -u github.com/progrium/gh-release/...
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ procfile-util exists -p non-existent
# will result in empty string for variable replacements
procfile-util expand

# specify a default-port to use (default: 5000)
procfile-util expand --default-port 3000

# expand variables with getenv used for variable expansion
# may use any variable available when executing procfile-util
procfile-util expand --allow-getenv
Expand All @@ -50,6 +53,9 @@ procfile-util expand --env-file .env

# combines getenv and .env file parsing to provide variable expansion
procfile-util expand --allow-getenv --env-file .env

# specify the default-port when performing variable expansion
procfile-util expand --allow-getenv --env-file .env --default-port 3000
```
### list

Expand All @@ -67,6 +73,10 @@ procfile-util list
# shows the command for the web process
procfile-util show -p web

# shows the command for the web process
# specify a default-port to use (default: 5000)
procfile-util show -p web --default-port 3000

# shows the command for the web process
# expand variables with getenv used for variable expansion
# may use any variable available when executing procfile-util
Expand All @@ -79,4 +89,8 @@ procfile-util show -p web --env-file .env
# shows the command for the web process
# combines getenv and .env file parsing to provide variable expansion
procfile-util show -p web --allow-getenv --env-file .env

# shows the command for the web process
# specify the default-port when performing variable expansion
procfile-util show web --allow-getenv --env-file .env --default-port 3000
```
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type procfileEntry struct {
Command string
}

const defaultPort = "5000"
const portEnvVar = "PORT"

// Version contains the procfile-util version
Expand Down Expand Up @@ -91,7 +90,7 @@ func parseProcfile(path string, delimiter string) ([]procfileEntry, error) {
return entries, nil
}

func expandEnv(e procfileEntry, envPath string, allowEnv bool) (string, error) {
func expandEnv(e procfileEntry, envPath string, allowEnv bool, defaultPort string) (string, error) {
baseExpandFunc := func(key string) string {
if key == "PS" {
return os.Getenv("PS")
Expand Down Expand Up @@ -176,11 +175,11 @@ func existsCommand(entries []procfileEntry, processType string) bool {
return false
}

func expandCommand(entries []procfileEntry, envPath string, allowGetenv bool, processType string) bool {
func expandCommand(entries []procfileEntry, envPath string, allowGetenv bool, processType string, defaultPort string) bool {
hasErrors := false
commands := make(map[string]string)
for _, entry := range entries {
command, err := expandEnv(entry, envPath, allowGetenv)
command, err := expandEnv(entry, envPath, allowGetenv, defaultPort)
if err != nil {
fmt.Fprintf(os.Stderr, "error processing command: %s\n", err)
hasErrors = true
Expand Down Expand Up @@ -208,7 +207,7 @@ func listCommand(entries []procfileEntry) bool {
return true
}

func showCommand(entries []procfileEntry, envPath string, allowGetenv bool, processType string) bool {
func showCommand(entries []procfileEntry, envPath string, allowGetenv bool, processType string, defaultPort string) bool {
var foundEntry procfileEntry
for _, entry := range entries {
if processType == entry.Name {
Expand All @@ -222,7 +221,7 @@ func showCommand(entries []procfileEntry, envPath string, allowGetenv bool, proc
return false
}

command, err := expandEnv(foundEntry, envPath, allowGetenv)
command, err := expandEnv(foundEntry, envPath, allowGetenv, defaultPort)
if err != nil {
fmt.Fprintf(os.Stderr, "error processing command: %s\n", err)
return false
Expand All @@ -237,6 +236,7 @@ func main() {
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"})
defaultPortFlag := parser.String("d", "default-port", &argparse.Options{Default: "5000", Help: "default port to use"})

existsCmd := parser.NewCommand("exists", "check if a process type exists")
processTypeExistsFlag := existsCmd.String("p", "process-type", &argparse.Options{Help: "name of process to retrieve"})
Expand Down Expand Up @@ -281,11 +281,11 @@ func main() {
} else if existsCmd.Happened() {
success = existsCommand(entries, *processTypeExistsFlag)
} else if expandCmd.Happened() {
success = expandCommand(entries, *envPathExpandFlag, *allowGetenvExpandFlag, *processTypeExpandFlag)
success = expandCommand(entries, *envPathExpandFlag, *allowGetenvExpandFlag, *processTypeExpandFlag, *defaultPortFlag)
} else if listCmd.Happened() {
success = listCommand(entries)
} else if showCmd.Happened() {
success = showCommand(entries, *envPathShowFlag, *allowGetenvShowFlag, *processTypeShowFlag)
success = showCommand(entries, *envPathShowFlag, *allowGetenvShowFlag, *processTypeShowFlag, *defaultPortFlag)
} else {
fmt.Print(parser.Usage(err))
}
Expand Down

0 comments on commit 17a9b04

Please sign in to comment.