From 3eb2ab2fa3c5471042ed0f1ea79b28c5a2c60ff9 Mon Sep 17 00:00:00 2001 From: Diego Quintero Date: Sat, 8 Jul 2023 02:45:33 +0000 Subject: [PATCH] fix(build): #1002 args manage ports fix - sourcing `shellCommands` into `managePorts` builtin Signed-off-by: Diego Quintero --- .mailmap | 2 ++ src/args/make-template/default.nix | 2 +- src/args/manage-ports/default.nix | 4 ++++ src/args/manage-ports/template.sh | 12 +++++++----- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.mailmap b/.mailmap index 17a620af..b401f463 100644 --- a/.mailmap +++ b/.mailmap @@ -6,6 +6,8 @@ Daniel Salazar Daniel Salazar David Acevedo David Acevedo David Arnold David Arnold David Arnold David Arnold +Diego Quintero Diego Quintero <57577966+este6an13@users.noreply.github.com> +Diego Quintero Diego Quintero Diego Restrepo Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com> Diego Restrepo Diego Restrepo Diego Restrepo Diego Restrepo Mesa <36453706+drestrepom@users.noreply.github.com> diff --git a/src/args/make-template/default.nix b/src/args/make-template/default.nix index a6e39b39..cb0bdef9 100644 --- a/src/args/make-template/default.nix +++ b/src/args/make-template/default.nix @@ -25,7 +25,7 @@ then abort '' - Ivalid placeholder: ${k} + Invalid placeholder: ${k} Placeholders must match: ${argumentRegex} For example: __argExample123__ diff --git a/src/args/manage-ports/default.nix b/src/args/manage-ports/default.nix index 5b916566..7b214244 100644 --- a/src/args/manage-ports/default.nix +++ b/src/args/manage-ports/default.nix @@ -1,9 +1,13 @@ { __nixpkgs__, makeTemplate, + __shellCommands__, ... }: makeTemplate { + replace = { + __argShellCommands__ = __shellCommands__; + }; name = "manage-ports"; searchPaths = { bin = [ diff --git a/src/args/manage-ports/template.sh b/src/args/manage-ports/template.sh index f6b128c5..48291aa2 100644 --- a/src/args/manage-ports/template.sh +++ b/src/args/manage-ports/template.sh @@ -1,23 +1,25 @@ # shellcheck shell=bash +source __argShellCommands__ + function _kill_port { local pids local port="${1}" pids="$(mktemp)" \ && if ! lsof -t "-i:${port}" > "${pids}"; then - info "Nothing listening on port: ${port}" \ + info "No process was found listening on port ${port}" \ && return 0 fi \ && while read -r pid; do if kill -9 "${pid}"; then if timeout 5 tail --pid="${pid}" -f /dev/null; then - info "Killed pid: ${pid}, listening on port: ${port}" + info "Process listening on port ${port} with PID ${pid} was successfully killed" else - warn "kill timeout pid: ${pid}, listening on port: ${port}" + warn "Timeout while attempting to kill process with PID ${pid} listening on port ${port}" fi else - error "Unable to kill pid: ${pid}, listening on port: ${port}" + error "Unable to kill process with PID ${pid} listening on port ${port}" fi done < "${pids}" } @@ -50,7 +52,7 @@ function wait_for_tcp { error "Timeout while waiting for ${host}:${port} to open" \ && return 1 else - info "Waiting 1 second for ${host}:${port} to open, ${elapsed} seconds in total" \ + info "Waiting 1 second for ${host}:${port} to open: ${elapsed} seconds in total" \ && sleep 1 \ && elapsed="$(("${elapsed}" + 1))" \ && continue