From 2a3ea6aa4f6bfa6495932e9f1144cd96f0b2c15b Mon Sep 17 00:00:00 2001 From: milkeclair Date: Sun, 15 Nov 2026 12:57:43 +0900 Subject: [PATCH 1/5] refactor: capture core values without success guards --- lib/arg/analysis.zsh | 4 +- lib/arg/is/operator.zsh | 7 ++- lib/arg/process.zsh | 19 ++++++-- lib/arr/operator.zsh | 8 ++- lib/arr/process.zsh | 65 ++++++++++++++++++------- lib/dir/process.zsh | 6 ++- lib/file/process.zsh | 17 +++++-- lib/file/read/process.zsh | 10 ++-- lib/file/write/process.zsh | 7 ++- lib/hash/has/not/operator.zsh | 14 ++++-- lib/hash/has/operator.zsh | 14 ++++-- lib/hash/process.zsh | 7 ++- lib/io/error/process.zsh | 16 ++++-- lib/io/process.zsh | 48 +++++++++++++----- lib/io/success/process.zsh | 16 ++++-- lib/io/warn/process.zsh | 16 ++++-- lib/perm/process.zsh | 28 ++++++++--- lib/str/color/process.zsh | 7 ++- lib/str/match/process.zsh | 4 +- lib/str/process.zsh | 57 ++++++++++++++++------ lib/t/dsl.zsh | 3 +- lib/t/expect.zsh | 6 ++- lib/t/expect/include.zsh | 6 ++- lib/t/expect/reply.zsh | 4 +- lib/t/expect/reply/excludes.zsh | 4 +- lib/t/expect/reply/includes.zsh | 4 +- lib/t/expect/reply/is/not/null.zsh | 4 +- lib/t/expect/reply/is/null.zsh | 4 +- lib/t/expect/status.zsh | 3 +- lib/t/log/dot.zsh | 3 +- lib/t/log/failure.zsh | 6 ++- lib/t/mock.zsh | 7 ++- lib/t/mock/call_original.zsh | 3 +- lib/t/mock/result.zsh | 3 +- lib/t/mock/unmock.zsh | 6 ++- lib/t/process.zsh | 6 ++- lib/t/state/current_idx.zsh | 7 ++- lib/t/state/logs.zsh | 7 ++- lib/t/state/mock_calls.zsh | 14 ++++-- lib/t/state/mock_originals.zsh | 7 ++- lib/update/archive/process.zsh | 6 +-- lib/update/core/process.zsh | 4 +- lib/update/installation/is/operator.zsh | 2 +- lib/update/installation/process.zsh | 8 +-- lib/update/mod/analysis.zsh | 2 +- lib/update/mod/process.zsh | 6 +-- lib/update/process.zsh | 2 +- test/lib/arg/process_test.zsh | 11 +++++ 48 files changed, 371 insertions(+), 147 deletions(-) diff --git a/lib/arg/analysis.zsh b/lib/arg/analysis.zsh index 60b40a2..e1ce1c2 100644 --- a/lib/arg/analysis.zsh +++ b/lib/arg/analysis.zsh @@ -8,7 +8,9 @@ # example: # z.arg.get "a" "b" "c" index=2 #=> "b" z.arg.get() { - z.arg.named index $@ && local index=$REPLY + z.arg.named index $@ + local index=$REPLY + z.arg.named.shift index $@ local args=($REPLY) z.arr.count $args diff --git a/lib/arg/is/operator.zsh b/lib/arg/is/operator.zsh index 0e6b191..29eb751 100644 --- a/lib/arg/is/operator.zsh +++ b/lib/arg/is/operator.zsh @@ -39,8 +39,11 @@ z.arg.is.empty() { # z.arg.is.valid "a" "b" "c" length=2 #=> 0 # z.arg.is.valid "a" "b" "c" length=4 #=> 1 z.arg.is.valid() { - z.arg.named length $@ && local length=$REPLY - z.arg.named.shift length $@ && local args=($REPLY) + z.arg.named length $@ + local length=$REPLY + + z.arg.named.shift length $@ + local args=($REPLY) local message="Expected at least $length arguments, but got ${#args}" if z.int.is.lt ${#args} $length; then diff --git a/lib/arg/process.zsh b/lib/arg/process.zsh index b45f567..112c456 100644 --- a/lib/arg/process.zsh +++ b/lib/arg/process.zsh @@ -12,11 +12,20 @@ # z.arg.as name=$1 as="-h|--help" #=> REPLY="" z.arg.as() { local args=($@) - z.arg.named name $args && local name=$REPLY - z.arg.named.shift name $args && args=($REPLY) - z.arg.named as $args && local as=$REPLY - z.arg.named.shift as $args && args=($REPLY) - z.arg.named return $args && local return=$REPLY + z.arg.named name $args + local name=$REPLY + + z.arg.named.shift name $args + args=($REPLY) + + z.arg.named as $args + local as=$REPLY + + z.arg.named.shift as $args + args=($REPLY) + + z.arg.named return $args + local return=$REPLY z.str.split str=$as local split_as=($REPLY[@]) diff --git a/lib/arr/operator.zsh b/lib/arr/operator.zsh index e582b13..51147dc 100644 --- a/lib/arr/operator.zsh +++ b/lib/arr/operator.zsh @@ -9,7 +9,9 @@ # z.arr.includes target=apple "banana" "apple" "cherry" #=> 0 (true) # z.arr.includes target=grape "banana" "apple" "cherry" #=> 1 (false) z.arr.includes() { - z.arg.named target $@ && local target=$REPLY + z.arg.named target $@ + local target=$REPLY + z.arg.named.shift target $@ local list=($REPLY) @@ -31,7 +33,9 @@ z.arr.includes() { # z.arr.excludes target=apple "banana" "apple" "cherry" #=> 1 (false) # z.arr.excludes target=grape "banana" "apple" "cherry" #=> 0 (true) z.arr.excludes() { - z.arg.named target $@ && local target=$REPLY + z.arg.named target $@ + local target=$REPLY + z.arg.named.shift target $@ local list=($REPLY) diff --git a/lib/arr/process.zsh b/lib/arr/process.zsh index 9a77083..8797b1b 100644 --- a/lib/arr/process.zsh +++ b/lib/arr/process.zsh @@ -8,8 +8,11 @@ # example: # z.arr.join "a" "b" "c" #=> REPLY="a b c" z.arr.join() { - z.arg.named delimiter $@ default=" " && local delimiter=$REPLY - z.arg.named.shift delimiter $@ && local arr=($REPLY) + z.arg.named delimiter $@ default=" " + local delimiter=$REPLY + + z.arg.named.shift delimiter $@ + local arr=($REPLY) local IFS=$delimiter z.return "${arr[*]}" @@ -26,7 +29,9 @@ z.arr.join() { # z.arr.split delimiter="," "a,b,c" #=> REPLY=("a" "b" "c") # z.arr.split "a b c" #=> REPLY=("a" "b" "c") z.arr.split() { - z.arg.named delimiter $@ default=" " && local delimiter=$REPLY + z.arg.named delimiter $@ default=" " + local delimiter=$REPLY + z.arg.named.shift delimiter $@ local str=$REPLY local arr @@ -49,11 +54,17 @@ z.arr.split() { z.arr.gsub() { local args=($@) - z.arg.named search $args && local search=${REPLY} - z.arg.named.shift search $args && args=($REPLY) + z.arg.named search $args + local search=${REPLY} - z.arg.named replace $args && local replace=${REPLY} - z.arg.named.shift replace $args && args=($REPLY) + z.arg.named.shift search $args + args=($REPLY) + + z.arg.named replace $args + local replace=${REPLY} + + z.arg.named.shift replace $args + args=($REPLY) local result=() @@ -77,7 +88,9 @@ z.arr.gsub() { z.arr.sort() { z.arg.named by $@ default=asc local sort_by=$REPLY - z.arg.named.shift by $@ && local arr=($REPLY) + + z.arg.named.shift by $@ + local arr=($REPLY) case $sort_by in asc) @@ -127,8 +140,11 @@ z.arr.unique() { # example: # z.arr.diff base="a b c" other="b c d" #=> REPLY=("a" "d") z.arr.diff() { - z.arg.named base $@ && local base=$REPLY - z.arg.named other $@ && local other=$REPLY + z.arg.named base $@ + local base=$REPLY + + z.arg.named other $@ + local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -173,8 +189,11 @@ z.arr.diff() { # example: # z.arr.intersect base="a b c" other="b c d" #=> REPLY=("b" "c") z.arr.intersect() { - z.arg.named base $@ && local base=$REPLY - z.arg.named other $@ && local other=$REPLY + z.arg.named base $@ + local base=$REPLY + + z.arg.named other $@ + local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -213,8 +232,11 @@ z.arr.intersect() { # example: # z.arr.union base="a b c" other="b c d e" #=> REPLY=("a" "b" "c" "d" "e") z.arr.union() { - z.arg.named base $@ && local base=$REPLY - z.arg.named other $@ && local other=$REPLY + z.arg.named base $@ + local base=$REPLY + + z.arg.named other $@ + local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -278,10 +300,17 @@ z.arr.reverse() { # z.arr.slice offset=2 to=5 "a" "b" "c" "d" "e" #=> REPLY=("c" "d" "e") z.arr.slice() { local args=($@) - z.arg.named offset $args && local offset=$REPLY - z.arg.named to $args && local to=$REPLY - z.arg.named.shift offset $args && args=($REPLY) - z.arg.named.shift to $args && args=($REPLY) + z.arg.named offset $args + local offset=$REPLY + + z.arg.named to $args + local to=$REPLY + + z.arg.named.shift offset $args + args=($REPLY) + + z.arg.named.shift to $args + args=($REPLY) local arr=($args) if z.is.not.null "$offset"; then diff --git a/lib/dir/process.zsh b/lib/dir/process.zsh index ee5d0ee..6a754c5 100644 --- a/lib/dir/process.zsh +++ b/lib/dir/process.zsh @@ -7,7 +7,8 @@ # example: # z.dir.make path="/path/to/dir" z.dir.make() { - z.arg.named path $@ && local dir=$REPLY + z.arg.named path $@ + local dir=$REPLY z.dir.not.exists $dir && mkdir -p $dir } @@ -21,7 +22,8 @@ z.dir.make() { # example: # z.dir.remove path="/path/to/dir" z.dir.remove() { - z.arg.named path $@ && local dir=$REPLY + z.arg.named path $@ + local dir=$REPLY z.dir.exists $dir && rm -rf $dir } diff --git a/lib/file/process.zsh b/lib/file/process.zsh index 0e52839..f444ca0 100644 --- a/lib/file/process.zsh +++ b/lib/file/process.zsh @@ -8,8 +8,11 @@ # example: # z.file.make path="/path/to/file.txt" with_dir=true z.file.make() { - z.arg.named path $@ && local file=$REPLY - z.arg.named with_dir $@ default=false && local with_dir=$REPLY + z.arg.named path $@ + local file=$REPLY + + z.arg.named with_dir $@ default=false + local with_dir=$REPLY if z.is.true $with_dir; then z.dir.make path=$(dirname $file) @@ -28,8 +31,11 @@ z.file.make() { # example: # z.file.write path="/path/to/file.txt" content="hello world" z.file.write() { - z.arg.named path $@ && local file=$REPLY - z.arg.named content $@ && local content=$REPLY + z.arg.named path $@ + local file=$REPLY + + z.arg.named content $@ + local content=$REPLY echo -n "$content" > $file } @@ -43,7 +49,8 @@ z.file.write() { # example: # z.file.read path="/path/to/file.txt" z.file.read() { - z.arg.named path $@ && local file=$REPLY + z.arg.named path $@ + local file=$REPLY if z.file.exists $file; then REPLY=$(cat $file) diff --git a/lib/file/read/process.zsh b/lib/file/read/process.zsh index 0001cc4..03dba58 100644 --- a/lib/file/read/process.zsh +++ b/lib/file/read/process.zsh @@ -7,7 +7,8 @@ # example: # z.file.read.lines path="/path/to/file.txt" z.file.read.lines() { - z.arg.named path $@ && local file=$REPLY + z.arg.named path $@ + local file=$REPLY if z.file.exists $file; then REPLY=(${(f)$(cat $file)}) @@ -26,8 +27,11 @@ z.file.read.lines() { # example: # z.file.read.pick path="/path/to/file.txt" word="search_word" z.file.read.pick() { - z.arg.named path $@ && local file=$REPLY - z.arg.named word $@ && local word=$REPLY + z.arg.named path $@ + local file=$REPLY + + z.arg.named word $@ + local word=$REPLY if z.file.exists $file; then REPLY=$(grep $word $file | head -n 1) diff --git a/lib/file/write/process.zsh b/lib/file/write/process.zsh index 84948a4..ec8966e 100644 --- a/lib/file/write/process.zsh +++ b/lib/file/write/process.zsh @@ -8,8 +8,11 @@ # example: # z.file.write.last path="/path/to/file.txt" content="hello world" z.file.write.last() { - z.arg.named path $@ && local file=$REPLY - z.arg.named content $@ && local content=$REPLY + z.arg.named path $@ + local file=$REPLY + + z.arg.named content $@ + local content=$REPLY echo "$content" >> $file } diff --git a/lib/hash/has/not/operator.zsh b/lib/hash/has/not/operator.zsh index 76c22b3..d6ff9af 100644 --- a/lib/hash/has/not/operator.zsh +++ b/lib/hash/has/not/operator.zsh @@ -11,8 +11,11 @@ # z.hash.has.not.key hash key=age # echo $? # outputs 0 z.hash.has.not.key() { - z.arg.named.shift key $@ && local hash_name=$REPLY - z.arg.named key $@ && local key=$REPLY + z.arg.named.shift key $@ + local hash_name=$REPLY + + z.arg.named key $@ + local key=$REPLY local ref="${hash_name}[$key]" @@ -32,8 +35,11 @@ z.hash.has.not.key() { # z.hash.has.not.value hash key=name # echo $? # outputs 0 z.hash.has.not.value() { - z.arg.named key $@ && local key=$REPLY - z.arg.named.shift key $@ && local hash_name=$REPLY + z.arg.named key $@ + local key=$REPLY + + z.arg.named.shift key $@ + local hash_name=$REPLY z.is.null ${${(P)hash_name}[$key]} } diff --git a/lib/hash/has/operator.zsh b/lib/hash/has/operator.zsh index d23e3bd..a4041c3 100644 --- a/lib/hash/has/operator.zsh +++ b/lib/hash/has/operator.zsh @@ -11,8 +11,11 @@ # z.hash.has.key hash key=name # echo $? # outputs 0 z.hash.has.key() { - z.arg.named.shift key $@ && local hash_name=$REPLY - z.arg.named key $@ && local key=$REPLY + z.arg.named.shift key $@ + local hash_name=$REPLY + + z.arg.named key $@ + local key=$REPLY local ref="${hash_name}[$key]" @@ -32,8 +35,11 @@ z.hash.has.key() { # z.hash.has.value hash key=name # echo $? # outputs 0 z.hash.has.value() { - z.arg.named key $@ && local key=$REPLY - z.arg.named.shift key $@ && local hash_name=$REPLY + z.arg.named key $@ + local key=$REPLY + + z.arg.named.shift key $@ + local hash_name=$REPLY z.is.not.null ${${(P)hash_name}[$key]} } diff --git a/lib/hash/process.zsh b/lib/hash/process.zsh index c0183c5..fbf421c 100644 --- a/lib/hash/process.zsh +++ b/lib/hash/process.zsh @@ -38,8 +38,11 @@ z.hash.to_arr() { # local -A merged=($REPLY) # echo ${merged[name]} # outputs "John" z.hash.merge() { - z.arg.named base $@ && local base=$REPLY - z.arg.named other $@ && local other=$REPLY + z.arg.named base $@ + local base=$REPLY + + z.arg.named other $@ + local other=$REPLY local -A merged_hash diff --git a/lib/io/error/process.zsh b/lib/io/error/process.zsh index ed40b43..f0d276f 100644 --- a/lib/io/error/process.zsh +++ b/lib/io/error/process.zsh @@ -9,8 +9,12 @@ # example: # z.io.error.oneline "error message" z.io.error.oneline() { - z.arg.named color $@ default=red && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=red + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -32,8 +36,12 @@ z.io.error.oneline() { # example: # z.io.error.line "error1" "error2" z.io.error.line() { - z.arg.named color $@ default=red && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=red + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/process.zsh b/lib/io/process.zsh index 89811ca..cb1ed00 100644 --- a/lib/io/process.zsh +++ b/lib/io/process.zsh @@ -9,8 +9,12 @@ # example: # z.io "hello" "world" #=> hello\nworld z.io() { - z.arg.named color $@ && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -48,8 +52,12 @@ z.io.empty() { # z.io.oneline "hello" # z.io.oneline "world" #=> helloworld z.io.oneline() { - z.arg.named color $@ && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -103,8 +111,12 @@ z.io.null() { # z.io.line "hello" "world" #=> hello\nworld # z.io.line #=> (empty line) z.io.line() { - z.arg.named color $@ && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -147,8 +159,12 @@ z.io.read() { # example: # z.io.success "Operation completed successfully." z.io.success() { - z.arg.named color $@ default=green && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=green + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY @@ -166,8 +182,12 @@ z.io.success() { # example: # z.io.warn "This is a warning message." z.io.warn() { - z.arg.named color $@ default=yellow && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=yellow + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY @@ -185,8 +205,12 @@ z.io.warn() { # example: # z.io.error "error message" z.io.error() { - z.arg.named color $@ default=red && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=red + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/success/process.zsh b/lib/io/success/process.zsh index 047e0ed..bbcb782 100644 --- a/lib/io/success/process.zsh +++ b/lib/io/success/process.zsh @@ -9,8 +9,12 @@ # example: # z.io.success.oneline "success message" z.io.success.oneline() { - z.arg.named color $@ default=green && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=green + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -32,8 +36,12 @@ z.io.success.oneline() { # example: # z.io.success.line "success1" "success2" z.io.success.line() { - z.arg.named color $@ default=green && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=green + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/warn/process.zsh b/lib/io/warn/process.zsh index 7fc86a5..ab8f9d6 100644 --- a/lib/io/warn/process.zsh +++ b/lib/io/warn/process.zsh @@ -9,8 +9,12 @@ # example: # z.io.warn.oneline "warn message" z.io.warn.oneline() { - z.arg.named color $@ default=yellow && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=yellow + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -32,8 +36,12 @@ z.io.warn.oneline() { # example: # z.io.warn.line "warn1" "warn2" z.io.warn.line() { - z.arg.named color $@ default=yellow && local color=$REPLY - z.arg.named indent $@ && local indent=$REPLY + z.arg.named color $@ default=yellow + local color=$REPLY + + z.arg.named indent $@ + local indent=$REPLY + z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/perm/process.zsh b/lib/perm/process.zsh index 7a1aa49..4db16f5 100644 --- a/lib/perm/process.zsh +++ b/lib/perm/process.zsh @@ -54,8 +54,11 @@ z.perm.dir() { # example: # z.perm._apply recursive=false path=/path/to/file mode=600 z.perm._apply() { - z.arg.named recursive $@ default=false && local recursive=$REPLY - z.arg.named path $@ && local target_path=$REPLY + z.arg.named recursive $@ default=false + local recursive=$REPLY + + z.arg.named path $@ + local target_path=$REPLY if z.is.null "$target_path"; then z.io.error "path is required" @@ -90,8 +93,11 @@ z.perm._apply() { # example: # z.perm._owner_spec owner=user group=group #=> "user:group" z.perm._owner_spec() { - z.arg.named owner $@ default="" && local owner=$REPLY - z.arg.named group $@ default="" && local group=$REPLY + z.arg.named owner $@ default="" + local owner=$REPLY + + z.arg.named group $@ default="" + local group=$REPLY if z.is.null "$owner" && z.is.null "$group"; then z.return @@ -122,7 +128,8 @@ z.perm._owner_spec() { # mode_group=read,none,none \ # mode_other=none,none,none z.perm._mode() { - z.arg.named mode $@ default="" && local mode=$REPLY + z.arg.named mode $@ default="" + local mode=$REPLY if z.is.not.null "$mode"; then z.return "$mode" return 0 @@ -140,9 +147,14 @@ z.perm._mode() { return 1 fi - z.arg.named mode_owner $@ default="none,none,none" && local mode_owner=$REPLY - z.arg.named mode_group $@ default="none,none,none" && local mode_group=$REPLY - z.arg.named mode_other $@ default="none,none,none" && local mode_other=$REPLY + z.arg.named mode_owner $@ default="none,none,none" + local mode_owner=$REPLY + + z.arg.named mode_group $@ default="none,none,none" + local mode_group=$REPLY + + z.arg.named mode_other $@ default="none,none,none" + local mode_other=$REPLY z.perm._mode_digit "$mode_owner" || return 1 local owner_digit=$REPLY diff --git a/lib/str/color/process.zsh b/lib/str/color/process.zsh index e81ec6e..27e1f16 100644 --- a/lib/str/color/process.zsh +++ b/lib/str/color/process.zsh @@ -28,8 +28,11 @@ z.str.color.strip() { # example: # z.str.color.decorate color=red message="Hello" #=> $'\033[31mHello\033[0m' z.str.color.decorate() { - z.arg.named color $@ && local color=$REPLY - z.arg.named message $@ && local message=$REPLY + z.arg.named color $@ + local color=$REPLY + + z.arg.named message $@ + local message=$REPLY z.str.color.strip $message local plain=$REPLY diff --git a/lib/str/match/process.zsh b/lib/str/match/process.zsh index 5b75684..ff94a53 100644 --- a/lib/str/match/process.zsh +++ b/lib/str/match/process.zsh @@ -31,7 +31,9 @@ z.str.match.rest() { # z.str.match.nth "one two three" "^o" index=1 #=> "one" # z.str.match.nth "apple banana cherry" "^a" index=2 #=> "banana" z.str.match.nth() { - z.arg.named index $@ && local index=$REPLY + z.arg.named index $@ + local index=$REPLY + z.arg.named.shift index $@ local str=$REPLY[1] local regex=$REPLY[2] diff --git a/lib/str/process.zsh b/lib/str/process.zsh index 8725288..4024869 100644 --- a/lib/str/process.zsh +++ b/lib/str/process.zsh @@ -33,8 +33,11 @@ z.str.color() { # example: # z.str.indent level=2 message="Hello" #=> " Hello" z.str.indent() { - z.arg.named level $@ && local level=$REPLY - z.arg.named message $@ && local message=$REPLY + z.arg.named level $@ + local level=$REPLY + + z.arg.named message $@ + local message=$REPLY if z.int.is.not.match $level || z.int.is.lt $level 0; then level=0 @@ -58,8 +61,11 @@ z.str.indent() { # example: # z.str.split str="apple|banana|cherry" delimiter=| #=> ("apple" "banana" "cherry") z.str.split() { - z.arg.named str $@ && local str=$REPLY - z.arg.named delimiter $@ default="|" && local delimiter=$REPLY + z.arg.named str $@ + local str=$REPLY + + z.arg.named delimiter $@ default="|" + local delimiter=$REPLY local IFS=$delimiter REPLY=(${=str}) @@ -77,7 +83,9 @@ z.str.split() { # z.str.partition "p foo bar" "[[:space:]]+" #=> ("p" "foo bar") # z.str.partition "a[0-9]b" "[0-9]" literal=true #=> ("a" "b") z.str.partition() { - z.arg.named literal $@ default=false && local literal=$REPLY + z.arg.named literal $@ default=false + local literal=$REPLY + z.arg.named.shift literal $@ local str=$REPLY[1] local delimiter=$REPLY[2] @@ -153,10 +161,17 @@ z.str.match() { # z.str.gsub str="Hello123World" search="[0-9]" replace="-" #=> "Hello---World" # z.str.gsub str="a[0-9]b" search="[0-9]" replace="X" literal=true #=> "aXb" z.str.gsub() { - z.arg.named str $@ && local str=$REPLY - z.arg.named search $@ && local search=$REPLY - z.arg.named replace $@ && local replace=$REPLY - z.arg.named literal $@ default=false && local literal=$REPLY + z.arg.named str $@ + local str=$REPLY + + z.arg.named search $@ + local search=$REPLY + + z.arg.named replace $@ + local replace=$REPLY + + z.arg.named literal $@ default=false + local literal=$REPLY if z.is.null $str || z.is.null $search; then z.return $str @@ -363,8 +378,12 @@ z.str.kebabize() { # z.str.delimitize delimiter="_" "helloWorld" #=> "hello_world" # z.str.delimitize delimiter="-" replace_chars="[ _]" "hello world_test" #=> "hello-world-test" z.str.delimitize() { - z.arg.named delimiter $@ && local delimiter=$REPLY - z.arg.named replace_chars $@ default="[ _-]" && local replace_chars=$REPLY + z.arg.named delimiter $@ + local delimiter=$REPLY + + z.arg.named replace_chars $@ default="[ _-]" + local replace_chars=$REPLY + z.arg.named.shift delimiter $@ z.arg.named.shift replace_chars $REPLY @@ -428,8 +447,12 @@ z.str.visible() { # example: # z.str.ljust width=10 fill="." "Hi" #=> "Hi........" z.str.ljust() { - z.arg.named width $@ && local width=$REPLY - z.arg.named fill $@ default=" " && local fill=$REPLY + z.arg.named width $@ + local width=$REPLY + + z.arg.named fill $@ default=" " + local fill=$REPLY + z.arg.named.shift width $@ z.arg.named.shift fill $REPLY local str=$REPLY @@ -460,8 +483,12 @@ z.str.ljust() { # example: # z.str.rjust width=10 fill="." "Hi" #=> "........Hi" z.str.rjust() { - z.arg.named width $@ && local width=$REPLY - z.arg.named fill $@ default=" " && local fill=$REPLY + z.arg.named width $@ + local width=$REPLY + + z.arg.named fill $@ default=" " + local fill=$REPLY + z.arg.named.shift width $@ z.arg.named.shift fill $REPLY local str=$REPLY diff --git a/lib/t/dsl.zsh b/lib/t/dsl.zsh index 43a9cb7..8c909fd 100644 --- a/lib/t/dsl.zsh +++ b/lib/t/dsl.zsh @@ -19,7 +19,8 @@ z.is.eq $z_mode "test" && { # example: # z.t.mark_not_found_error message="command not found: ls" z.t._mark_not_found_error() { - z.arg.named message $@ && local message=$REPLY + z.arg.named message $@ + local message=$REPLY local error_flag_file="/tmp/z_t_error_$$" z.file.make path=$error_flag_file with_dir=true diff --git a/lib/t/expect.zsh b/lib/t/expect.zsh index 0c18bda..7b77287 100644 --- a/lib/t/expect.zsh +++ b/lib/t/expect.zsh @@ -11,7 +11,8 @@ z.t.expect() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then @@ -43,7 +44,8 @@ z.t.expect() { z.t.expect.not() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then diff --git a/lib/t/expect/include.zsh b/lib/t/expect/include.zsh index 71addab..260001f 100644 --- a/lib/t/expect/include.zsh +++ b/lib/t/expect/include.zsh @@ -11,7 +11,8 @@ z.t.expect.includes() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then @@ -39,7 +40,8 @@ z.t.expect.includes() { z.t.expect.excludes() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then diff --git a/lib/t/expect/reply.zsh b/lib/t/expect/reply.zsh index 43b2729..2cbea08 100644 --- a/lib/t/expect/reply.zsh +++ b/lib/t/expect/reply.zsh @@ -11,7 +11,9 @@ z.t.expect.reply() { local expect=$1 local reply=$REPLY - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t.expect "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/excludes.zsh b/lib/t/expect/reply/excludes.zsh index 76a3082..f57dacf 100644 --- a/lib/t/expect/reply/excludes.zsh +++ b/lib/t/expect/reply/excludes.zsh @@ -11,7 +11,9 @@ z.t.expect.reply.excludes() { local expect=$1 local reply=$REPLY - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t.expect.excludes "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/includes.zsh b/lib/t/expect/reply/includes.zsh index c1fa877..e54f74c 100644 --- a/lib/t/expect/reply/includes.zsh +++ b/lib/t/expect/reply/includes.zsh @@ -11,7 +11,9 @@ z.t.expect.reply.includes() { local expect=$1 local reply=$REPLY - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t.expect.includes "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/is/not/null.zsh b/lib/t/expect/reply/is/not/null.zsh index 9a93dc5..3172dc8 100644 --- a/lib/t/expect/reply/is/not/null.zsh +++ b/lib/t/expect/reply/is/not/null.zsh @@ -10,7 +10,9 @@ z.t.expect.reply.is.not.null() { local expect="" local reply=$REPLY - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t.expect.not "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/is/null.zsh b/lib/t/expect/reply/is/null.zsh index 66f0160..cd5a2a5 100644 --- a/lib/t/expect/reply/is/null.zsh +++ b/lib/t/expect/reply/is/null.zsh @@ -10,7 +10,9 @@ z.t.expect.reply.is.null() { local expect="" local reply=$REPLY - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.t.expect "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/status.zsh b/lib/t/expect/status.zsh index bf7e88b..97c0f0d 100644 --- a/lib/t/expect/status.zsh +++ b/lib/t/expect/status.zsh @@ -12,7 +12,8 @@ z.t.expect.status() { z.status local actual=$REPLY local expect=$1 - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY z.is.eq $expect "true" && expect=0 z.is.eq $expect "false" && expect=1 diff --git a/lib/t/log/dot.zsh b/lib/t/log/dot.zsh index ffe5834..b0502c1 100644 --- a/lib/t/log/dot.zsh +++ b/lib/t/log/dot.zsh @@ -40,7 +40,8 @@ z.t._log.dot.pending() { # example: # z.t._log.dot.output char=F z.t._log.dot.output() { - z.arg.named char $@ && local char=$REPLY + z.arg.named char $@ + local char=$REPLY local count_file="${Z_TEST_COMPACT_DIR}/.dot_count" local count=0 diff --git a/lib/t/log/failure.zsh b/lib/t/log/failure.zsh index 48ce01c..ab76899 100644 --- a/lib/t/log/failure.zsh +++ b/lib/t/log/failure.zsh @@ -38,7 +38,8 @@ z.t._log.failure.remember() { # example: # z.t._log.failure.add "red" z.t._log.failure.add() { - z.arg.named color $@ && local color=$REPLY + z.arg.named color $@ + local color=$REPLY z.t._state.current_idx "describe" local d_idx=$REPLY @@ -78,7 +79,8 @@ z.t._log.failure.add() { # example: # z.t._log.failure.handle "error message" z.t._log.failure.handle() { - z.arg.named message $@ && local error_message=$REPLY + z.arg.named message $@ + local error_message=$REPLY z.str.indent level=4 message=$error_message z.str.color.red $REPLY diff --git a/lib/t/mock.zsh b/lib/t/mock.zsh index 5db53cf..d99253d 100644 --- a/lib/t/mock.zsh +++ b/lib/t/mock.zsh @@ -8,8 +8,11 @@ # example: # z.t.mock name=my_func behavior=call_original z.t.mock() { - z.arg.named name $@ && local func_name=$REPLY - z.arg.named behavior $@ && local behavior=$REPLY + z.arg.named name $@ + local func_name=$REPLY + + z.arg.named behavior $@ + local behavior=$REPLY local original_func_name="original_$func_name" local nonfunctional="_nonfunctional" diff --git a/lib/t/mock/call_original.zsh b/lib/t/mock/call_original.zsh index 0736b7d..89766dc 100644 --- a/lib/t/mock/call_original.zsh +++ b/lib/t/mock/call_original.zsh @@ -7,7 +7,8 @@ # example: # z.t.mock.call_original name=my_func z.t.mock.call_original() { - z.arg.named name $@ && local name=$REPLY + z.arg.named name $@ + local name=$REPLY z.t.mock name=$name behavior=call_original } diff --git a/lib/t/mock/result.zsh b/lib/t/mock/result.zsh index ca77589..aabff32 100644 --- a/lib/t/mock/result.zsh +++ b/lib/t/mock/result.zsh @@ -8,7 +8,8 @@ # example: # z.t.mock.result name=my_func z.t.mock.result() { - z.arg.named name $@ && local func_name=$REPLY + z.arg.named name $@ + local func_name=$REPLY if z.is.null $func_name; then z.t._state.mock_last_func diff --git a/lib/t/mock/unmock.zsh b/lib/t/mock/unmock.zsh index bc5d8c1..710cb5c 100644 --- a/lib/t/mock/unmock.zsh +++ b/lib/t/mock/unmock.zsh @@ -8,7 +8,8 @@ # example: # z.t.mock.unmock name=my_func z.t.mock.unmock() { - z.arg.named name $@ && local func_name=$REPLY + z.arg.named name $@ + local func_name=$REPLY local nonfunctional="_nonfunctional" if z.is.null $func_name; then @@ -47,7 +48,8 @@ z.t.mock.unmock() { # example: # z.t.mock.unmock.all z.t.mock.unmock.all() { - z.arg.named skip_unmock $@ && local skip_unmock=$REPLY + z.arg.named skip_unmock $@ + local skip_unmock=$REPLY if z.t.mock.unmock._is_not_skippable $skip_unmock; then z.t._state.mock_originals diff --git a/lib/t/process.zsh b/lib/t/process.zsh index 11ad0a2..094fafd 100644 --- a/lib/t/process.zsh +++ b/lib/t/process.zsh @@ -239,7 +239,8 @@ z.t._setup_temp_dirs() { # example: # z.t._show_compact_results $compact_dir $files z.t._show_compact_results() { - local compact_dir=$1 && shift + local compact_dir=$1 + shift local files=($@) z.io.empty @@ -269,7 +270,8 @@ z.t._show_compact_results() { # example: # z.t._show_totals $count_dir $files z.t._show_totals() { - local count_dir=$1 && shift + local count_dir=$1 + shift local files=($@) local total_tests=0 diff --git a/lib/t/state/current_idx.zsh b/lib/t/state/current_idx.zsh index 2494287..7ec53e8 100644 --- a/lib/t/state/current_idx.zsh +++ b/lib/t/state/current_idx.zsh @@ -24,8 +24,11 @@ z.t._state.current_idx() { # z.t._state.current_idx.set "describe" value=1 z.t._state.current_idx.set() { local REPLY - z.arg.named value $@ && local value=$REPLY - z.arg.named.shift value $@ && local context=$REPLY + z.arg.named value $@ + local value=$REPLY + + z.arg.named.shift value $@ + local context=$REPLY z_t_current_idx[$context]=$value } diff --git a/lib/t/state/logs.zsh b/lib/t/state/logs.zsh index 5ee482b..7c9dc55 100644 --- a/lib/t/state/logs.zsh +++ b/lib/t/state/logs.zsh @@ -48,8 +48,11 @@ z.t._state.logs.context() { # z.t._state.logs.context.set index=0 "Updated log entry" z.t._state.logs.context.set() { local REPLY - z.arg.named index $@ && local context=$REPLY - z.arg.named.shift index $@ && local value=$REPLY + z.arg.named index $@ + local context=$REPLY + + z.arg.named.shift index $@ + local value=$REPLY local target_log=${z_t_logs[$context]} diff --git a/lib/t/state/mock_calls.zsh b/lib/t/state/mock_calls.zsh index 386d457..2b38908 100644 --- a/lib/t/state/mock_calls.zsh +++ b/lib/t/state/mock_calls.zsh @@ -35,8 +35,11 @@ z.t._state.mock_calls.context() { # z.t._state.mock_calls.add name=my_func "arg1" "arg2" z.t._state.mock_calls.add() { local REPLY - z.arg.named name $@ && local func_name=$REPLY - z.arg.named.shift name $@ && local args=$REPLY + z.arg.named name $@ + local func_name=$REPLY + + z.arg.named.shift name $@ + local args=$REPLY if z.is.not.null ${z_t_mock_calls[$func_name]}; then z_t_mock_calls[$func_name]="${z_t_mock_calls[$func_name]}${z_t_mock_call_sep}${args}" @@ -55,8 +58,11 @@ z.t._state.mock_calls.add() { # example: # z.t._state.mock_calls.set name=my_func "value=new value" z.t._state.mock_calls.set() { - z.arg.named name $@ && local func_name=$REPLY - z.arg.named value $@ && local value=$REPLY + z.arg.named name $@ + local func_name=$REPLY + + z.arg.named value $@ + local value=$REPLY z_t_mock_calls[$func_name]=$value } diff --git a/lib/t/state/mock_originals.zsh b/lib/t/state/mock_originals.zsh index 47e8ea6..d0e0907 100644 --- a/lib/t/state/mock_originals.zsh +++ b/lib/t/state/mock_originals.zsh @@ -35,8 +35,11 @@ z.t._state.mock_originals.context() { # z.t._state.mock_originals.add name=my_func "original function definition" z.t._state.mock_originals.add() { local REPLY - z.arg.named name $@ && local func_name=$REPLY - z.arg.named.shift name $@ && local original_func=$REPLY + z.arg.named name $@ + local func_name=$REPLY + + z.arg.named.shift name $@ + local original_func=$REPLY z_t_mock_originals[$func_name]=$original_func } diff --git a/lib/update/archive/process.zsh b/lib/update/archive/process.zsh index 0e469c1..698b254 100644 --- a/lib/update/archive/process.zsh +++ b/lib/update/archive/process.zsh @@ -8,7 +8,7 @@ # example: # z.update.archive._download dir=/tmp/update branch=main z.update.archive._download() { - z.arg.named dir "$@" || { z.return; return 1; } + z.arg.named dir "$@" local dir=$REPLY z.dir.exists "$dir" || { z.return; return 1; } @@ -41,11 +41,11 @@ z.update.archive._download() { # example: # z.update.archive._extract file=/tmp/source.tar.gz dir=/tmp/update/source z.update.archive._extract() { - z.arg.named file "$@" || { z.return; return 1; } + z.arg.named file "$@" local file=$REPLY - z.arg.named dir "$@" || { z.return; return 1; } + z.arg.named dir "$@" local dir=$REPLY z.is.null "$dir" && { z.return; return 1; } diff --git a/lib/update/core/process.zsh b/lib/update/core/process.zsh index f549555..2b3ecc6 100644 --- a/lib/update/core/process.zsh +++ b/lib/update/core/process.zsh @@ -8,10 +8,10 @@ # example: # z.update.core._copy source=/tmp/source dir=/tmp/update/next z.update.core._copy() { - z.arg.named source "$@" || return 1 + z.arg.named source "$@" local source_dir=$REPLY - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY z.is.null "$dir" && return 1 z.dir.exists "$dir" && return 1 diff --git a/lib/update/installation/is/operator.zsh b/lib/update/installation/is/operator.zsh index 9e20f99..f7abcb2 100644 --- a/lib/update/installation/is/operator.zsh +++ b/lib/update/installation/is/operator.zsh @@ -7,7 +7,7 @@ # example: # z.update.installation.is._valid dir=~/.z z.update.installation.is._valid() { - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY z.is.null "$dir" && return 1 diff --git a/lib/update/installation/process.zsh b/lib/update/installation/process.zsh index 36dcec4..de1bd41 100644 --- a/lib/update/installation/process.zsh +++ b/lib/update/installation/process.zsh @@ -9,13 +9,13 @@ # example: # z.update.installation._replace dir=~/.z prepared=/tmp/next backup=/tmp/previous z.update.installation._replace() { - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY - z.arg.named prepared "$@" || return 1 + z.arg.named prepared "$@" local prepared=$REPLY - z.arg.named backup "$@" || return 1 + z.arg.named backup "$@" local backup=$REPLY z.is.null "$backup" && return 1 @@ -45,7 +45,7 @@ z.update.installation._replace() { # example: # z.update.installation._reload dir=~/.z previous=$PWD z.update.installation._reload() { - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY z.file.exists "$dir/main.zsh" || return 1 diff --git a/lib/update/mod/analysis.zsh b/lib/update/mod/analysis.zsh index bea922c..e49eeff 100644 --- a/lib/update/mod/analysis.zsh +++ b/lib/update/mod/analysis.zsh @@ -8,7 +8,7 @@ # example: # z.update.mod._resolve source=/tmp/source completion z.update.mod._resolve() { - z.arg.named source "$@" || { z.return; return 1; } + z.arg.named source "$@" local source_dir=$REPLY z.dir.exists "$source_dir" || { z.return; return 1; } diff --git a/lib/update/mod/process.zsh b/lib/update/mod/process.zsh index fd80967..97d2f9e 100644 --- a/lib/update/mod/process.zsh +++ b/lib/update/mod/process.zsh @@ -10,13 +10,13 @@ # example: # z.update.mod._copy source=/tmp/source current=~/.z dir=/tmp/update/next job z.update.mod._copy() { - z.arg.named source "$@" || return 1 + z.arg.named source "$@" local source_dir=$REPLY - z.arg.named current "$@" || return 1 + z.arg.named current "$@" local current_dir=$REPLY - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY z.dir.exists "$source_dir" || return 1 diff --git a/lib/update/process.zsh b/lib/update/process.zsh index fcff6fb..ee40e2f 100644 --- a/lib/update/process.zsh +++ b/lib/update/process.zsh @@ -69,7 +69,7 @@ z.update() { # example: # z.update._confirm dir=~/.z z.update._confirm() { - z.arg.named dir "$@" || return 1 + z.arg.named dir "$@" local dir=$REPLY z.is.null "$dir" && return 1 diff --git a/test/lib/arg/process_test.zsh b/test/lib/arg/process_test.zsh index f67bdcb..ddca315 100644 --- a/test/lib/arg/process_test.zsh +++ b/test/lib/arg/process_test.zsh @@ -75,6 +75,17 @@ z.t.describe "z.arg.named"; { } } + z.t.context "指定した名前の引数がない場合"; { + z.t.it "成功して空の値を返す"; { + z.arg.named name other=fuga + local result_code=$? + local result_reply=$REPLY + + z.t.expect "$result_code" 0 + z.t.expect "$result_reply" "" + } + } + z.t.context "defaultが指定されていて、値がない場合"; { z.t.it "デフォルト値を返す"; { z.arg.named name name="" other=fuga default=default_value From 446de0ffe1365147e57cf4bb1153ed43c89fb3c5 Mon Sep 17 00:00:00 2001 From: milkeclair Date: Sun, 15 Nov 2026 12:57:43 +0900 Subject: [PATCH 2/5] refactor: consolidate core failure checks at operation boundaries --- AGENTS.md | 6 ++++++ lib/common/is/operator.zsh | 2 -- lib/int/is/operator.zsh | 6 ------ lib/update/archive/process.zsh | 3 --- lib/update/core/process.zsh | 9 +-------- lib/update/mod/process.zsh | 4 ---- test/lib/update/core/process_test.zsh | 14 ++++---------- test/lib/update/mod/process_test.zsh | 7 ++----- 8 files changed, 13 insertions(+), 38 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3029fbb..a6a7c11 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -53,3 +53,9 @@ zの関数は、関数名の階層とディレクトリ構成を対応させて - `lib/a/process.zsh` のテストは `test/lib/a/process_test.zsh` - `lib/a/b/process.zsh` のテストは `test/lib/a/b/process_test.zsh` - `mod/a/b/operator.zsh` のテストは `test/mod/a/b/operator_test.zsh` + +## 失敗処理 + +終了ステータスは関数の契約に合わせて扱ってください。`z.arg.named`のように、正常値・未指定値ともに終了ステータス0で`REPLY`へ返す処理は、そのまま呼び出して直後に変数へ取り込みます。値の未指定や不一致は、返された値や判定関数で扱います。呼び出し元で必要な条件が確定しているパス生成なども、通常の計算として扱ってください。 + +`|| return 1`は、コピー失敗後の切替防止や依存関係の循環検出など、失敗時に後続の処理を止める必要がある箇所に置いてください。通常の取得・代入・計算はそのまま実行し、入力・結果を使う操作や判定が担う検証へまとめてください。削除・置換では対象を操作の前に検証し、失敗時に復旧する処理を維持してください。 diff --git a/lib/common/is/operator.zsh b/lib/common/is/operator.zsh index 7584e46..5e061b7 100644 --- a/lib/common/is/operator.zsh +++ b/lib/common/is/operator.zsh @@ -26,7 +26,6 @@ z.is.truthy() { local value=$1 z.guard; { - z.arg.is.empty $@ && return 1 z.is.false $value && return 1 } @@ -68,7 +67,6 @@ z.is.falsy() { local value=$1 z.guard; { - z.arg.is.empty $@ && return 0 z.is.true $value && return 1 } diff --git a/lib/int/is/operator.zsh b/lib/int/is/operator.zsh index 3b4dd8c..dd05430 100644 --- a/lib/int/is/operator.zsh +++ b/lib/int/is/operator.zsh @@ -42,8 +42,6 @@ z.int.is.eq() { z.int.is.zero() { local value=$1 - z.int.is.match $value || return 1 - z.is.eq $value 0 } @@ -58,8 +56,6 @@ z.int.is.zero() { z.int.is.positive() { local value=$1 - z.int.is.match $value || return 1 - z.int.is.gt $value 0 } @@ -74,8 +70,6 @@ z.int.is.positive() { z.int.is.negative() { local value=$1 - z.int.is.match $value || return 1 - z.int.is.lt $value 0 } diff --git a/lib/update/archive/process.zsh b/lib/update/archive/process.zsh index 698b254..6873d1d 100644 --- a/lib/update/archive/process.zsh +++ b/lib/update/archive/process.zsh @@ -14,7 +14,6 @@ z.update.archive._download() { z.arg.named branch "$@" default=main local branch=$REPLY - z.is.null "$branch" && { z.return; return 1; } local file="$dir/source.tar.gz" z.file.exists "$file" && { z.return; return 1; } @@ -26,8 +25,6 @@ z.update.archive._download() { return 1 fi - z.file.exists "$file" || { z.return; return 1; } - z.return "$file" } diff --git a/lib/update/core/process.zsh b/lib/update/core/process.zsh index 2b3ecc6..6c6a4ab 100644 --- a/lib/update/core/process.zsh +++ b/lib/update/core/process.zsh @@ -10,6 +10,7 @@ z.update.core._copy() { z.arg.named source "$@" local source_dir=$REPLY + z.dir.exists "$source_dir" || return 1 z.arg.named dir "$@" local dir=$REPLY @@ -18,14 +19,6 @@ z.update.core._copy() { local core_files=(main.zsh install.zsh uninstall.zsh version.zsh help.zsh README.md) - for directory in lib test; do - z.dir.exists "$source_dir/$directory" || return 1 - done - - for core_file in "${core_files[@]}"; do - z.file.exists "$source_dir/$core_file" || return 1 - done - z.dir.make path="$dir" || return 1 for entry in lib test "${core_files[@]}"; do diff --git a/lib/update/mod/process.zsh b/lib/update/mod/process.zsh index 97d2f9e..d7695c4 100644 --- a/lib/update/mod/process.zsh +++ b/lib/update/mod/process.zsh @@ -29,10 +29,6 @@ z.update.mod._copy() { z.arg.named.shift dir "${(@)REPLY}" local selected=(${(@)REPLY}) - for mod_name in "${selected[@]}"; do - z.dir.exists "$source_dir/mod/$mod_name" || return 1 - done - if z.dir.exists "$current_dir/mod"; then z.dir.make path="$dir/mod" || return 1 diff --git a/test/lib/update/core/process_test.zsh b/test/lib/update/core/process_test.zsh index 108f006..94e0f6f 100644 --- a/test/lib/update/core/process_test.zsh +++ b/test/lib/update/core/process_test.zsh @@ -60,37 +60,31 @@ z.t.describe "z.update.core._copy"; { } z.t.context "配布元のtest directoryがない場合"; { - z.t.it "コピーを開始しない"; { + z.t.it "コピーの失敗を返す"; { local dir=/tmp/z_t/update_core/missing_directory z.dir.make path="$dir/source/lib" - z.update.core._copy source="$dir/source" dir="$dir/prepared" + z.update.core._copy source="$dir/source" dir="$dir/prepared" 2>/dev/null local copy_status=$? z.t.expect "$copy_status" 1 - z.dir.not.exists "$dir/prepared" - z.t.expect.status.is.true - z.dir.remove path=/tmp/z_t/update_core } } z.t.context "必須fileがない場合"; { - z.t.it "コピーを開始しない"; { + z.t.it "コピーの失敗を返す"; { local dir=/tmp/z_t/update_core/missing_file z.dir.make path="$dir/source/lib" z.dir.make path="$dir/source/test" z.file.write path="$dir/source/main.zsh" content=main - z.update.core._copy source="$dir/source" dir="$dir/prepared" + z.update.core._copy source="$dir/source" dir="$dir/prepared" 2>/dev/null local copy_status=$? z.t.expect "$copy_status" 1 - z.dir.not.exists "$dir/prepared" - z.t.expect.status.is.true - z.dir.remove path=/tmp/z_t/update_core } } diff --git a/test/lib/update/mod/process_test.zsh b/test/lib/update/mod/process_test.zsh index abccbbf..98a6a1c 100644 --- a/test/lib/update/mod/process_test.zsh +++ b/test/lib/update/mod/process_test.zsh @@ -112,14 +112,14 @@ z.t.describe "z.update.mod._copy"; { } z.t.context "配布元に選択modがない場合"; { - z.t.it "既存と準備先を変更しない"; { + z.t.it "コピーの失敗を返して現行modを保持する"; { local dir=/tmp/z_t/update_mod_copy/missing z.dir.make path="$dir/current/mod/app" z.dir.make path="$dir/source" z.dir.make path="$dir/prepared" z.file.write path="$dir/current/mod/app/value" content=original - z.update.mod._copy source="$dir/source" current="$dir/current" dir="$dir/prepared" missing + z.update.mod._copy source="$dir/source" current="$dir/current" dir="$dir/prepared" missing 2>/dev/null local copy_status=$? z.t.expect "$copy_status" 1 @@ -127,9 +127,6 @@ z.t.describe "z.update.mod._copy"; { z.file.read path="$dir/current/mod/app/value" z.t.expect.reply original - z.dir.not.exists "$dir/prepared/mod" - z.t.expect.status.is.true - z.dir.remove path=/tmp/z_t/update_mod_copy } } From eccd51f592637b9219b65af0484d46d8c2ab648e Mon Sep 17 00:00:00 2001 From: milkeclair Date: Sun, 15 Nov 2026 13:00:33 +0900 Subject: [PATCH 3/5] docs: align argument example with direct value capture --- README.md | 4 +++- test/lib/readme/sample_test.zsh | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2500c1e..899e82f 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ Script to check if the number of arguments is more than 2. ```zsh my.argument_check() { - z.arg.named max $@ default=2 && local max=$REPLY + z.arg.named max $@ default=2 + local max=$REPLY + z.arg.named.shift max $@ z.arr.count $REPLY diff --git a/test/lib/readme/sample_test.zsh b/test/lib/readme/sample_test.zsh index bba1cb9..0fcb64a 100755 --- a/test/lib/readme/sample_test.zsh +++ b/test/lib/readme/sample_test.zsh @@ -1,7 +1,9 @@ source ${z_main} my.argument_check() { - z.arg.named max $@ default=2 && local max=$REPLY + z.arg.named max $@ default=2 + local max=$REPLY + z.arg.named.shift max $@ z.arr.count $REPLY From 99a7fbbcd71f0fb6699a85a46e388bf895021039 Mon Sep 17 00:00:00 2001 From: milkeclair Date: Sun, 15 Nov 2026 13:11:18 +0900 Subject: [PATCH 4/5] fix: preserve established value capture and declaration style --- AGENTS.md | 4 +- README.md | 4 +- lib/arg/analysis.zsh | 4 +- lib/arg/is/operator.zsh | 7 +--- lib/arg/process.zsh | 19 +++------ lib/arr/operator.zsh | 8 +--- lib/arr/process.zsh | 65 +++++++++--------------------- lib/dir/process.zsh | 6 +-- lib/file/process.zsh | 17 +++----- lib/file/read/process.zsh | 10 ++--- lib/file/write/process.zsh | 7 +--- lib/hash/has/not/operator.zsh | 14 ++----- lib/hash/has/operator.zsh | 14 ++----- lib/hash/process.zsh | 7 +--- lib/io/error/process.zsh | 16 ++------ lib/io/process.zsh | 48 ++++++---------------- lib/io/success/process.zsh | 16 ++------ lib/io/warn/process.zsh | 16 ++------ lib/perm/process.zsh | 28 ++++--------- lib/str/color/process.zsh | 7 +--- lib/str/match/process.zsh | 4 +- lib/str/process.zsh | 57 +++++++------------------- lib/t/dsl.zsh | 3 +- lib/t/expect.zsh | 6 +-- lib/t/expect/include.zsh | 6 +-- lib/t/expect/reply.zsh | 4 +- lib/t/expect/reply/excludes.zsh | 4 +- lib/t/expect/reply/includes.zsh | 4 +- lib/t/expect/reply/is/not/null.zsh | 4 +- lib/t/expect/reply/is/null.zsh | 4 +- lib/t/expect/status.zsh | 3 +- lib/t/log/dot.zsh | 3 +- lib/t/log/failure.zsh | 6 +-- lib/t/mock.zsh | 7 +--- lib/t/mock/call_original.zsh | 3 +- lib/t/mock/result.zsh | 3 +- lib/t/mock/unmock.zsh | 6 +-- lib/t/process.zsh | 6 +-- lib/t/state/current_idx.zsh | 7 +--- lib/t/state/logs.zsh | 7 +--- lib/t/state/mock_calls.zsh | 14 ++----- lib/t/state/mock_originals.zsh | 7 +--- test/lib/readme/sample_test.zsh | 4 +- 43 files changed, 136 insertions(+), 353 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index a6a7c11..7850599 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,6 +56,6 @@ zの関数は、関数名の階層とディレクトリ構成を対応させて ## 失敗処理 -終了ステータスは関数の契約に合わせて扱ってください。`z.arg.named`のように、正常値・未指定値ともに終了ステータス0で`REPLY`へ返す処理は、そのまま呼び出して直後に変数へ取り込みます。値の未指定や不一致は、返された値や判定関数で扱います。呼び出し元で必要な条件が確定しているパス生成なども、通常の計算として扱ってください。 +`|| return 1`は、コピー失敗後の切替防止や依存関係の循環検出など、失敗時に後続の処理を止める必要がある箇所に置いてください。削除・置換では操作対象の検証と復旧処理を維持し、通常の取得・計算では同じ条件の重複検証を整理してください。 -`|| return 1`は、コピー失敗後の切替防止や依存関係の循環検出など、失敗時に後続の処理を止める必要がある箇所に置いてください。通常の取得・代入・計算はそのまま実行し、入力・結果を使う操作や判定が担う検証へまとめてください。削除・置換では対象を操作の前に検証し、失敗時に復旧する処理を維持してください。 +引数取得と代入は、`z.arg.named ... && local ...`などの既存の書式に合わせてください。常に成功する値取得に`|| return 1`を追加する必要はありません。 diff --git a/README.md b/README.md index 899e82f..2500c1e 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,7 @@ Script to check if the number of arguments is more than 2. ```zsh my.argument_check() { - z.arg.named max $@ default=2 - local max=$REPLY - + z.arg.named max $@ default=2 && local max=$REPLY z.arg.named.shift max $@ z.arr.count $REPLY diff --git a/lib/arg/analysis.zsh b/lib/arg/analysis.zsh index e1ce1c2..60b40a2 100644 --- a/lib/arg/analysis.zsh +++ b/lib/arg/analysis.zsh @@ -8,9 +8,7 @@ # example: # z.arg.get "a" "b" "c" index=2 #=> "b" z.arg.get() { - z.arg.named index $@ - local index=$REPLY - + z.arg.named index $@ && local index=$REPLY z.arg.named.shift index $@ local args=($REPLY) z.arr.count $args diff --git a/lib/arg/is/operator.zsh b/lib/arg/is/operator.zsh index 29eb751..0e6b191 100644 --- a/lib/arg/is/operator.zsh +++ b/lib/arg/is/operator.zsh @@ -39,11 +39,8 @@ z.arg.is.empty() { # z.arg.is.valid "a" "b" "c" length=2 #=> 0 # z.arg.is.valid "a" "b" "c" length=4 #=> 1 z.arg.is.valid() { - z.arg.named length $@ - local length=$REPLY - - z.arg.named.shift length $@ - local args=($REPLY) + z.arg.named length $@ && local length=$REPLY + z.arg.named.shift length $@ && local args=($REPLY) local message="Expected at least $length arguments, but got ${#args}" if z.int.is.lt ${#args} $length; then diff --git a/lib/arg/process.zsh b/lib/arg/process.zsh index 112c456..b45f567 100644 --- a/lib/arg/process.zsh +++ b/lib/arg/process.zsh @@ -12,20 +12,11 @@ # z.arg.as name=$1 as="-h|--help" #=> REPLY="" z.arg.as() { local args=($@) - z.arg.named name $args - local name=$REPLY - - z.arg.named.shift name $args - args=($REPLY) - - z.arg.named as $args - local as=$REPLY - - z.arg.named.shift as $args - args=($REPLY) - - z.arg.named return $args - local return=$REPLY + z.arg.named name $args && local name=$REPLY + z.arg.named.shift name $args && args=($REPLY) + z.arg.named as $args && local as=$REPLY + z.arg.named.shift as $args && args=($REPLY) + z.arg.named return $args && local return=$REPLY z.str.split str=$as local split_as=($REPLY[@]) diff --git a/lib/arr/operator.zsh b/lib/arr/operator.zsh index 51147dc..e582b13 100644 --- a/lib/arr/operator.zsh +++ b/lib/arr/operator.zsh @@ -9,9 +9,7 @@ # z.arr.includes target=apple "banana" "apple" "cherry" #=> 0 (true) # z.arr.includes target=grape "banana" "apple" "cherry" #=> 1 (false) z.arr.includes() { - z.arg.named target $@ - local target=$REPLY - + z.arg.named target $@ && local target=$REPLY z.arg.named.shift target $@ local list=($REPLY) @@ -33,9 +31,7 @@ z.arr.includes() { # z.arr.excludes target=apple "banana" "apple" "cherry" #=> 1 (false) # z.arr.excludes target=grape "banana" "apple" "cherry" #=> 0 (true) z.arr.excludes() { - z.arg.named target $@ - local target=$REPLY - + z.arg.named target $@ && local target=$REPLY z.arg.named.shift target $@ local list=($REPLY) diff --git a/lib/arr/process.zsh b/lib/arr/process.zsh index 8797b1b..9a77083 100644 --- a/lib/arr/process.zsh +++ b/lib/arr/process.zsh @@ -8,11 +8,8 @@ # example: # z.arr.join "a" "b" "c" #=> REPLY="a b c" z.arr.join() { - z.arg.named delimiter $@ default=" " - local delimiter=$REPLY - - z.arg.named.shift delimiter $@ - local arr=($REPLY) + z.arg.named delimiter $@ default=" " && local delimiter=$REPLY + z.arg.named.shift delimiter $@ && local arr=($REPLY) local IFS=$delimiter z.return "${arr[*]}" @@ -29,9 +26,7 @@ z.arr.join() { # z.arr.split delimiter="," "a,b,c" #=> REPLY=("a" "b" "c") # z.arr.split "a b c" #=> REPLY=("a" "b" "c") z.arr.split() { - z.arg.named delimiter $@ default=" " - local delimiter=$REPLY - + z.arg.named delimiter $@ default=" " && local delimiter=$REPLY z.arg.named.shift delimiter $@ local str=$REPLY local arr @@ -54,17 +49,11 @@ z.arr.split() { z.arr.gsub() { local args=($@) - z.arg.named search $args - local search=${REPLY} + z.arg.named search $args && local search=${REPLY} + z.arg.named.shift search $args && args=($REPLY) - z.arg.named.shift search $args - args=($REPLY) - - z.arg.named replace $args - local replace=${REPLY} - - z.arg.named.shift replace $args - args=($REPLY) + z.arg.named replace $args && local replace=${REPLY} + z.arg.named.shift replace $args && args=($REPLY) local result=() @@ -88,9 +77,7 @@ z.arr.gsub() { z.arr.sort() { z.arg.named by $@ default=asc local sort_by=$REPLY - - z.arg.named.shift by $@ - local arr=($REPLY) + z.arg.named.shift by $@ && local arr=($REPLY) case $sort_by in asc) @@ -140,11 +127,8 @@ z.arr.unique() { # example: # z.arr.diff base="a b c" other="b c d" #=> REPLY=("a" "d") z.arr.diff() { - z.arg.named base $@ - local base=$REPLY - - z.arg.named other $@ - local other=$REPLY + z.arg.named base $@ && local base=$REPLY + z.arg.named other $@ && local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -189,11 +173,8 @@ z.arr.diff() { # example: # z.arr.intersect base="a b c" other="b c d" #=> REPLY=("b" "c") z.arr.intersect() { - z.arg.named base $@ - local base=$REPLY - - z.arg.named other $@ - local other=$REPLY + z.arg.named base $@ && local base=$REPLY + z.arg.named other $@ && local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -232,11 +213,8 @@ z.arr.intersect() { # example: # z.arr.union base="a b c" other="b c d e" #=> REPLY=("a" "b" "c" "d" "e") z.arr.union() { - z.arg.named base $@ - local base=$REPLY - - z.arg.named other $@ - local other=$REPLY + z.arg.named base $@ && local base=$REPLY + z.arg.named other $@ && local other=$REPLY local base_arr=(${=base}) local other_arr=(${=other}) @@ -300,17 +278,10 @@ z.arr.reverse() { # z.arr.slice offset=2 to=5 "a" "b" "c" "d" "e" #=> REPLY=("c" "d" "e") z.arr.slice() { local args=($@) - z.arg.named offset $args - local offset=$REPLY - - z.arg.named to $args - local to=$REPLY - - z.arg.named.shift offset $args - args=($REPLY) - - z.arg.named.shift to $args - args=($REPLY) + z.arg.named offset $args && local offset=$REPLY + z.arg.named to $args && local to=$REPLY + z.arg.named.shift offset $args && args=($REPLY) + z.arg.named.shift to $args && args=($REPLY) local arr=($args) if z.is.not.null "$offset"; then diff --git a/lib/dir/process.zsh b/lib/dir/process.zsh index 6a754c5..ee5d0ee 100644 --- a/lib/dir/process.zsh +++ b/lib/dir/process.zsh @@ -7,8 +7,7 @@ # example: # z.dir.make path="/path/to/dir" z.dir.make() { - z.arg.named path $@ - local dir=$REPLY + z.arg.named path $@ && local dir=$REPLY z.dir.not.exists $dir && mkdir -p $dir } @@ -22,8 +21,7 @@ z.dir.make() { # example: # z.dir.remove path="/path/to/dir" z.dir.remove() { - z.arg.named path $@ - local dir=$REPLY + z.arg.named path $@ && local dir=$REPLY z.dir.exists $dir && rm -rf $dir } diff --git a/lib/file/process.zsh b/lib/file/process.zsh index f444ca0..0e52839 100644 --- a/lib/file/process.zsh +++ b/lib/file/process.zsh @@ -8,11 +8,8 @@ # example: # z.file.make path="/path/to/file.txt" with_dir=true z.file.make() { - z.arg.named path $@ - local file=$REPLY - - z.arg.named with_dir $@ default=false - local with_dir=$REPLY + z.arg.named path $@ && local file=$REPLY + z.arg.named with_dir $@ default=false && local with_dir=$REPLY if z.is.true $with_dir; then z.dir.make path=$(dirname $file) @@ -31,11 +28,8 @@ z.file.make() { # example: # z.file.write path="/path/to/file.txt" content="hello world" z.file.write() { - z.arg.named path $@ - local file=$REPLY - - z.arg.named content $@ - local content=$REPLY + z.arg.named path $@ && local file=$REPLY + z.arg.named content $@ && local content=$REPLY echo -n "$content" > $file } @@ -49,8 +43,7 @@ z.file.write() { # example: # z.file.read path="/path/to/file.txt" z.file.read() { - z.arg.named path $@ - local file=$REPLY + z.arg.named path $@ && local file=$REPLY if z.file.exists $file; then REPLY=$(cat $file) diff --git a/lib/file/read/process.zsh b/lib/file/read/process.zsh index 03dba58..0001cc4 100644 --- a/lib/file/read/process.zsh +++ b/lib/file/read/process.zsh @@ -7,8 +7,7 @@ # example: # z.file.read.lines path="/path/to/file.txt" z.file.read.lines() { - z.arg.named path $@ - local file=$REPLY + z.arg.named path $@ && local file=$REPLY if z.file.exists $file; then REPLY=(${(f)$(cat $file)}) @@ -27,11 +26,8 @@ z.file.read.lines() { # example: # z.file.read.pick path="/path/to/file.txt" word="search_word" z.file.read.pick() { - z.arg.named path $@ - local file=$REPLY - - z.arg.named word $@ - local word=$REPLY + z.arg.named path $@ && local file=$REPLY + z.arg.named word $@ && local word=$REPLY if z.file.exists $file; then REPLY=$(grep $word $file | head -n 1) diff --git a/lib/file/write/process.zsh b/lib/file/write/process.zsh index ec8966e..84948a4 100644 --- a/lib/file/write/process.zsh +++ b/lib/file/write/process.zsh @@ -8,11 +8,8 @@ # example: # z.file.write.last path="/path/to/file.txt" content="hello world" z.file.write.last() { - z.arg.named path $@ - local file=$REPLY - - z.arg.named content $@ - local content=$REPLY + z.arg.named path $@ && local file=$REPLY + z.arg.named content $@ && local content=$REPLY echo "$content" >> $file } diff --git a/lib/hash/has/not/operator.zsh b/lib/hash/has/not/operator.zsh index d6ff9af..76c22b3 100644 --- a/lib/hash/has/not/operator.zsh +++ b/lib/hash/has/not/operator.zsh @@ -11,11 +11,8 @@ # z.hash.has.not.key hash key=age # echo $? # outputs 0 z.hash.has.not.key() { - z.arg.named.shift key $@ - local hash_name=$REPLY - - z.arg.named key $@ - local key=$REPLY + z.arg.named.shift key $@ && local hash_name=$REPLY + z.arg.named key $@ && local key=$REPLY local ref="${hash_name}[$key]" @@ -35,11 +32,8 @@ z.hash.has.not.key() { # z.hash.has.not.value hash key=name # echo $? # outputs 0 z.hash.has.not.value() { - z.arg.named key $@ - local key=$REPLY - - z.arg.named.shift key $@ - local hash_name=$REPLY + z.arg.named key $@ && local key=$REPLY + z.arg.named.shift key $@ && local hash_name=$REPLY z.is.null ${${(P)hash_name}[$key]} } diff --git a/lib/hash/has/operator.zsh b/lib/hash/has/operator.zsh index a4041c3..d23e3bd 100644 --- a/lib/hash/has/operator.zsh +++ b/lib/hash/has/operator.zsh @@ -11,11 +11,8 @@ # z.hash.has.key hash key=name # echo $? # outputs 0 z.hash.has.key() { - z.arg.named.shift key $@ - local hash_name=$REPLY - - z.arg.named key $@ - local key=$REPLY + z.arg.named.shift key $@ && local hash_name=$REPLY + z.arg.named key $@ && local key=$REPLY local ref="${hash_name}[$key]" @@ -35,11 +32,8 @@ z.hash.has.key() { # z.hash.has.value hash key=name # echo $? # outputs 0 z.hash.has.value() { - z.arg.named key $@ - local key=$REPLY - - z.arg.named.shift key $@ - local hash_name=$REPLY + z.arg.named key $@ && local key=$REPLY + z.arg.named.shift key $@ && local hash_name=$REPLY z.is.not.null ${${(P)hash_name}[$key]} } diff --git a/lib/hash/process.zsh b/lib/hash/process.zsh index fbf421c..c0183c5 100644 --- a/lib/hash/process.zsh +++ b/lib/hash/process.zsh @@ -38,11 +38,8 @@ z.hash.to_arr() { # local -A merged=($REPLY) # echo ${merged[name]} # outputs "John" z.hash.merge() { - z.arg.named base $@ - local base=$REPLY - - z.arg.named other $@ - local other=$REPLY + z.arg.named base $@ && local base=$REPLY + z.arg.named other $@ && local other=$REPLY local -A merged_hash diff --git a/lib/io/error/process.zsh b/lib/io/error/process.zsh index f0d276f..ed40b43 100644 --- a/lib/io/error/process.zsh +++ b/lib/io/error/process.zsh @@ -9,12 +9,8 @@ # example: # z.io.error.oneline "error message" z.io.error.oneline() { - z.arg.named color $@ default=red - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=red && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -36,12 +32,8 @@ z.io.error.oneline() { # example: # z.io.error.line "error1" "error2" z.io.error.line() { - z.arg.named color $@ default=red - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=red && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/process.zsh b/lib/io/process.zsh index cb1ed00..89811ca 100644 --- a/lib/io/process.zsh +++ b/lib/io/process.zsh @@ -9,12 +9,8 @@ # example: # z.io "hello" "world" #=> hello\nworld z.io() { - z.arg.named color $@ - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -52,12 +48,8 @@ z.io.empty() { # z.io.oneline "hello" # z.io.oneline "world" #=> helloworld z.io.oneline() { - z.arg.named color $@ - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -111,12 +103,8 @@ z.io.null() { # z.io.line "hello" "world" #=> hello\nworld # z.io.line #=> (empty line) z.io.line() { - z.arg.named color $@ - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -159,12 +147,8 @@ z.io.read() { # example: # z.io.success "Operation completed successfully." z.io.success() { - z.arg.named color $@ default=green - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=green && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY @@ -182,12 +166,8 @@ z.io.success() { # example: # z.io.warn "This is a warning message." z.io.warn() { - z.arg.named color $@ default=yellow - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=yellow && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY @@ -205,12 +185,8 @@ z.io.warn() { # example: # z.io.error "error message" z.io.error() { - z.arg.named color $@ default=red - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=red && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/success/process.zsh b/lib/io/success/process.zsh index bbcb782..047e0ed 100644 --- a/lib/io/success/process.zsh +++ b/lib/io/success/process.zsh @@ -9,12 +9,8 @@ # example: # z.io.success.oneline "success message" z.io.success.oneline() { - z.arg.named color $@ default=green - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=green && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -36,12 +32,8 @@ z.io.success.oneline() { # example: # z.io.success.line "success1" "success2" z.io.success.line() { - z.arg.named color $@ default=green - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=green && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/io/warn/process.zsh b/lib/io/warn/process.zsh index ab8f9d6..7fc86a5 100644 --- a/lib/io/warn/process.zsh +++ b/lib/io/warn/process.zsh @@ -9,12 +9,8 @@ # example: # z.io.warn.oneline "warn message" z.io.warn.oneline() { - z.arg.named color $@ default=yellow - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=yellow && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) @@ -36,12 +32,8 @@ z.io.warn.oneline() { # example: # z.io.warn.line "warn1" "warn2" z.io.warn.line() { - z.arg.named color $@ default=yellow - local color=$REPLY - - z.arg.named indent $@ - local indent=$REPLY - + z.arg.named color $@ default=yellow && local color=$REPLY + z.arg.named indent $@ && local indent=$REPLY z.arg.named.shift color $@ z.arg.named.shift indent $REPLY local args=($REPLY) diff --git a/lib/perm/process.zsh b/lib/perm/process.zsh index 4db16f5..7a1aa49 100644 --- a/lib/perm/process.zsh +++ b/lib/perm/process.zsh @@ -54,11 +54,8 @@ z.perm.dir() { # example: # z.perm._apply recursive=false path=/path/to/file mode=600 z.perm._apply() { - z.arg.named recursive $@ default=false - local recursive=$REPLY - - z.arg.named path $@ - local target_path=$REPLY + z.arg.named recursive $@ default=false && local recursive=$REPLY + z.arg.named path $@ && local target_path=$REPLY if z.is.null "$target_path"; then z.io.error "path is required" @@ -93,11 +90,8 @@ z.perm._apply() { # example: # z.perm._owner_spec owner=user group=group #=> "user:group" z.perm._owner_spec() { - z.arg.named owner $@ default="" - local owner=$REPLY - - z.arg.named group $@ default="" - local group=$REPLY + z.arg.named owner $@ default="" && local owner=$REPLY + z.arg.named group $@ default="" && local group=$REPLY if z.is.null "$owner" && z.is.null "$group"; then z.return @@ -128,8 +122,7 @@ z.perm._owner_spec() { # mode_group=read,none,none \ # mode_other=none,none,none z.perm._mode() { - z.arg.named mode $@ default="" - local mode=$REPLY + z.arg.named mode $@ default="" && local mode=$REPLY if z.is.not.null "$mode"; then z.return "$mode" return 0 @@ -147,14 +140,9 @@ z.perm._mode() { return 1 fi - z.arg.named mode_owner $@ default="none,none,none" - local mode_owner=$REPLY - - z.arg.named mode_group $@ default="none,none,none" - local mode_group=$REPLY - - z.arg.named mode_other $@ default="none,none,none" - local mode_other=$REPLY + z.arg.named mode_owner $@ default="none,none,none" && local mode_owner=$REPLY + z.arg.named mode_group $@ default="none,none,none" && local mode_group=$REPLY + z.arg.named mode_other $@ default="none,none,none" && local mode_other=$REPLY z.perm._mode_digit "$mode_owner" || return 1 local owner_digit=$REPLY diff --git a/lib/str/color/process.zsh b/lib/str/color/process.zsh index 27e1f16..e81ec6e 100644 --- a/lib/str/color/process.zsh +++ b/lib/str/color/process.zsh @@ -28,11 +28,8 @@ z.str.color.strip() { # example: # z.str.color.decorate color=red message="Hello" #=> $'\033[31mHello\033[0m' z.str.color.decorate() { - z.arg.named color $@ - local color=$REPLY - - z.arg.named message $@ - local message=$REPLY + z.arg.named color $@ && local color=$REPLY + z.arg.named message $@ && local message=$REPLY z.str.color.strip $message local plain=$REPLY diff --git a/lib/str/match/process.zsh b/lib/str/match/process.zsh index ff94a53..5b75684 100644 --- a/lib/str/match/process.zsh +++ b/lib/str/match/process.zsh @@ -31,9 +31,7 @@ z.str.match.rest() { # z.str.match.nth "one two three" "^o" index=1 #=> "one" # z.str.match.nth "apple banana cherry" "^a" index=2 #=> "banana" z.str.match.nth() { - z.arg.named index $@ - local index=$REPLY - + z.arg.named index $@ && local index=$REPLY z.arg.named.shift index $@ local str=$REPLY[1] local regex=$REPLY[2] diff --git a/lib/str/process.zsh b/lib/str/process.zsh index 4024869..8725288 100644 --- a/lib/str/process.zsh +++ b/lib/str/process.zsh @@ -33,11 +33,8 @@ z.str.color() { # example: # z.str.indent level=2 message="Hello" #=> " Hello" z.str.indent() { - z.arg.named level $@ - local level=$REPLY - - z.arg.named message $@ - local message=$REPLY + z.arg.named level $@ && local level=$REPLY + z.arg.named message $@ && local message=$REPLY if z.int.is.not.match $level || z.int.is.lt $level 0; then level=0 @@ -61,11 +58,8 @@ z.str.indent() { # example: # z.str.split str="apple|banana|cherry" delimiter=| #=> ("apple" "banana" "cherry") z.str.split() { - z.arg.named str $@ - local str=$REPLY - - z.arg.named delimiter $@ default="|" - local delimiter=$REPLY + z.arg.named str $@ && local str=$REPLY + z.arg.named delimiter $@ default="|" && local delimiter=$REPLY local IFS=$delimiter REPLY=(${=str}) @@ -83,9 +77,7 @@ z.str.split() { # z.str.partition "p foo bar" "[[:space:]]+" #=> ("p" "foo bar") # z.str.partition "a[0-9]b" "[0-9]" literal=true #=> ("a" "b") z.str.partition() { - z.arg.named literal $@ default=false - local literal=$REPLY - + z.arg.named literal $@ default=false && local literal=$REPLY z.arg.named.shift literal $@ local str=$REPLY[1] local delimiter=$REPLY[2] @@ -161,17 +153,10 @@ z.str.match() { # z.str.gsub str="Hello123World" search="[0-9]" replace="-" #=> "Hello---World" # z.str.gsub str="a[0-9]b" search="[0-9]" replace="X" literal=true #=> "aXb" z.str.gsub() { - z.arg.named str $@ - local str=$REPLY - - z.arg.named search $@ - local search=$REPLY - - z.arg.named replace $@ - local replace=$REPLY - - z.arg.named literal $@ default=false - local literal=$REPLY + z.arg.named str $@ && local str=$REPLY + z.arg.named search $@ && local search=$REPLY + z.arg.named replace $@ && local replace=$REPLY + z.arg.named literal $@ default=false && local literal=$REPLY if z.is.null $str || z.is.null $search; then z.return $str @@ -378,12 +363,8 @@ z.str.kebabize() { # z.str.delimitize delimiter="_" "helloWorld" #=> "hello_world" # z.str.delimitize delimiter="-" replace_chars="[ _]" "hello world_test" #=> "hello-world-test" z.str.delimitize() { - z.arg.named delimiter $@ - local delimiter=$REPLY - - z.arg.named replace_chars $@ default="[ _-]" - local replace_chars=$REPLY - + z.arg.named delimiter $@ && local delimiter=$REPLY + z.arg.named replace_chars $@ default="[ _-]" && local replace_chars=$REPLY z.arg.named.shift delimiter $@ z.arg.named.shift replace_chars $REPLY @@ -447,12 +428,8 @@ z.str.visible() { # example: # z.str.ljust width=10 fill="." "Hi" #=> "Hi........" z.str.ljust() { - z.arg.named width $@ - local width=$REPLY - - z.arg.named fill $@ default=" " - local fill=$REPLY - + z.arg.named width $@ && local width=$REPLY + z.arg.named fill $@ default=" " && local fill=$REPLY z.arg.named.shift width $@ z.arg.named.shift fill $REPLY local str=$REPLY @@ -483,12 +460,8 @@ z.str.ljust() { # example: # z.str.rjust width=10 fill="." "Hi" #=> "........Hi" z.str.rjust() { - z.arg.named width $@ - local width=$REPLY - - z.arg.named fill $@ default=" " - local fill=$REPLY - + z.arg.named width $@ && local width=$REPLY + z.arg.named fill $@ default=" " && local fill=$REPLY z.arg.named.shift width $@ z.arg.named.shift fill $REPLY local str=$REPLY diff --git a/lib/t/dsl.zsh b/lib/t/dsl.zsh index 8c909fd..43a9cb7 100644 --- a/lib/t/dsl.zsh +++ b/lib/t/dsl.zsh @@ -19,8 +19,7 @@ z.is.eq $z_mode "test" && { # example: # z.t.mark_not_found_error message="command not found: ls" z.t._mark_not_found_error() { - z.arg.named message $@ - local message=$REPLY + z.arg.named message $@ && local message=$REPLY local error_flag_file="/tmp/z_t_error_$$" z.file.make path=$error_flag_file with_dir=true diff --git a/lib/t/expect.zsh b/lib/t/expect.zsh index 7b77287..0c18bda 100644 --- a/lib/t/expect.zsh +++ b/lib/t/expect.zsh @@ -11,8 +11,7 @@ z.t.expect() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then @@ -44,8 +43,7 @@ z.t.expect() { z.t.expect.not() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then diff --git a/lib/t/expect/include.zsh b/lib/t/expect/include.zsh index 260001f..71addab 100644 --- a/lib/t/expect/include.zsh +++ b/lib/t/expect/include.zsh @@ -11,8 +11,7 @@ z.t.expect.includes() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then @@ -40,8 +39,7 @@ z.t.expect.includes() { z.t.expect.excludes() { local actual=$1 local expect=$2 - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t._state.skip.it if z.is.true $REPLY; then diff --git a/lib/t/expect/reply.zsh b/lib/t/expect/reply.zsh index 2cbea08..43b2729 100644 --- a/lib/t/expect/reply.zsh +++ b/lib/t/expect/reply.zsh @@ -11,9 +11,7 @@ z.t.expect.reply() { local expect=$1 local reply=$REPLY - - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t.expect "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/excludes.zsh b/lib/t/expect/reply/excludes.zsh index f57dacf..76a3082 100644 --- a/lib/t/expect/reply/excludes.zsh +++ b/lib/t/expect/reply/excludes.zsh @@ -11,9 +11,7 @@ z.t.expect.reply.excludes() { local expect=$1 local reply=$REPLY - - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t.expect.excludes "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/includes.zsh b/lib/t/expect/reply/includes.zsh index e54f74c..c1fa877 100644 --- a/lib/t/expect/reply/includes.zsh +++ b/lib/t/expect/reply/includes.zsh @@ -11,9 +11,7 @@ z.t.expect.reply.includes() { local expect=$1 local reply=$REPLY - - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t.expect.includes "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/is/not/null.zsh b/lib/t/expect/reply/is/not/null.zsh index 3172dc8..9a93dc5 100644 --- a/lib/t/expect/reply/is/not/null.zsh +++ b/lib/t/expect/reply/is/not/null.zsh @@ -10,9 +10,7 @@ z.t.expect.reply.is.not.null() { local expect="" local reply=$REPLY - - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t.expect.not "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/reply/is/null.zsh b/lib/t/expect/reply/is/null.zsh index cd5a2a5..66f0160 100644 --- a/lib/t/expect/reply/is/null.zsh +++ b/lib/t/expect/reply/is/null.zsh @@ -10,9 +10,7 @@ z.t.expect.reply.is.null() { local expect="" local reply=$REPLY - - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.t.expect "$reply" "$expect" "skip_unmock=$skip_unmock" } diff --git a/lib/t/expect/status.zsh b/lib/t/expect/status.zsh index 97c0f0d..bf7e88b 100644 --- a/lib/t/expect/status.zsh +++ b/lib/t/expect/status.zsh @@ -12,8 +12,7 @@ z.t.expect.status() { z.status local actual=$REPLY local expect=$1 - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY z.is.eq $expect "true" && expect=0 z.is.eq $expect "false" && expect=1 diff --git a/lib/t/log/dot.zsh b/lib/t/log/dot.zsh index b0502c1..ffe5834 100644 --- a/lib/t/log/dot.zsh +++ b/lib/t/log/dot.zsh @@ -40,8 +40,7 @@ z.t._log.dot.pending() { # example: # z.t._log.dot.output char=F z.t._log.dot.output() { - z.arg.named char $@ - local char=$REPLY + z.arg.named char $@ && local char=$REPLY local count_file="${Z_TEST_COMPACT_DIR}/.dot_count" local count=0 diff --git a/lib/t/log/failure.zsh b/lib/t/log/failure.zsh index ab76899..48ce01c 100644 --- a/lib/t/log/failure.zsh +++ b/lib/t/log/failure.zsh @@ -38,8 +38,7 @@ z.t._log.failure.remember() { # example: # z.t._log.failure.add "red" z.t._log.failure.add() { - z.arg.named color $@ - local color=$REPLY + z.arg.named color $@ && local color=$REPLY z.t._state.current_idx "describe" local d_idx=$REPLY @@ -79,8 +78,7 @@ z.t._log.failure.add() { # example: # z.t._log.failure.handle "error message" z.t._log.failure.handle() { - z.arg.named message $@ - local error_message=$REPLY + z.arg.named message $@ && local error_message=$REPLY z.str.indent level=4 message=$error_message z.str.color.red $REPLY diff --git a/lib/t/mock.zsh b/lib/t/mock.zsh index d99253d..5db53cf 100644 --- a/lib/t/mock.zsh +++ b/lib/t/mock.zsh @@ -8,11 +8,8 @@ # example: # z.t.mock name=my_func behavior=call_original z.t.mock() { - z.arg.named name $@ - local func_name=$REPLY - - z.arg.named behavior $@ - local behavior=$REPLY + z.arg.named name $@ && local func_name=$REPLY + z.arg.named behavior $@ && local behavior=$REPLY local original_func_name="original_$func_name" local nonfunctional="_nonfunctional" diff --git a/lib/t/mock/call_original.zsh b/lib/t/mock/call_original.zsh index 89766dc..0736b7d 100644 --- a/lib/t/mock/call_original.zsh +++ b/lib/t/mock/call_original.zsh @@ -7,8 +7,7 @@ # example: # z.t.mock.call_original name=my_func z.t.mock.call_original() { - z.arg.named name $@ - local name=$REPLY + z.arg.named name $@ && local name=$REPLY z.t.mock name=$name behavior=call_original } diff --git a/lib/t/mock/result.zsh b/lib/t/mock/result.zsh index aabff32..ca77589 100644 --- a/lib/t/mock/result.zsh +++ b/lib/t/mock/result.zsh @@ -8,8 +8,7 @@ # example: # z.t.mock.result name=my_func z.t.mock.result() { - z.arg.named name $@ - local func_name=$REPLY + z.arg.named name $@ && local func_name=$REPLY if z.is.null $func_name; then z.t._state.mock_last_func diff --git a/lib/t/mock/unmock.zsh b/lib/t/mock/unmock.zsh index 710cb5c..bc5d8c1 100644 --- a/lib/t/mock/unmock.zsh +++ b/lib/t/mock/unmock.zsh @@ -8,8 +8,7 @@ # example: # z.t.mock.unmock name=my_func z.t.mock.unmock() { - z.arg.named name $@ - local func_name=$REPLY + z.arg.named name $@ && local func_name=$REPLY local nonfunctional="_nonfunctional" if z.is.null $func_name; then @@ -48,8 +47,7 @@ z.t.mock.unmock() { # example: # z.t.mock.unmock.all z.t.mock.unmock.all() { - z.arg.named skip_unmock $@ - local skip_unmock=$REPLY + z.arg.named skip_unmock $@ && local skip_unmock=$REPLY if z.t.mock.unmock._is_not_skippable $skip_unmock; then z.t._state.mock_originals diff --git a/lib/t/process.zsh b/lib/t/process.zsh index 094fafd..11ad0a2 100644 --- a/lib/t/process.zsh +++ b/lib/t/process.zsh @@ -239,8 +239,7 @@ z.t._setup_temp_dirs() { # example: # z.t._show_compact_results $compact_dir $files z.t._show_compact_results() { - local compact_dir=$1 - shift + local compact_dir=$1 && shift local files=($@) z.io.empty @@ -270,8 +269,7 @@ z.t._show_compact_results() { # example: # z.t._show_totals $count_dir $files z.t._show_totals() { - local count_dir=$1 - shift + local count_dir=$1 && shift local files=($@) local total_tests=0 diff --git a/lib/t/state/current_idx.zsh b/lib/t/state/current_idx.zsh index 7ec53e8..2494287 100644 --- a/lib/t/state/current_idx.zsh +++ b/lib/t/state/current_idx.zsh @@ -24,11 +24,8 @@ z.t._state.current_idx() { # z.t._state.current_idx.set "describe" value=1 z.t._state.current_idx.set() { local REPLY - z.arg.named value $@ - local value=$REPLY - - z.arg.named.shift value $@ - local context=$REPLY + z.arg.named value $@ && local value=$REPLY + z.arg.named.shift value $@ && local context=$REPLY z_t_current_idx[$context]=$value } diff --git a/lib/t/state/logs.zsh b/lib/t/state/logs.zsh index 7c9dc55..5ee482b 100644 --- a/lib/t/state/logs.zsh +++ b/lib/t/state/logs.zsh @@ -48,11 +48,8 @@ z.t._state.logs.context() { # z.t._state.logs.context.set index=0 "Updated log entry" z.t._state.logs.context.set() { local REPLY - z.arg.named index $@ - local context=$REPLY - - z.arg.named.shift index $@ - local value=$REPLY + z.arg.named index $@ && local context=$REPLY + z.arg.named.shift index $@ && local value=$REPLY local target_log=${z_t_logs[$context]} diff --git a/lib/t/state/mock_calls.zsh b/lib/t/state/mock_calls.zsh index 2b38908..386d457 100644 --- a/lib/t/state/mock_calls.zsh +++ b/lib/t/state/mock_calls.zsh @@ -35,11 +35,8 @@ z.t._state.mock_calls.context() { # z.t._state.mock_calls.add name=my_func "arg1" "arg2" z.t._state.mock_calls.add() { local REPLY - z.arg.named name $@ - local func_name=$REPLY - - z.arg.named.shift name $@ - local args=$REPLY + z.arg.named name $@ && local func_name=$REPLY + z.arg.named.shift name $@ && local args=$REPLY if z.is.not.null ${z_t_mock_calls[$func_name]}; then z_t_mock_calls[$func_name]="${z_t_mock_calls[$func_name]}${z_t_mock_call_sep}${args}" @@ -58,11 +55,8 @@ z.t._state.mock_calls.add() { # example: # z.t._state.mock_calls.set name=my_func "value=new value" z.t._state.mock_calls.set() { - z.arg.named name $@ - local func_name=$REPLY - - z.arg.named value $@ - local value=$REPLY + z.arg.named name $@ && local func_name=$REPLY + z.arg.named value $@ && local value=$REPLY z_t_mock_calls[$func_name]=$value } diff --git a/lib/t/state/mock_originals.zsh b/lib/t/state/mock_originals.zsh index d0e0907..47e8ea6 100644 --- a/lib/t/state/mock_originals.zsh +++ b/lib/t/state/mock_originals.zsh @@ -35,11 +35,8 @@ z.t._state.mock_originals.context() { # z.t._state.mock_originals.add name=my_func "original function definition" z.t._state.mock_originals.add() { local REPLY - z.arg.named name $@ - local func_name=$REPLY - - z.arg.named.shift name $@ - local original_func=$REPLY + z.arg.named name $@ && local func_name=$REPLY + z.arg.named.shift name $@ && local original_func=$REPLY z_t_mock_originals[$func_name]=$original_func } diff --git a/test/lib/readme/sample_test.zsh b/test/lib/readme/sample_test.zsh index 0fcb64a..bba1cb9 100755 --- a/test/lib/readme/sample_test.zsh +++ b/test/lib/readme/sample_test.zsh @@ -1,9 +1,7 @@ source ${z_main} my.argument_check() { - z.arg.named max $@ default=2 - local max=$REPLY - + z.arg.named max $@ default=2 && local max=$REPLY z.arg.named.shift max $@ z.arr.count $REPLY From f0f2842243e2b4db0cf972c63abb752394c5c9fa Mon Sep 17 00:00:00 2001 From: milkeclair Date: Sun, 15 Nov 2026 13:26:00 +0900 Subject: [PATCH 5/5] refactor: remove redundant archive and completion cancellation guards --- lib/update/archive/process.zsh | 1 - lib/update/installation/process.zsh | 2 +- test/lib/update/archive/process_test.zsh | 4 ++-- test/lib/update/installation/process_test.zsh | 22 +++++++++++++------ 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/update/archive/process.zsh b/lib/update/archive/process.zsh index 6873d1d..9f17888 100644 --- a/lib/update/archive/process.zsh +++ b/lib/update/archive/process.zsh @@ -46,7 +46,6 @@ z.update.archive._extract() { local dir=$REPLY z.is.null "$dir" && { z.return; return 1; } - z.file.exists "$file" || { z.return; return 1; } z.dir.exists "$dir" && { z.return; return 1; } z.dir.make path="$dir" || return 1 diff --git a/lib/update/installation/process.zsh b/lib/update/installation/process.zsh index de1bd41..5d667f0 100644 --- a/lib/update/installation/process.zsh +++ b/lib/update/installation/process.zsh @@ -53,7 +53,7 @@ z.update.installation._reload() { local previous_dir=$REPLY if (( ${+functions[z.completion.cache._cancel]} )); then - z.completion.cache._cancel || return 1 + z.completion.cache._cancel fi if z.is.eq "$previous_dir" "$dir" || z.str.start_with "$previous_dir" "$dir/"; then diff --git a/test/lib/update/archive/process_test.zsh b/test/lib/update/archive/process_test.zsh index 5d497ee..cad59be 100644 --- a/test/lib/update/archive/process_test.zsh +++ b/test/lib/update/archive/process_test.zsh @@ -165,8 +165,8 @@ z.t.describe "z.update.archive._extract"; { } z.t.context "file引数がない場合"; { - z.t.it "展開先を作らない"; { - z.update.archive._extract dir=/tmp/z_t/update_extract_absent + z.t.it "失敗して展開先を残さない"; { + z.update.archive._extract dir=/tmp/z_t/update_extract_absent 2>/dev/null local extract_status=$? local result=$REPLY diff --git a/test/lib/update/installation/process_test.zsh b/test/lib/update/installation/process_test.zsh index 4fee652..96976f0 100644 --- a/test/lib/update/installation/process_test.zsh +++ b/test/lib/update/installation/process_test.zsh @@ -254,20 +254,28 @@ z.t.describe "z.update.installation._reload"; { } } - z.t.context "cancelが失敗した場合"; { - z.t.it "sourceを実行しない"; { - local dir=/tmp/z_t/update_reload/cancel_failure + z.t.context "補完jobが回収済みの場合"; { + z.t.it "IDを破棄して本体の再読込を続ける"; { + local dir=/tmp/z_t/update_reload/collected_job + local z_completion_cache_job_id=collected-job z.dir.make path="$dir" z.file.write path="$dir/main.zsh" content="touch \"$dir/loaded\"" - z.t.mock name="z.completion.cache._cancel" behavior="return 1" + z.t.mock name="z.job.status" behavior="return 1" + z.t.mock name="z.completion.enable" behavior="return 0" - z.update.installation._reload dir="$dir" + () { + local Z_ROOT=$z_root + + z.update.installation._reload dir="$dir" + } local reload_status=$? + local remaining_id=$z_completion_cache_job_id - z.t.expect "$reload_status" 1 + z.t.expect "$reload_status" 0 + z.t.expect.is.null "$remaining_id" - z.file.not.exists "$dir/loaded" + z.file.exists "$dir/loaded" z.t.expect.status.is.true z.dir.remove path=/tmp/z_t/update_reload