aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-09-08 17:34:12 +0000
committermerakor <cem@ckyln.com>2021-09-08 17:34:12 +0000
commit1ff783d1ccb17fbf702f352812ae7eb834fed3ee (patch)
treea55376def230cc2bf3b14aa34467c13ea845e1f0
parent8ccb6ca3acdec76fdb279ed61ba21694e3efe5ab (diff)
downloadcpt-1ff783d1ccb17fbf702f352812ae7eb834fed3ee.tar.gz
log(): change print function depending on number of arguments
FossilOrigin-Name: 9628d8c0a2b3f6cb9b78898701aace71a1f4d1aec8b98b55f75acb34c21b4ddd
-rw-r--r--spec/01_lib_spec.sh2
-rw-r--r--spec/02_src_spec.sh2
-rw-r--r--src/cpt-lib.in8
3 files changed, 8 insertions, 4 deletions
diff --git a/spec/01_lib_spec.sh b/spec/01_lib_spec.sh
index b56ac32..29bd05a 100644
--- a/spec/01_lib_spec.sh
+++ b/spec/01_lib_spec.sh
@@ -162,7 +162,7 @@ Describe 'CPT Library'
End
It "doesn't log 'running hook' if no package is given"
When call run_hook 2 '' destination
- The stderr should eq "-> Running 2 hook "
+ The stderr should eq "-> Running 2 hook"
The output should eq "$CPT_HOOK 2 null destination"
End
It "uses the /etc/cpt-hook file of the root when called with a fourth arg"
diff --git a/spec/02_src_spec.sh b/spec/02_src_spec.sh
index be81775..5286ab9 100644
--- a/spec/02_src_spec.sh
+++ b/spec/02_src_spec.sh
@@ -20,7 +20,7 @@ Describe 'Main toolchain'
Describe '--help'
It 'outputs usage information'
When run script src/cpt --help
- The line 1 of stderr should eq "-> Carbs Packaging Tool "
+ The line 1 of stderr should eq "-> Carbs Packaging Tool"
End
End
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index 58c9a0f..1d3a0de 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -28,8 +28,12 @@ log() {
#
# '${3:-->}': If the 3rd argument is missing, set prefix to '->'.
# '${2:+colorb}': If the 2nd argument exists, set text style of '$1'.
- printf '%b%s %b%b%s%b %s\n' \
- "$colory" "${3:-->}" "$colre" "${2:+$colorb}" "$1" "$colre" "$2" >&2
+ case $# in
+ 1) printf '%b->%b %s\n' "$colory" "$colre" "$1" ;;
+ 2) printf '%b->%b %b%s%b %s\n' "$colory" "$colre" "$colorb" "$1" "$colre" "$2" ;;
+ 3) printf '%b%s%b %b%s%b %s\n' "$colory" "${3:-->}" "$colre" "$colorb" "$1" "$colre" "$2" ;;
+ *) return 1
+ esac >&2
}
warn() {