From 34c945242f44ec2b3fedf663120ac521aea5cde5 Mon Sep 17 00:00:00 2001 From: Chris Kalafarski Date: Thu, 9 Mar 2023 11:03:54 -0500 Subject: [PATCH 1/2] Support custom app directory location --- README.md | 3 +-- cmd/puma-dev/main_darwin.go | 2 +- cmd/puma-dev/main_linux.go | 2 +- dev/get_env.go | 8 ++++++++ 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 dev/get_env.go diff --git a/README.md b/README.md index 084f0cf..8a3da77 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ On systems with SELinux you may have to run `restorecon /path/to/puma-dev` in or Simply symlink your app's directory into `~/.puma-dev`! That's it! -You can use the built-in helper subcommand: `puma-dev link [-n name] [dir]` to link app directories into your puma-dev directory (`~/.puma-dev` by default). +You can use the built-in helper subcommand: `puma-dev link [-n name] [dir]` to link app directories into your puma-dev directory (`~/.puma-dev` by default, but can be changed with `PUMA_DEV_APP_DIR`). ### Options @@ -352,4 +352,3 @@ To build puma-dev, follow these steps: Tagged builds (e.g `v0.18.0`) will automatically create [pre-release](https://github.com/puma/puma-dev/releases) with artifacts for use in the Homebrew formula. All [builds with passing tests](https://github.com/puma/puma-dev/actions) will publish binaries that are saved for 90 days. - diff --git a/cmd/puma-dev/main_darwin.go b/cmd/puma-dev/main_darwin.go index 11fdbdb..0ad471e 100644 --- a/cmd/puma-dev/main_darwin.go +++ b/cmd/puma-dev/main_darwin.go @@ -21,7 +21,7 @@ var ( fDNSPort = flag.Int("dns-port", 9253, "port to listen on dns for") fHTTPPort = flag.Int("http-port", 9280, "port to listen on http for") fTLSPort = flag.Int("https-port", 9283, "port to listen on https for") - fDir = flag.String("dir", "~/.puma-dev", "directory to watch for apps") + fDir = flag.String("dir", dev.GetEnv("PUMA_DEV_APP_DIR", "~/.puma-dev"), "directory to watch for apps") fTimeout = flag.Duration("timeout", 15*60*time.Second, "how long to let an app idle for") fPow = flag.Bool("pow", false, "Mimic pow's settings") fLaunch = flag.Bool("launchd", false, "Use socket from launchd") diff --git a/cmd/puma-dev/main_linux.go b/cmd/puma-dev/main_linux.go index b0e4a9f..ac3f975 100644 --- a/cmd/puma-dev/main_linux.go +++ b/cmd/puma-dev/main_linux.go @@ -17,7 +17,7 @@ import ( var ( fDebug = flag.Bool("debug", false, "enable debug output") - fDir = flag.String("dir", "~/.puma-dev", "directory to watch for apps") + fDir = flag.String("dir", dev.GetEnv("PUMA_DEV_APP_DIR", "~/.puma-dev"), "directory to watch for apps") fDomains = flag.String("d", "test", "domains to handle, separate with :, defaults to test") fHTTPPort = flag.Int("http-port", 9280, "port to listen on http for") fNoServePublicPaths = flag.String("no-serve-public-paths", "", "Disable static file server for specific paths under /public") diff --git a/dev/get_env.go b/dev/get_env.go new file mode 100644 index 0000000..25324ad --- /dev/null +++ b/dev/get_env.go @@ -0,0 +1,8 @@ +package dev + +func GetEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} From 8cf18e3a45fbfcb085a8e23937cab7107bf8cecf Mon Sep 17 00:00:00 2001 From: Chris Kalafarski Date: Thu, 9 Mar 2023 11:10:49 -0500 Subject: [PATCH 2/2] Fix whitespace --- dev/get_env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/get_env.go b/dev/get_env.go index 25324ad..765928b 100644 --- a/dev/get_env.go +++ b/dev/get_env.go @@ -2,7 +2,7 @@ package dev func GetEnv(key, fallback string) string { if value, ok := os.LookupEnv(key); ok { - return value + return value } return fallback }