Skip to content

Commit 6d15d9f

Browse files
committed
recognize if tty
1 parent d37b642 commit 6d15d9f

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

.bin/argsh

+6-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ source "${PATH_BASE}/libraries/docker.sh"
1717
###
1818
test::docs() {
1919
:args "Run tests for the documentation" "${@}"
20-
docker run --rm -it $(docker::user) node:21-alpine sh -c "
20+
docker run --rm $(docker::user) node:21-alpine sh -c "
2121
cd /workspace/www
2222
[ -d node_modules ] || yarn --silent --frozen-lockfile
2323
yarn build
@@ -26,7 +26,7 @@ test::docs() {
2626

2727
lint::docs() {
2828
:args "Run linters for the documentation" "${@}"
29-
docker run --rm -it $(docker::user) node:21-alpine sh -c "
29+
docker run --rm $(docker::user) node:21-alpine sh -c "
3030
cd /workspace/www
3131
[ -d node_modules ] || yarn --silent --frozen-lockfile
3232
yarn lint:content
@@ -38,7 +38,7 @@ lint::vale() {
3838
:args "Run vale for the documentation" "${@}"
3939
local alert_level="${vale?"need to specify alert level"}"
4040
binary::exists docker || exit 1
41-
docker run --rm -it $(docker::user) jdkato/vale:latest sh -c "
41+
docker run --rm $(docker::user) jdkato/vale:latest sh -c "
4242
cd /workspace/www/vale
4343
./run-vale.sh docs content \"${alert_level}\"
4444
"
@@ -101,8 +101,10 @@ argsh::docker() {
101101
### main
102102
###
103103
argsh::main() {
104+
local tty=""
105+
[[ -t 1 ]] && tty="-it"
104106
# shellcheck disable=SC2046
105-
docker run --rm -it $(docker::user) \
107+
docker run --rm ${tty} $(docker::user) \
106108
-e "BATS_LOAD" \
107109
-e "ARGSH_SOURCE" \
108110
-e "GIT_COMMIT_SHA=$(git rev-parse HEAD || :)" \

libraries/docker.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ docker::user() {
2828

2929
echo "${user}:x:${uid}:${gid}::${home}:${shell}" > /tmp/docker_passwd
3030
echo "${user}:x:${gid}:" > /tmp/docker_group
31-
32-
echo -v "${PATH_BASE:-.}:${home}"
33-
echo -v /tmp/docker_passwd:/etc/passwd -v /tmp/docker_group:/etc/group
34-
echo -u "${uid}:${gid}"
35-
echo -w "${home}"
31+
echo "-v /tmp/docker_passwd:/etc/passwd -v /tmp/docker_group:/etc/group"
32+
echo "-u ${uid}:${gid}"
33+
34+
echo "-v ${PATH_BASE:-.}:${home}"
35+
echo "-w ${home}"
3636
}

libraries/fmt.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ set -euo pipefail
1414
# cat file.txt | fmt::tty
1515
fmt::tty() {
1616
local str="${1:-"$(cat)"}"
17-
command -v fmt &>/dev/null || {
17+
if ! command -v fmt &>/dev/null || [[ ! -t 1 ]]; then
1818
echo "${str}"
1919
return 0
20-
}
20+
fi
2121

2222
local cols
2323
cols="$(tput cols)"

libraries/main.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ argsh::shebang() {
2727
echo "This script requires Docker to be installed"
2828
return 1
2929
} >&2
30+
local tty=""
31+
[[ -t 1 ]] && tty="-it"
3032
# shellcheck disable=SC2046
31-
docker run --rm -it $(docker::user) \
33+
docker run --rm ${tty} $(docker::user) \
3234
-e "BATS_LOAD" \
3335
-e "ARGSH_SOURCE" \
3436
-e "GIT_COMMIT_SHA=$(git rev-parse HEAD || :)" \

0 commit comments

Comments
 (0)