* [PATCH 1/2] add function getargnum
@ 2012-11-26 2:38 Dave Young
[not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Dave Young @ 2012-11-26 2:38 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA, initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA, vgoyal-H+wXaHxf7aLQT0dZR+AlfA
For cmdline argument with numeric value, add a new function getargnum
It will get proper value with default value as $1, max value as $2.
valid result will be echo to stdout, for nul or value not valid it will just
echo the default value.
Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
modules.d/99base/dracut-lib.sh | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -167,6 +167,25 @@ getargbool() {
return 0
}
+# getargnum <defaultval> <maxval> <args...>
+# Will echo the arg if it's in range [0 - maxval].
+# If it's not set or it's not valid, will set it <defaultval>.
+getargnum() {
+ local _b
+ unset _b
+ local _default
+ local _max
+ _default=$1; shift
+ _max=$1; shift
+ _b=$(getarg "$@")
+ [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+ if [ -n "$_b" ]; then
+ [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
+ [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
+ fi
+ echo $_default
+}
+
_dogetargs() {
debug_off
local _o _found _key
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] add function getargnum
[not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
@ 2012-11-27 22:28 ` Vivek Goyal
[not found] ` <20121127222846.GF6964-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-28 8:42 ` [PATCH 1/2 v2] " Dave Young
2013-01-11 9:59 ` [PATCH 1/2] " Harald Hoyer
2 siblings, 1 reply; 6+ messages in thread
From: Vivek Goyal @ 2012-11-27 22:28 UTC (permalink / raw)
To: Dave Young
Cc: harald-H+wXaHxf7aLQT0dZR+AlfA, initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA
On Mon, Nov 26, 2012 at 10:38:47AM +0800, Dave Young wrote:
>
>
> For cmdline argument with numeric value, add a new function getargnum
> It will get proper value with default value as $1, max value as $2.
> valid result will be echo to stdout, for nul or value not valid it will just
> echo the default value.
>
> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> modules.d/99base/dracut-lib.sh | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> --- dracut.orig/modules.d/99base/dracut-lib.sh
> +++ dracut/modules.d/99base/dracut-lib.sh
> @@ -167,6 +167,25 @@ getargbool() {
> return 0
> }
>
> +# getargnum <defaultval> <maxval> <args...>
^^^^^^
Is above one arg or multiple args. I thought in one call we will resolve
the value of one parameter?
> +# Will echo the arg if it's in range [0 - maxval].
You might want to consider passing in minval instead of assuming it
is always 0. It just makes function more generic.
Thanks
Vivek
> +# If it's not set or it's not valid, will set it <defaultval>.
> +getargnum() {
> + local _b
> + unset _b
> + local _default
> + local _max
> + _default=$1; shift
> + _max=$1; shift
> + _b=$(getarg "$@")
> + [ $? -ne 0 -a -z "$_b" ] && _b=$_default
> + if [ -n "$_b" ]; then
> + [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
> + [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
> + fi
> + echo $_default
> +}
> +
> _dogetargs() {
> debug_off
> local _o _found _key
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] add function getargnum
[not found] ` <20121127222846.GF6964-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2012-11-28 5:51 ` Dave Young
0 siblings, 0 replies; 6+ messages in thread
From: Dave Young @ 2012-11-28 5:51 UTC (permalink / raw)
To: Vivek Goyal
Cc: harald-H+wXaHxf7aLQT0dZR+AlfA, initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA
On 11/28/2012 06:28 AM, Vivek Goyal wrote:
> On Mon, Nov 26, 2012 at 10:38:47AM +0800, Dave Young wrote:
>>
>>
>> For cmdline argument with numeric value, add a new function getargnum
>> It will get proper value with default value as $1, max value as $2.
>> valid result will be echo to stdout, for nul or value not valid it will just
>> echo the default value.
>>
>> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> ---
>> modules.d/99base/dracut-lib.sh | 19 +++++++++++++++++++
>> 1 file changed, 19 insertions(+)
>>
>> --- dracut.orig/modules.d/99base/dracut-lib.sh
>> +++ dracut/modules.d/99base/dracut-lib.sh
>> @@ -167,6 +167,25 @@ getargbool() {
>> return 0
>> }
>>
>> +# getargnum <defaultval> <maxval> <args...>
> ^^^^^^
> Is above one arg or multiple args. I thought in one call we will resolve
> the value of one parameter?
It is one arg. will s/args.../arg
>
>> +# Will echo the arg if it's in range [0 - maxval].
>
> You might want to consider passing in minval instead of assuming it
> is always 0. It just makes function more generic.
Make sense. I would like to assume the arg as a number >=0 even with the
minval added which means minval should be >=0.
>
> Thanks
> Vivek
>
>> +# If it's not set or it's not valid, will set it <defaultval>.
>> +getargnum() {
>> + local _b
>> + unset _b
>> + local _default
>> + local _max
>> + _default=$1; shift
>> + _max=$1; shift
>> + _b=$(getarg "$@")
>> + [ $? -ne 0 -a -z "$_b" ] && _b=$_default
>> + if [ -n "$_b" ]; then
>> + [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
>> + [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
>> + fi
>> + echo $_default
>> +}
>> +
>> _dogetargs() {
>> debug_off
>> local _o _found _key
--
Thanks
Dave
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2 v2] add function getargnum
[not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-11-27 22:28 ` Vivek Goyal
@ 2012-11-28 8:42 ` Dave Young
2013-01-11 9:59 ` [PATCH 1/2] " Harald Hoyer
2 siblings, 0 replies; 6+ messages in thread
From: Dave Young @ 2012-11-28 8:42 UTC (permalink / raw)
To: harald-H+wXaHxf7aLQT0dZR+AlfA, initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA, vgoyal-H+wXaHxf7aLQT0dZR+AlfA
For cmdline argument with numeric value, add a new function getargnum
It will get proper value with default value as $1, min value as $2,
max value as $3, and param name as $4. valid result will be echo to stdout.
for nul or value not valid it will just echo the default value.
Note: The values should be >=0
[v1->v2]: add arg <minval>
Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
modules.d/99base/dracut-lib.sh | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
--- dracut.orig/modules.d/99base/dracut-lib.sh
+++ dracut/modules.d/99base/dracut-lib.sh
@@ -167,6 +167,27 @@ getargbool() {
return 0
}
+# getargnum <defaultval> <minval> <maxval> <arg>
+# Will echo the arg if it's in range [minval - maxval].
+# If it's not set or it's not valid, will set it <defaultval>.
+# Note all values are required to be >= 0 here.
+# <defaultval> should be with [minval -maxval].
+getargnum() {
+ local _b
+ unset _b
+ local _default _min _max
+ _default=$1; shift
+ _min=$1; shift
+ _max=$1; shift
+ _b=$(getarg "$1")
+ [ $? -ne 0 -a -z "$_b" ] && _b=$_default
+ if [ -n "$_b" ]; then
+ [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
+ [[ $_b -ge $_min && $_b -le $_max ]] && echo $_b && return
+ fi
+ echo $_default
+}
+
_dogetargs() {
debug_off
local _o _found _key
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] add function getargnum
[not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-11-27 22:28 ` Vivek Goyal
2012-11-28 8:42 ` [PATCH 1/2 v2] " Dave Young
@ 2013-01-11 9:59 ` Harald Hoyer
[not found] ` <50EFE278.6040509-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2 siblings, 1 reply; 6+ messages in thread
From: Harald Hoyer @ 2013-01-11 9:59 UTC (permalink / raw)
To: Dave Young
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA, vgoyal-H+wXaHxf7aLQT0dZR+AlfA
Am 26.11.2012 03:38, schrieb Dave Young:
>
>
> For cmdline argument with numeric value, add a new function getargnum
> It will get proper value with default value as $1, max value as $2.
> valid result will be echo to stdout, for nul or value not valid it will just
> echo the default value.
>
> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> ---
> modules.d/99base/dracut-lib.sh | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> --- dracut.orig/modules.d/99base/dracut-lib.sh
> +++ dracut/modules.d/99base/dracut-lib.sh
> @@ -167,6 +167,25 @@ getargbool() {
> return 0
> }
>
> +# getargnum <defaultval> <maxval> <args...>
> +# Will echo the arg if it's in range [0 - maxval].
> +# If it's not set or it's not valid, will set it <defaultval>.
> +getargnum() {
> + local _b
> + unset _b
> + local _default
> + local _max
> + _default=$1; shift
> + _max=$1; shift
> + _b=$(getarg "$@")
> + [ $? -ne 0 -a -z "$_b" ] && _b=$_default
> + if [ -n "$_b" ]; then
> + [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
we can't use "=~" because it's not posix shell. We restricted ourselves to dash
syntax in the initramfs. sorry.
> + [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
> + fi
> + echo $_default
> +}
> +
> _dogetargs() {
> debug_off
> local _o _found _key
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] add function getargnum
[not found] ` <50EFE278.6040509-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2013-01-14 8:57 ` Dave Young
0 siblings, 0 replies; 6+ messages in thread
From: Dave Young @ 2013-01-14 8:57 UTC (permalink / raw)
To: Harald Hoyer
Cc: initramfs-u79uwXL29TY76Z2rM5mHXA,
jstancek-H+wXaHxf7aLQT0dZR+AlfA, vgoyal-H+wXaHxf7aLQT0dZR+AlfA
On 01/11/2013 05:59 PM, Harald Hoyer wrote:
> Am 26.11.2012 03:38, schrieb Dave Young:
>>
>>
>> For cmdline argument with numeric value, add a new function getargnum
>> It will get proper value with default value as $1, max value as $2.
>> valid result will be echo to stdout, for nul or value not valid it will just
>> echo the default value.
>>
>> Signed-off-by: Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>> ---
>> modules.d/99base/dracut-lib.sh | 19 +++++++++++++++++++
>> 1 file changed, 19 insertions(+)
>>
>> --- dracut.orig/modules.d/99base/dracut-lib.sh
>> +++ dracut/modules.d/99base/dracut-lib.sh
>> @@ -167,6 +167,25 @@ getargbool() {
>> return 0
>> }
>>
>> +# getargnum <defaultval> <maxval> <args...>
>> +# Will echo the arg if it's in range [0 - maxval].
>> +# If it's not set or it's not valid, will set it <defaultval>.
>> +getargnum() {
>> + local _b
>> + unset _b
>> + local _default
>> + local _max
>> + _default=$1; shift
>> + _max=$1; shift
>> + _b=$(getarg "$@")
>> + [ $? -ne 0 -a -z "$_b" ] && _b=$_default
>> + if [ -n "$_b" ]; then
>> + [[ "$_b" =~ ^[0-9]+$ ]] && _b=$(($_b)) && \
>
> we can't use "=~" because it's not posix shell. We restricted ourselves to dash
> syntax in the initramfs. sorry.
Will fix, thanks for review.
>
>
>> + [[ $_b -ge 0 && $_b -le $_max ]] && echo $_b && return
>> + fi
>> + echo $_default
>> +}
>> +
>> _dogetargs() {
>> debug_off
>> local _o _found _key
>>
>
--
Thanks
Dave
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2013-01-14 8:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-26 2:38 [PATCH 1/2] add function getargnum Dave Young
[not found] ` <20121126023847.GA6884-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2012-11-27 22:28 ` Vivek Goyal
[not found] ` <20121127222846.GF6964-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-28 5:51 ` Dave Young
2012-11-28 8:42 ` [PATCH 1/2 v2] " Dave Young
2013-01-11 9:59 ` [PATCH 1/2] " Harald Hoyer
[not found] ` <50EFE278.6040509-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2013-01-14 8:57 ` Dave Young
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.