[Libguestfs] [PATCH 3/5] p2v: Implement --short-options and --long-options in virt-p2v-make-* scripts.

Richard W.M. Jones rjones at redhat.com
Thu Aug 25 12:15:27 UTC 2016


---
 p2v/virt-p2v-make-disk.in      | 15 +++++++++++++--
 p2v/virt-p2v-make-kickstart.in | 24 +++++++++++++++++++-----
 p2v/virt-p2v-make-kiwi.in      | 24 +++++++++++++++++++-----
 3 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/p2v/virt-p2v-make-disk.in b/p2v/virt-p2v-make-disk.in
index eeaa3b7..c5b5463 100644
--- a/p2v/virt-p2v-make-disk.in
+++ b/p2v/virt-p2v-make-disk.in
@@ -36,9 +36,11 @@ else
 fi
 
 # Parse the command line arguments.
+shortopts=o:vV
+longopts=arch:,help,short-options,inject-ssh-identity:,install:,long-options,no-warn-if-partition,output:,verbose,version
 TEMP=`getopt \
-        -o o:vV \
-        --long arch:,help,inject-ssh-identity:,install:,no-warn-if-partition,output:,verbose,version \
+        -o "$shortopts" \
+        --long "$longopts" \
         -n $program -- "$@"`
 if [ $? != 0 ]; then
     echo "$program: problem parsing the command line arguments"
@@ -92,6 +94,15 @@ while true; do
         -V|--version)
             echo "$program $version"
             exit 0;;
+        --short-options)
+            echo -n "$shortopts" |
+                @SED@ -e 's/://g' -e 's/\(.\)/-\1\n/g'
+            exit 0;;
+        --long-options)
+            echo "$longopts" |
+                @SED@ -e 's/,/\n/g' -e 's/:$//mg' -e 's/\(.*\)/--\1/mg' |
+                grep -v -E -- "--(short|long)-options"
+            exit 0;;
         --)
             shift
             break;;
diff --git a/p2v/virt-p2v-make-kickstart.in b/p2v/virt-p2v-make-kickstart.in
index c57e212..85217d5 100644
--- a/p2v/virt-p2v-make-kickstart.in
+++ b/p2v/virt-p2v-make-kickstart.in
@@ -22,9 +22,12 @@ unset CDPATH
 program="virt-p2v-make-kickstart"
 version="@PACKAGE_VERSION@"
 
+# Parse the command line arguments.
+shortopts=o:vV
+longopts=help,inject-ssh-identity:,install:,long-options,output:,proxy:,short-options,verbose,version
 TEMP=`getopt \
-        -o o:vV \
-        --long help,inject-ssh-identity:,install:,output:,proxy:,verbose,version \
+        -o "$shortopts" \
+        --long "$longopts" \
         -n $program -- "$@"`
 if [ $? != 0 ]; then
     echo "$program: problem parsing the command line arguments"
@@ -68,11 +71,22 @@ while true; do
             set +x
             verbose=1
             shift;;
-        -V|--version)
-            echo "$program $version"
-            exit 0;;
+
+        # help etc.
         --help)
             usage 0;;
+        -V|--version)
+            echo "$program $version"
+            exit 0;;
+        --short-options)
+            echo -n "$shortopts" |
+                @SED@ -e 's/://g' -e 's/\(.\)/-\1\n/g'
+            exit 0;;
+        --long-options)
+            echo "$longopts" |
+                @SED@ -e 's/,/\n/g' -e 's/:$//mg' -e 's/\(.*\)/--\1/mg' |
+                grep -v -E -- "--(short|long)-options"
+            exit 0;;
         --)
             shift
             break;;
diff --git a/p2v/virt-p2v-make-kiwi.in b/p2v/virt-p2v-make-kiwi.in
index e493bd4..dc7fce4 100644
--- a/p2v/virt-p2v-make-kiwi.in
+++ b/p2v/virt-p2v-make-kiwi.in
@@ -22,9 +22,12 @@ unset CDPATH
 program="virt-p2v-make-kiwi"
 version="@PACKAGE_VERSION@"
 
+# Parse the command line arguments.
+shortopts=o:V
+longopts=help,inject-ssh-identity:,long-options,output:,short-options,version
 TEMP=`getopt \
-        -o o:V \
-        --long help,inject-ssh-identity:,output:,version \
+        -o "$shortopts" \
+        --long "$longopts" \
         -n $program -- "$@"`
 if [ $? != 0 ]; then
     echo "$program: problem parsing the command line arguments"
@@ -52,11 +55,22 @@ while true; do
         -o|--output)
             output="$2"
             shift 2;;
-        -V|--version)
-            echo "$program $version"
-            exit 0;;
+
+        # help etc.
         --help)
             usage 0;;
+        -V|--version)
+            echo "$program $version"
+            exit 0;;
+        --short-options)
+            echo -n "$shortopts" |
+                @SED@ -e 's/://g' -e 's/\(.\)/-\1\n/g'
+            exit 0;;
+        --long-options)
+            echo "$longopts" |
+                @SED@ -e 's/,/\n/g' -e 's/:$//mg' -e 's/\(.*\)/--\1/mg' |
+                grep -v -E -- "--(short|long)-options"
+            exit 0;;
         --)
             shift
             break;;
-- 
2.7.4




More information about the Libguestfs mailing list