Skip to content

Commit

Permalink
cqfd: config_load: avoid a for loop in flavor detection
Browse files Browse the repository at this point in the history
It is much simpler to grep the flavor option in the list of
flavors instead of comparing value by value in a for loop.
A test is added to make sure partial flavors won't be
interpreted as existing flavors.
  • Loading branch information
Olivier Dugas authored and joufellasfl committed Sep 29, 2017
1 parent 6740571 commit a02480e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 5 additions & 13 deletions cqfd
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ make_archive() {
# config_load() - load build settings from cqfdrc
# $1: optional "flavor" of the build, is a suffix of command.
config_load() {
local p_flavor="$1"

IFS="$IFS" parse_ini_config_file "$cqfdrc"

cfg.section.project # load the [project] section
Expand All @@ -245,18 +243,12 @@ config_load() {

# build parameters may be overriden by a flavor defined in the
# build section's 'flavors' parameter.
if [ -n "$p_flavor" ]; then
for flavor in $flavors; do
if [ "$flavor" = "$p_flavor" ]; then
local _found=1
break
fi
done

if [ -n "$_found" ]; then
cfg.section."$p_flavor" # load the [$p_flavor] section
local flavor="$1"
if [ -n "$flavor" ]; then
if grep -qw "$flavor" <<< "$flavors"; then
cfg.section."$flavor" # load the [$flavor] section
else
die "flavor \"$p_flavor\" not found in flavors list"
die "flavor \"$flavor\" not found in flavors list"
fi
fi

Expand Down
11 changes: 11 additions & 0 deletions tests/05-cqfd_init_flavor
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ else
jtest_result fail
fi

################################################################################
# 'cqfd init' with invalid flavor should fail
################################################################################
flavorPart="${flavor:0:2}"
jtest_prepare "cqfd init using part of '$flavor' flavor should fail"
if $cqfd -b $flavorPart init; then
jtest_result fail
else
jtest_result pass
fi

################################################################################
# 'cqfd init' without flavor generates our regular container
################################################################################
Expand Down

0 comments on commit a02480e

Please sign in to comment.