Skip to content

Commit

Permalink
Options2 - commit as is
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed Jan 7, 2024
1 parent 6788062 commit 11c07a0
Show file tree
Hide file tree
Showing 18 changed files with 88 additions and 160 deletions.
12 changes: 6 additions & 6 deletions manualTests/Object::create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ source "${srcDir}/Options2/__all.sh"
# shellcheck source=/src/Log/__all.sh
source "${srcDir}/Log/__all.sh"


#set -x
set -o errexit
set -o pipefail
Expand All @@ -22,17 +21,18 @@ Object::create zzzGroupGlobalOptionsFunction \
--property-title "GLOBAL OPTIONS:"

Object::create simpleObjectFunction \
--type "Group"
--type "Group"

Object::create groupObjectFunction \
--type "Group" \
--property-title "title" \
--property-help "help"
--type "Group" \
--property-title "title" \
--property-help "help"

BASH_FRAMEWORK_DISPLAY_LEVEL=__LEVEL_DEBUG

Object::create optionFunction \
--type "Option" \
--property-variableName "varName"

Options2::validateOptionObject "${optionFunction}"
# shellcheck disable=SC2154
Options2::validateOptionObject "${optionFunction}"
2 changes: 1 addition & 1 deletion manualTests/Object::setProperty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ declare -a newPropertyObject=(
--property-property "propertyValue"
)
Object::setProperty newPropertyObject --property-newProperty "value"
declare -p newPropertyObject
declare -p newPropertyObject
3 changes: 2 additions & 1 deletion manualTests/Options2::renderHelpArg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ declare -a arg=(
--property-mandatory 1
--property-max 2
)
# shellcheck disable=SC2034
declare -a group=(
--type "Group"
--property-title "Global options"
Expand All @@ -42,4 +43,4 @@ declare -a arg=(
)
Options2::validateArgObject arg
UI::theme "default"
Options2::renderArgHelp arg 2>&1
Options2::renderArgHelp arg 2>&1
24 changes: 12 additions & 12 deletions manualTests/testCreateObject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ source src/Options2/__all.sh

declare myFunction
Object::create myFunction \
--type "Command" \
--property-name "François"
--type "Command" \
--property-name "François"
declare myFunction2
Object::create myFunction2 \
--array-list "a" \
--type "Command2" \
--property-name "François2" \
--array-list "b" \
--array-list "c"
--array-list "a" \
--type "Command2" \
--property-name "François2" \
--array-list "b" \
--array-list "c"

echo "--------------------------------------------"
${myFunction} getProperty --property-name
Expand All @@ -30,12 +30,12 @@ ${myFunction2} setProperty name "myFunction2François3"
${myFunction2} getProperty --property-name
echo -n "name2 "
${myFunction2} setProperty name2 "newProperty name2"

${myFunction2} getProperty --property-name2

echo "--------------------------------------------"
Object::create myFunction2 \
--function-name "argFunction2Overload" \
--type "Command2Overload" \
--property-name "François2Overload"
${myFunction2} getProperty --property-name
--function-name "argFunction2Overload" \
--type "Command2Overload" \
--property-name "François2Overload"
${myFunction2} getProperty --property-name
26 changes: 13 additions & 13 deletions src/Object/create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Object::create::simpleObject { #@test
Object::create simpleObjectFunction \
--type "simpleObjectType" \
--property-property "propertyValue"

run ${simpleObjectFunction} type
assert_output "simpleObjectType"

Expand All @@ -43,7 +43,7 @@ function Object::create::missingPositionalArg { #@test
run Object::create \
--type "simpleObjectType" \
--propertyInvalid-property "propertyValue" 2>&1

assert_output --partial "local: \`--type': invalid variable name for name reference"
assert_failure 1
}
Expand All @@ -54,7 +54,7 @@ function Object::create::simpleObjectNonStrict { #@test
--strict 0 \
--type "simpleObjectType" \
--property-property "propertyValue"

run ${simpleObjectType} strict
assert_output "0"

Expand All @@ -68,7 +68,7 @@ function Object::create::invalidProperty { #@test
run Object::create simpleObjectType \
--type "simpleObjectType" \
--propertyInvalid-property "propertyValue" 2>&1

assert_output --partial "ERROR - invalid object property --propertyInvalid-property"
assert_failure 1
}
Expand All @@ -79,25 +79,25 @@ function Object::create::duplicatedProperty { #@test
--type "simpleObjectType" \
--property-property "propertyValue1" \
--property-property "propertyValue2" 2>&1

assert_output --partial "ERROR - property property is provided more than one time"
assert_failure 1
}

function Object::create::invalidObjectType { #@test
declare invalidObjectType
declare invalidObjectType
run Object::create invalidObjectType \
--type "invalidéObjectType" \
--property-property "propertyValue" 2>&1

assert_output --partial "ERROR - invalid object type invalidéObjectType"
assert_failure 1
}

function Object::create::missingObjectType { #@test
run Object::create missingObjectType \
--property-property "propertyValue" 2>&1

assert_output --partial "ERROR - missing object type"
assert_failure 1
}
Expand All @@ -107,9 +107,9 @@ function Object::create::unknownArray { #@test
Object::create unknownArray \
--type "simpleObjectType" \
--array-list "unknownArray" 2>&1

run ${unknownArray} getArray "unknownArray"

assert_output --partial "ERROR - unknown array unknownArray"
assert_failure 2
}
Expand All @@ -121,7 +121,7 @@ function Object::create::propertyArrayOrdered { #@test
--property-property "propertyValue" \
--array-list "value1" \
--array-list "value2"

run ${propertyArrayOrdered} type
assert_success
assert_output "simpleObjectType"
Expand All @@ -148,7 +148,7 @@ function Object::create::propertyArrayUnordered { #@test
--array-list "value2" \
--property-property "propertyValue" \
--array-list "value3"

run ${propertyArrayUnordered} type
assert_success
assert_output "simpleObjectType"
Expand All @@ -172,4 +172,4 @@ function Object::create::propertyArrayUnordered { #@test
assert_lines_count 2
assert_line --index 0 "list"
assert_line --index 1 "property"
}
}
4 changes: 2 additions & 2 deletions src/Object/getArray.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ function Object::getArray::multipleArrayValues { #@test
assert_success
}

function Object::getArray::unknownProperty { #@test
function Object::getArray::unknownArray { #@test
declare -a simpleObject=(
--type "simpleObjectType"
--property-property "propertyValue"
)
run Object::getArray simpleObject --array-unknownArray 1
assert_output --partial "ERROR - unknown array --array-unknownArray"
assert_output ""
assert_failure 1

run Object::getArray simpleObject --array-unknownArray 0
Expand Down
6 changes: 6 additions & 0 deletions src/Object/getArray.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

# @description get array elements from object
# @arg $1 object_get_array_objectData:&String[] the object
# @arg $2 arrayName:String the name of the array property to search (eg: --array-property)
# @arg $3 strict:Boolean if !0 then return code 1 if array property not found
# @stdout the array property values if array property found(one value by line)
# @exitcode 1 if array property not found
Object::getArray() {
local -n object_get_array_objectData=$1
local arrayName="${2:-}"
Expand Down
2 changes: 1 addition & 1 deletion src/Object/getProperty.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Object::getProperty::unknownProperty { #@test
--property-property "propertyValue"
)
run Object::getProperty simpleObject --property-unknownProperty 1
assert_output --partial "ERROR - unknown property --property-unknownProperty"
assert_output ""
assert_failure 1

run Object::getProperty simpleObject --property-unknownProperty 0
Expand Down
6 changes: 6 additions & 0 deletions src/Object/getProperty.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/bin/bash

# @description get property value from object
# @arg $1 object_get_property_objectData:&String[] the object
# @arg $2 propertyName:String the name of the property to search (eg: --property)
# @arg $3 strict:Boolean if !0 then return code 1 if property not found
# @stdout the property value if property found
# @exitcode 1 if property not found
Object::getProperty() {
local -n object_get_property_objectData=$1
local propertyName="${2:-}"
Expand Down
63 changes: 0 additions & 63 deletions src/Object/initFromTemplate.bats

This file was deleted.

32 changes: 0 additions & 32 deletions src/Object/initFromTemplate.sh

This file was deleted.

8 changes: 6 additions & 2 deletions src/Object/memberExists.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/bin/bash

# @description check if member(property or array property) exists on given object
# @arg $1 object_member_exists_objectData:&String[] the object
# @arg $2 memberName:String the name of the member to search (eg: --property)
# @exitcode 1 if member not found
Object::memberExists() {
local -n object_member_exists_objectData=$1
local propertyName="${2:-}"
local memberName="${2:-}"

local -i propertiesLength="${#object_member_exists_objectData[@]}"
local -i i=0 || true
while ((i < propertiesLength)); do
if [[ "${object_member_exists_objectData[${i}]}" = "${propertyName}" ]]; then
if [[ "${object_member_exists_objectData[${i}]}" = "${memberName}" ]]; then
return 0
fi
((i = i + 1))
Expand Down
4 changes: 4 additions & 0 deletions src/Object/setArray.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# @description create or overwrite array property on object
# @arg $1 object_set_array_objectData:&String[] the object
# @arg $2 arrayName:String the name of the array property to search (eg: --array-property)
# @arg $@ arrayValues:String[] array values to set
Object::setArray() {
local -n object_set_array_objectData=$1
local arrayName="${2:-}"
Expand Down
4 changes: 4 additions & 0 deletions src/Object/setProperty.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# @description create or overwrite property value on object
# @arg $1 object_set_property_objectData:&String[] the object
# @arg $2 propertyName:String the name of the property to search (eg: --property)
# @arg $3 propertyValue:String property value to set
Object::setProperty() {
local -n object_set_property_objectData=$1
local propertyName="${2:-}"
Expand Down
Loading

0 comments on commit 11c07a0

Please sign in to comment.