Skip to content

Commit

Permalink
Merge pull request #437 from sm-shaw/436
Browse files Browse the repository at this point in the history
Improve CLI diset error message
  • Loading branch information
abondvt89 committed Sep 27, 2022
2 parents f89a729 + bda574d commit fa9e267
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/generic/gencli.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,18 @@ proc vuset { args } {
}
}}}

proc findakey { key2find dictname } {
upvar #0 $dictname $dictname
foreach key [dict keys [ set $dictname]] {
dict for {k v} [dict get [ set $dictname ] $key] {
if { $k eq $key2find } {
return $key
}
}
}
return {}
}

proc diset { args } {
global rdbms opmode
if {[ llength $args ] != 3} {
Expand Down Expand Up @@ -554,11 +566,15 @@ proc diset { args } {
SQLiteUpdateKeyValue $key $dct $key2 $val
remote_command [ concat diset $dct $key2 [ list \{$val\} ]]
}}
} else {
putscli {Usage: diset dict key value}
putscli "Dictionary \"$dct\" for $rdbms exists but key \"$key2\" doesn't"
putscli "Type \"print dict\" for valid dictionaries and keys for $rdbms"
}
} else {
set key2find [ findakey $key2 $dictname ]
if { [ string length $key2find ] > 0 } {
putscli "Dictionary \"$dct\" for $rdbms exists but key \"$key2\" doesn't, key \"$key2\" is in the \"$key2find\" dictionary"
} else {
putscli "Dictionary \"$dct\" for $rdbms exists but key \"$key2\" doesn't, key \"$key2\" cannot be found in any $rdbms dictionary"
}
putscli "Type \"print dict\" for valid dictionaries and keys for $rdbms"
}
} else {
putscli {Usage: diset dict key value}
putscli "Dictionary \"$dct\" for $rdbms does not exist"
Expand Down

0 comments on commit fa9e267

Please sign in to comment.