Merge pull request #7870 from feelancer21/check-script-fix

scripts: Direct 'lnd --help' output to a file
This commit is contained in:
Oliver Gugger 2023-08-14 12:30:29 +02:00 committed by GitHub
commit 55cc35c6ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,33 +14,37 @@ CONF_FILE=${2:-sample-lnd.conf}
# We are reading the default values of lnd from lnd --help. To avoid formatting # We are reading the default values of lnd from lnd --help. To avoid formatting
# issues the width of the terminal is set to 240. This needs a workaround for # issues the width of the terminal is set to 240. This needs a workaround for
# CI where we don't have an interactive terminal. # CI where we don't have an interactive terminal.
FILE_TMP=$(mktemp)
if [ -t 0 ]; then if [ -t 0 ]; then
size=($(stty size))
stty cols 240 stty cols 240
LND_HELP="$(go run -tags="$TAGS" \ go run -tags="$TAGS" github.com/lightningnetwork/lnd/cmd/lnd --help > \
github.com/lightningnetwork/lnd/cmd/lnd --help)"" --end" $FILE_TMP
stty cols ${size[1]}
else else
tmux new-session -d -s simulated-terminal -x 240 -y 9999 tmux new-session -d -s simulated-terminal -x 240 -y 9999
tmux send-keys -t simulated-terminal.0 "go run -tags=\"$TAGS\" \ tmux send-keys -t simulated-terminal.0 "go run -tags=\"$TAGS\" \
github.com/lightningnetwork/lnd/cmd/lnd --help; tmux wait -S run" ENTER github.com/lightningnetwork/lnd/cmd/lnd --help >"$FILE_TMP"; \
tmux wait -S run" ENTER
tmux wait-for run tmux wait-for run
LND_HELP="$(tmux capture-pane -t simulated-terminal.0 -p)"" --end"
tmux kill-session -t simulated-terminal tmux kill-session -t simulated-terminal
fi fi
LND_HELP="$(cat $FILE_TMP) --end"
# LND_OPTIONS is a list of all options of lnd including the equal sign, which # LND_OPTIONS is a list of all options of lnd including the equal sign, which
# is needed to distinguish between booleans and other variables. # is needed to distinguish between booleans and other variables.
# It is created by reading the first two columns of lnd --help. # It is created by reading the first two columns of lnd --help.
LND_OPTIONS="$(go run -tags="$TAGS" \ LND_OPTIONS="$(cat $FILE_TMP | \
github.com/lightningnetwork/lnd/cmd/lnd --help | \
awk '{ awk '{
option=""; option="";
if ($1 ~ /^--/){option=$1}; if ($1 ~ /^--/){option=$1};
if ($2 ~ /^--/){option=$2}; if ($2 ~ /^--/){option=$2};
if (match(option, /--[^=]+[=]*/) && if (match(option, /--[^=]+[=]*/))
substr(option, length(option)) != "-")
{printf "%s ", substr(option, RSTART, RLENGTH)} {printf "%s ", substr(option, RSTART, RLENGTH)}
} }
END { printf "%s", "--end"}')" END { printf "%s", "--end"}')"
rm $FILE_TMP
# OPTIONS_NO_CONF is a list of all options without any expected entries in # OPTIONS_NO_CONF is a list of all options without any expected entries in
# sample-lnd.conf. There's no validation needed for these options. # sample-lnd.conf. There's no validation needed for these options.