Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-build-utils
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
korinf
etersoft-build-utils
Commits
e2b3a85f
Commit
e2b3a85f
authored
Dec 12, 2014
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve usearg
parent
d4f9848d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
7 deletions
+13
-7
common
share/eterbuild/functions/common
+7
-3
test_usearg.sh
tests/test_usearg.sh
+6
-4
No files found.
share/eterbuild/functions/common
View file @
e2b3a85f
...
...
@@ -468,13 +468,17 @@ showcmd()
SETCOLOR_NORMAL
}
# Example: $ command $(usearg -d "$PARAM")
# will add -d "$PARAM" if $PARAM is not empty
# Example:
# $ command $(usearg -d "$PARAM")
# will add -d "$PARAM" if $PARAM is not empty
# $ command $(usearg -d "$PARAM" "empty-word)
# will add -d "$PARAM" if $PARAM is not 'empty-word'
usearg
()
{
local
ARG
=
$1
shift
[
-n
"
$1
"
]
&&
echo
"
$ARG
$@
"
[
"
$1
"
!=
"
$2
"
]
&&
echo
"
$ARG
$1
"
}
# return 0 if arg1 >= arg2
...
...
tests/test_usearg.sh
View file @
e2b3a85f
...
...
@@ -8,8 +8,10 @@ check()
[
"
$2
"
!=
"
$3
"
]
&&
echo
"FATAL with '
$1
': result '
$2
' do not match with '
$3
'"
||
echo
"OK for '
$1
' with '
$2
'"
}
echo
"
$(
usearg
-f
TEST
)
"
echo
"
$(
usearg
-f
TEST MORE
)
"
echo
"
$(
usearg
-f
$TEST
)
"
check
"-f TEST"
"
$(
usearg
-f
TEST
)
"
"-f TEST"
check
"-f 'TEST MORE'"
"
$(
usearg
-f
'TEST MORE'
)
"
"-f TEST MORE"
check
"-f 'TEST MORE'"
"
$(
usearg
-f
TEST MORE
)
"
"-f TEST"
check
"-f 'TEST TEST'"
"
$(
usearg
-f
TEST TEST
)
"
""
check
"TEST=
$TEST
-f
\$
TEST"
"
$(
usearg
-f
$TEST
)
"
""
TEST
=
124
echo
"
$(
usearg
-f
$TEST
)
"
check
"TEST=
$TEST
-f
\$
TEST"
"
$(
usearg
-f
$TEST
)
"
"-f 124
"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment