From 76986927eb98873737aa5839abf2d578fd75cc0b Mon Sep 17 00:00:00 2001 From: 3wc <3wc.git@doesthisthing.work> Date: Sat, 12 Sep 2020 14:00:28 +0200 Subject: [PATCH] Allow passing arguments to `logs` --- abra | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/abra b/abra index f89c9e2..7723a09 100755 --- a/abra +++ b/abra @@ -24,10 +24,11 @@ sub_help() { echo "Usage: $PROGRAM_NAME [-a STACK_NAME] [options]" echo "" echo "Subcommands:" - echo " run SERVICE [CMD] run a command in the specified service's container" + echo " run SERVICE CMD run a command in the specified service's container" + echo " run_args SERVICE ARGS CMD run, passing extra args to docker exec" echo " secret_generate SECRET VERSION [CMD] generate a secret, store it in pass & as a Docker secret" echo " deploy [COMPOSE_FILE] let 'em rip" - echo " logs SERVICE tail logs from a deployed service" + echo " logs SERVICE [ARGS] tail logs from a deployed service" echo " ... (custom commands)" echo "" echo "Make sure \$STACK_NAME is set using direnv or -a" @@ -50,7 +51,7 @@ sub_secret_generate(){ sub_run_args(){ SERVICE=$1 - ARGS=$2 + DOCKER_ARGS=$2 shift 2 @@ -67,7 +68,7 @@ sub_run_args(){ exit fi - docker exec $ARGS -it "$CONTAINER" $@ + docker exec $DOCKER_ARGS -it "$CONTAINER" $@ return } @@ -106,11 +107,19 @@ sub_deploy (){ sub_logs (){ SERVICE=$1 - docker service logs "${STACK_NAME}_${SERVICE}" \ + shift + + if [ $# -eq 0 ]; then + LOGS_ARGS="\ --follow \ --no-trunc \ --details \ - --timestamps + --timestamps" + else + LOGS_ARGS="$@" + fi + + docker service logs "${STACK_NAME}_${SERVICE}" $LOGS_ARGS } subcommand=$1