Skip to content

Commit db608b4

Browse files
Make shellcheck cover our .source files
...and fix them so it passes. This is to avoid issues such as #3650 [static] I tried tweaking `.pre-commit-config.yaml` instead but it didn't quite work / ended up way too complex. With only two affected files, adding a line on top and adding `+x` seems like a reasonable workaround... Signed-off-by: Martin Florian <martin.florian@digitalasset.com>
1 parent cf03bf5 commit db608b4

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

build-tools/lib/libcli.source

100644100755
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# -*- shell-script -*-
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
25

36
# common functions for use with bash based clis
47
# all functions must be prefixed with _
58

69
# make a fancy header
710
function _header(){
8-
local msg="$@"
11+
local msg="$*"
912
local vbar
1013
printf -v vbar '─%.0s' $(seq $((${#msg} +2)) )
1114
local out
@@ -30,6 +33,7 @@ function _prefix(){
3033
else
3134
cat
3235
fi | while read -r; do
36+
# shellcheck disable=SC2059
3337
printf -- "${format}" "${REPLY}"
3438
done
3539
}
@@ -60,7 +64,7 @@ function _debug() {
6064

6165
# issue a user friendly red error
6266
function _error_msg(){
63-
echo -e "\e[1;31mERROR: $@\e[0m" >&2
67+
echo -e "\e[1;31mERROR: $*\e[0m" >&2
6468
}
6569

6670
# issue a user friendly green informational message
@@ -84,12 +88,12 @@ function _warning(){
8488

8589
# prints a little green check mark before $@
8690
function _ok(){
87-
echo -e "\e[32;1m✔\e[0m ${@}"
91+
echo -e "\e[32;1m✔\e[0m $*"
8892
}
8993

9094
# prints a little red x mark before $@ and sets check to 1 if you are using it
9195
function _nope(){
92-
echo -e "\e[31;1m✘\e[0m ${@}"
96+
echo -e "\e[31;1m✘\e[0m $*"
9397
}
9498

9599

@@ -130,15 +134,16 @@ function _join(){
130134

131135
# buffer the output of a long command and output it when it is done
132136
function _pipe_buffer(){
133-
local buff="$(mktemp)"
137+
local buff
138+
buff="$(mktemp)"
134139
cat > "${buff}"
135140
cat "${buff}"
136141
}
137142

138143

139144
# just sha returns just the sha without the file names
140145
function _just_sha(){
141-
sha256sum $@ | cut -f1 -d' '
146+
sha256sum "$@" | cut -f1 -d' '
142147
}
143148

144149
# checks if a function exists
@@ -149,23 +154,24 @@ function _has_func(){
149154

150155
# copies a function
151156
function _cp_func(){
152-
_has_func $1 || return
153-
local code="$(declare -f "$1" | tail -n+2)"
157+
_has_func "$1" || return
158+
local code
159+
code="$(declare -f "$1" | tail -n+2)"
154160
eval "function ${2}()${code}"
155161
}
156162

157163

158164
# basic confirm action
159165
function _confirm(){
160166
echo -e "$@"
161-
read -p '[y/n]: '
167+
read -r -p '[y/n]: '
162168
[ "${REPLY}" == 'y' ] || exit 0
163169
}
164170

165171
# run a command with set -x
166172
function _set_x(){
167173
set -x
168-
$@ ; RC=$?
174+
"$@" ; RC=$?
169175
{ set +x; } 2>/dev/null
170176
return $RC
171177
}

cluster/scripts/utils.source

100644100755
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
17
function get_postgres_type() {
28
local instance=$1
39
local stack=$2
@@ -43,7 +49,7 @@ function get_stack_for_namespace_component() {
4349
stack="$namespace"
4450
fi
4551

46-
echo $stack
52+
echo "$stack"
4753
}
4854

4955
create_component_instance() {

0 commit comments

Comments
 (0)