[RFC,v2,1/3] pw_mon: improve command line options

Message ID 20231107203158.1261199-2-aconole@redhat.com (mailing list archive)
State New
Headers
Series Add a recheck framework to pw-ci |

Commit Message

Aaron Conole Nov. 7, 2023, 8:31 p.m. UTC
  In the future, we'll use this to add support for passing opts into some parts
of pw_mon.

Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 pw_mon | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 51 insertions(+), 14 deletions(-)
  

Comments

Michael Santana Nov. 17, 2023, 4:26 p.m. UTC | #1
On Tue, Nov 7, 2023 at 3:32 PM Aaron Conole <aconole@redhat.com> wrote:
>
> In the future, we'll use this to add support for passing opts into some parts
> of pw_mon.
>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
Acked-by: Michael Santana <msantana@redhat.com>
> ---
>  pw_mon | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 51 insertions(+), 14 deletions(-)
>
> diff --git a/pw_mon b/pw_mon
> index 28feb8b..da4b9a9 100755
> --- a/pw_mon
> +++ b/pw_mon
> @@ -21,34 +21,71 @@
>
>  [ -f "${HOME}/.pwmon-rc" ] && source "${HOME}/.pwmon-rc"
>
> -if [ "$1" != "" ]; then
> -    pw_project="$1"
> -    shift
> +if [ "$1" != ""  ]; then
> +    if ! echo "$1" | grep -q -s -E ^-- ; then
The missing quotes give me OCD, but I'll let it pass :)

It is technically correct apparently. It worked when I tested it. I
guess I am so used to using grep with quotes that I had never
considered that there was a whole world where people use grep without
quotes :P

> +        pw_project="$1"
> +        shift
> +    fi
>  fi
>
>  if [ "$1" != "" ]; then
> -    pw_instance="$1"
> -    shift
> -fi
> -
> -if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
> -   echo "ERROR: Patchwork instance and project are unset."
> -   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
> -   echo "(or pass it as an argument)."
> -   echo "Also either setup pw_instance or pass it as an argument."
> -   exit 1
> +    if ! echo "$1" | grep -q -s -E ^-- ; then
> +        pw_instance="$1"
> +        shift
> +    fi
>  fi
>
>  userpw=""
>
>  if [ "$1" != "" ]; then
> -    pw_credential="$1"
> +    if ! echo "$1" | grep -q -s -E ^-- ; then
> +        pw_credential="$1"
> +        shift
> +    fi
>  fi
>
> +
> +while [ "$1" != "" ]; do
> +    if echo "$1" | grep -q -s -E ^--pw-project= ; then
> +        pw_project=$(echo "$1" | sed s/^--pw-project=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
> +        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
> +        shift
> +    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
> +        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
> +        shift
> +    elif echo "$1" | grep -E ^--help >/dev/null 2>&1; then
> +        echo "patchwork monitor script"
> +        echo "$0: args"
> +        echo "Required if not set in ~/.pwmon-rc file:"
> +        echo "  proj|--pw-project=<proj>               Project name"
> +        echo "  instance|--pw-instance=<inst url>      URL for pw"
> +        echo ""
> +        echo "Options:"
> +        echo "    --pw-credentials=u:p         Sets user / password for web client"
> +        echo "    --add-filter-recheck=filter  Adds a filter to flag that a recheck needs to be done"
> +        echo ""
> +        exit 0
> +    else
> +        echo "Unknown option: '$1'"
> +        echo "Rerun with --help for details"
> +        exit 1
> +    fi
> +done
> +
>  if [ "X$pw_credential" != "X" ]; then
>     userpw="-u \"${pw_credential}\""
>  fi
>
> +if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
> +   echo "ERROR: Patchwork instance and project are unset."
> +   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
> +   echo "(or pass it as an argument)."
> +   echo "Also either setup pw_instance or pass it as an argument."
> +   exit 1
> +fi
> +
>  source $(dirname $0)/series_db_lib.sh
>
>  function emit_series() {
> --
> 2.41.0
>
  
Aaron Conole Nov. 17, 2023, 7:28 p.m. UTC | #2
Michael Santana <msantana@redhat.com> writes:

> On Tue, Nov 7, 2023 at 3:32 PM Aaron Conole <aconole@redhat.com> wrote:
>>
>> In the future, we'll use this to add support for passing opts into some parts
>> of pw_mon.
>>
>> Signed-off-by: Aaron Conole <aconole@redhat.com>
> Acked-by: Michael Santana <msantana@redhat.com>

Thanks

>> ---
>>  pw_mon | 65 +++++++++++++++++++++++++++++++++++++++++++++-------------
>>  1 file changed, 51 insertions(+), 14 deletions(-)
>>
>> diff --git a/pw_mon b/pw_mon
>> index 28feb8b..da4b9a9 100755
>> --- a/pw_mon
>> +++ b/pw_mon
>> @@ -21,34 +21,71 @@
>>
>>  [ -f "${HOME}/.pwmon-rc" ] && source "${HOME}/.pwmon-rc"
>>
>> -if [ "$1" != "" ]; then
>> -    pw_project="$1"
>> -    shift
>> +if [ "$1" != ""  ]; then
>> +    if ! echo "$1" | grep -q -s -E ^-- ; then
> The missing quotes give me OCD, but I'll let it pass :)
>
> It is technically correct apparently. It worked when I tested it. I
> guess I am so used to using grep with quotes that I had never
> considered that there was a whole world where people use grep without
> quotes :P
>
>> +        pw_project="$1"
>> +        shift
>> +    fi
>>  fi
>>
>>  if [ "$1" != "" ]; then
>> -    pw_instance="$1"
>> -    shift
>> -fi
>> -
>> -if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
>> -   echo "ERROR: Patchwork instance and project are unset."
>> -   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
>> -   echo "(or pass it as an argument)."
>> -   echo "Also either setup pw_instance or pass it as an argument."
>> -   exit 1
>> +    if ! echo "$1" | grep -q -s -E ^-- ; then
>> +        pw_instance="$1"
>> +        shift
>> +    fi
>>  fi
>>
>>  userpw=""
>>
>>  if [ "$1" != "" ]; then
>> -    pw_credential="$1"
>> +    if ! echo "$1" | grep -q -s -E ^-- ; then
>> +        pw_credential="$1"
>> +        shift
>> +    fi
>>  fi
>>
>> +
>> +while [ "$1" != "" ]; do
>> +    if echo "$1" | grep -q -s -E ^--pw-project= ; then
>> +        pw_project=$(echo "$1" | sed s/^--pw-project=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
>> +        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
>> +        shift
>> +    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
>> +        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
>> +        shift
>> +    elif echo "$1" | grep -E ^--help >/dev/null 2>&1; then
>> +        echo "patchwork monitor script"
>> +        echo "$0: args"
>> +        echo "Required if not set in ~/.pwmon-rc file:"
>> +        echo "  proj|--pw-project=<proj>               Project name"
>> +        echo "  instance|--pw-instance=<inst url>      URL for pw"
>> +        echo ""
>> +        echo "Options:"
>> +        echo "    --pw-credentials=u:p         Sets user / password for web client"
>> +        echo "    --add-filter-recheck=filter  Adds a filter to flag that a recheck needs to be done"
>> +        echo ""
>> +        exit 0
>> +    else
>> +        echo "Unknown option: '$1'"
>> +        echo "Rerun with --help for details"
>> +        exit 1
>> +    fi
>> +done
>> +
>>  if [ "X$pw_credential" != "X" ]; then
>>     userpw="-u \"${pw_credential}\""
>>  fi
>>
>> +if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
>> +   echo "ERROR: Patchwork instance and project are unset."
>> +   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
>> +   echo "(or pass it as an argument)."
>> +   echo "Also either setup pw_instance or pass it as an argument."
>> +   exit 1
>> +fi
>> +
>>  source $(dirname $0)/series_db_lib.sh
>>
>>  function emit_series() {
>> --
>> 2.41.0
>>
  

Patch

diff --git a/pw_mon b/pw_mon
index 28feb8b..da4b9a9 100755
--- a/pw_mon
+++ b/pw_mon
@@ -21,34 +21,71 @@ 
 
 [ -f "${HOME}/.pwmon-rc" ] && source "${HOME}/.pwmon-rc"
 
-if [ "$1" != "" ]; then
-    pw_project="$1"
-    shift
+if [ "$1" != ""  ]; then
+    if ! echo "$1" | grep -q -s -E ^-- ; then
+        pw_project="$1"
+        shift
+    fi
 fi
 
 if [ "$1" != "" ]; then
-    pw_instance="$1"
-    shift
-fi
-
-if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
-   echo "ERROR: Patchwork instance and project are unset."
-   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
-   echo "(or pass it as an argument)."
-   echo "Also either setup pw_instance or pass it as an argument."
-   exit 1
+    if ! echo "$1" | grep -q -s -E ^-- ; then
+        pw_instance="$1"
+        shift
+    fi
 fi
 
 userpw=""
 
 if [ "$1" != "" ]; then
-    pw_credential="$1"
+    if ! echo "$1" | grep -q -s -E ^-- ; then
+        pw_credential="$1"
+        shift
+    fi
 fi
 
+
+while [ "$1" != "" ]; do
+    if echo "$1" | grep -q -s -E ^--pw-project= ; then
+        pw_project=$(echo "$1" | sed s/^--pw-project=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--pw-instance= ; then
+        pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
+        shift
+    elif echo "$1" | grep -q -s -E ^--pw-credentials= ; then
+        pw_credential=$(echo "$1" | sed s/^--pw-credentials=//)
+        shift
+    elif echo "$1" | grep -E ^--help >/dev/null 2>&1; then
+        echo "patchwork monitor script"
+        echo "$0: args"
+        echo "Required if not set in ~/.pwmon-rc file:"
+        echo "  proj|--pw-project=<proj>		Project name"
+        echo "  instance|--pw-instance=<inst url>	URL for pw"
+        echo ""
+        echo "Options:"
+        echo "    --pw-credentials=u:p		Sets user / password for web client"
+        echo "    --add-filter-recheck=filter	Adds a filter to flag that a recheck needs to be done"
+        echo ""
+        exit 0
+    else
+        echo "Unknown option: '$1'"
+        echo "Rerun with --help for details"
+        exit 1
+    fi
+done
+
 if [ "X$pw_credential" != "X" ]; then
    userpw="-u \"${pw_credential}\""
 fi
 
+if [ "X$pw_instance" == "X" -o "X$pw_project" == "X" ]; then
+   echo "ERROR: Patchwork instance and project are unset."
+   echo "Please setup ${HOME}/.pwmon-rc and set pw_project "
+   echo "(or pass it as an argument)."
+   echo "Also either setup pw_instance or pass it as an argument."
+   exit 1
+fi
+
 source $(dirname $0)/series_db_lib.sh
 
 function emit_series() {