Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 0/5] bash completion: Add missing bash completion scripts (RHBZ#1367738).
This implements most of RHBZ#1367738. I didn't bother with virt-v2v-copy-to-local and virt-win-reg, but all the other tools now have full bash completion. Rich.
Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 1/5] fish: Move display_*_options functions to a separate file.
By moving these two functions out of the common options parsing code, it means we don't need to depend on all the other machinery of options parsing, such as the global variables ("verbose"), libconfig, etc. --- align/Makefile.am | 2 ++ align/scan.c | 1 + cat/Makefile.am | 2 ++ cat/cat.c | 1 + cat/filesystems.c | 1 + cat/log.c | 1 + cat/ls.c | 1 + df/Makefile.am | 2 ++ df/main.c | 1 + diff/Makefile.am | 2 ++ diff/diff.c | 1 + edit/Makefile.am | 2 ++ edit/edit.c | 1 + fish/Makefile.am | 2 ++ fish/display-options.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ fish/display-options.h | 25 +++++++++++++++++++ fish/fish.c | 1 + fish/options.c | 31 ------------------------ fish/options.h | 3 --- format/Makefile.am | 2 ++ format/format.c | 1 + fuse/Makefile.am | 2 ++ fuse/guestmount.c | 1 + inspector/Makefile.am | 2 ++ inspector/inspector.c | 1 + make-fs/Makefile.am | 4 ++- make-fs/make-fs.c | 1 + rescue/Makefile.am | 2 ++ rescue/rescue.c | 1 + 29 files changed, 128 insertions(+), 35 deletions(-) create mode 100644 fish/display-options.c create mode 100644 fish/display-options.h diff --git a/align/Makefile.am b/align/Makefile.am index edae4b9..2b4dee4 100644 --- a/align/Makefile.am +++ b/align/Makefile.am @@ -37,6 +37,8 @@ SHARED_SOURCE_FILES = \ ../df/parallel.c \ ../df/parallel.h \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/align/scan.c b/align/scan.c index 9575eda..4171f8c 100644 --- a/align/scan.c +++ b/align/scan.c @@ -40,6 +40,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "parallel.h" #include "domains.h" diff --git a/cat/Makefile.am b/cat/Makefile.am index a2ca16f..266e1c5 100644 --- a/cat/Makefile.am +++ b/cat/Makefile.am @@ -41,6 +41,8 @@ CLEANFILES = \ bin_PROGRAMS = virt-cat virt-filesystems virt-log virt-ls SHARED_SOURCE_FILES = \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/cat/cat.c b/cat/cat.c index 9039f7f..9c8d1a9 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -32,6 +32,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "windows.h" /* Currently open libguestfs handle. */ diff --git a/cat/filesystems.c b/cat/filesystems.c index ab24f2d..6c8ce01 100644 --- a/cat/filesystems.c +++ b/cat/filesystems.c @@ -36,6 +36,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* These globals are shared with options.c. */ guestfs_h *g; diff --git a/cat/log.c b/cat/log.c index bacd8b6..0968ef5 100644 --- a/cat/log.c +++ b/cat/log.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* Currently open libguestfs handle. */ guestfs_h *g; diff --git a/cat/ls.c b/cat/ls.c index 282996f..8903159 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "visit.h" /* Currently open libguestfs handle. */ diff --git a/df/Makefile.am b/df/Makefile.am index 74a0391..cbfb160 100644 --- a/df/Makefile.am +++ b/df/Makefile.am @@ -32,6 +32,8 @@ bin_PROGRAMS = virt-df SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/df/main.c b/df/main.c index f1d874a..3f9296f 100644 --- a/df/main.c +++ b/df/main.c @@ -38,6 +38,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "domains.h" #include "parallel.h" #include "virt-df.h" diff --git a/diff/Makefile.am b/diff/Makefile.am index 9421771..87d18c5 100644 --- a/diff/Makefile.am +++ b/diff/Makefile.am @@ -31,6 +31,8 @@ bin_PROGRAMS = virt-diff SHARED_SOURCE_FILES = \ ../cat/visit.h \ ../cat/visit.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/diff/diff.c b/diff/diff.c index 2ac71eb..e0eea57 100644 --- a/diff/diff.c +++ b/diff/diff.c @@ -39,6 +39,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "visit.h" /* Internal tree structure built for each guest. */ diff --git a/edit/Makefile.am b/edit/Makefile.am index b4dd8a1..709bfca 100644 --- a/edit/Makefile.am +++ b/edit/Makefile.am @@ -30,6 +30,8 @@ bin_PROGRAMS = virt-edit SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/file-edit.h \ ../fish/file-edit.c \ diff --git a/edit/edit.c b/edit/edit.c index 8a0c00c..6f3e388 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -37,6 +37,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" #include "windows.h" #include "file-edit.h" diff --git a/fish/Makefile.am b/fish/Makefile.am index aa0ef74..1e3c1d9 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -72,6 +72,8 @@ EXTRA_DIST = \ # files must not include other guestfish files. SHARED_SOURCE_FILES = \ config.c \ + display-options.h \ + display-options.c \ domain.c \ inspect.c \ keys.c \ diff --git a/fish/display-options.c b/fish/display-options.c new file mode 100644 index 0000000..18f7700 --- /dev/null +++ b/fish/display-options.c @@ -0,0 +1,66 @@ +/* libguestfs - implement --short-options and --long-options + * Copyright (C) 2010-2016 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/** + * This file contains common code used to implement I<--short-options> + * and I<--long-options> in C virt tools. (The equivalent for + * OCaml virt tools is implemented by F<mllib/getopt.ml>). + * + * These "hidden" options are used to implement bash tab completion. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#include "guestfs-internal-all.h" +#include "display-options.h" + +/** + * Implements the internal C<tool I<--short-options>> flag, which just + * lists out the short options available. Used by bash completion. + */ +void +display_short_options (const char *format) +{ + while (*format) { + if (*format != ':') + printf ("-%c\n", *format); + ++format; + } + exit (EXIT_SUCCESS); +} + +/** + * Implements the internal C<tool I<--long-options>> flag, which just + * lists out the long options available. Used by bash completion. + */ +void +display_long_options (const struct option *long_options) +{ + while (long_options->name) { + if (STRNEQ (long_options->name, "long-options") && + STRNEQ (long_options->name, "short-options")) + printf ("--%s\n", long_options->name); + long_options++; + } + exit (EXIT_SUCCESS); +} diff --git a/fish/display-options.h b/fish/display-options.h new file mode 100644 index 0000000..f295d6d --- /dev/null +++ b/fish/display-options.h @@ -0,0 +1,25 @@ +/* libguestfs - implement --short-options and --long-options + * Copyright (C) 2010-2016 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef DISPLAY_OPTIONS_H +#define DISPLAY_OPTIONS_H + +extern void display_short_options (const char *) __attribute__((noreturn)); +extern void display_long_options (const struct option *) __attribute__((noreturn)); + +#endif /* DISPLAY_OPTIONS_H */ diff --git a/fish/fish.c b/fish/fish.c index 302b52f..f20fbc0 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -48,6 +48,7 @@ #include "fish.h" #include "options.h" +#include "display-options.h" #include "progress.h" #include "c-ctype.h" diff --git a/fish/options.c b/fish/options.c index 653be24..96db212 100644 --- a/fish/options.c +++ b/fish/options.c @@ -367,34 +367,3 @@ free_mps (struct mp *mp) free (mp); } - -/** - * Implements the internal C<tool I<--short-options>> flag, which just - * lists out the short options available. Used by bash completion. - */ -void -display_short_options (const char *format) -{ - while (*format) { - if (*format != ':') - printf ("-%c\n", *format); - ++format; - } - exit (EXIT_SUCCESS); -} - -/** - * Implements the internal C<tool I<--long-options>> flag, which just - * lists out the long options available. Used by bash completion. - */ -void -display_long_options (const struct option *long_options) -{ - while (long_options->name) { - if (STRNEQ (long_options->name, "long-options") && - STRNEQ (long_options->name, "short-options")) - printf ("--%s\n", long_options->name); - long_options++; - } - exit (EXIT_SUCCESS); -} diff --git a/fish/options.h b/fish/options.h index bbe38aa..89afe9e 100644 --- a/fish/options.h +++ b/fish/options.h @@ -22,7 +22,6 @@ #include <config.h> #include <stdbool.h> -#include <getopt.h> #include "guestfs-internal-frontend.h" @@ -140,8 +139,6 @@ extern char add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive); extern void mount_mps (struct mp *mp); extern void free_drives (struct drv *drv); extern void free_mps (struct mp *mp); -extern void display_short_options (const char *) __attribute__((noreturn)); -extern void display_long_options (const struct option *) __attribute__((noreturn)); #define OPTION_a \ do { \ diff --git a/format/Makefile.am b/format/Makefile.am index 9951ba1..d955e35 100644 --- a/format/Makefile.am +++ b/format/Makefile.am @@ -30,6 +30,8 @@ bin_PROGRAMS = virt-format SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/format/format.c b/format/format.c index 5933aeb..0ce4ac4 100644 --- a/format/format.c +++ b/format/format.c @@ -33,6 +33,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* These globals are shared with options.c. */ guestfs_h *g; diff --git a/fuse/Makefile.am b/fuse/Makefile.am index da0e636..c70f649 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -40,6 +40,8 @@ bin_PROGRAMS = \ # between guestfish and guestmount. SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/fuse/guestmount.c b/fuse/guestmount.c index dccc7ba..9da96d2 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -41,6 +41,7 @@ #include "ignore-value.h" #include "options.h" +#include "display-options.h" static int write_pipe_fd (int fd); static int write_pid_file (const char *pid_file, pid_t pid); diff --git a/inspector/Makefile.am b/inspector/Makefile.am index cdaedf3..af596bf 100644 --- a/inspector/Makefile.am +++ b/inspector/Makefile.am @@ -58,6 +58,8 @@ bin_PROGRAMS = virt-inspector SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/inspector/inspector.c b/inspector/inspector.c index 4c027df..9a8fa4d 100644 --- a/inspector/inspector.c +++ b/inspector/inspector.c @@ -39,6 +39,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" /* Currently open libguestfs handle. */ guestfs_h *g; diff --git a/make-fs/Makefile.am b/make-fs/Makefile.am index 2bec12f..ea723af 100644 --- a/make-fs/Makefile.am +++ b/make-fs/Makefile.am @@ -29,9 +29,11 @@ CLEANFILES = \ bin_PROGRAMS = virt-make-fs SHARED_SOURCE_FILES = \ + ../fish/display-options.h \ + ../fish/display-options.c \ + ../fish/domain.c \ ../fish/options.h \ ../fish/options.c \ - ../fish/domain.c \ ../fish/uri.c virt_make_fs_SOURCES = \ diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c index 2f91370..ade2e60 100644 --- a/make-fs/make-fs.c +++ b/make-fs/make-fs.c @@ -40,6 +40,7 @@ #include "xstrtol.h" #include "options.h" +#include "display-options.h" guestfs_h *g; const char *libvirt_uri; diff --git a/rescue/Makefile.am b/rescue/Makefile.am index 1568730..58564dc 100644 --- a/rescue/Makefile.am +++ b/rescue/Makefile.am @@ -31,6 +31,8 @@ bin_PROGRAMS = virt-rescue SHARED_SOURCE_FILES = \ ../fish/config.c \ + ../fish/display-options.h \ + ../fish/display-options.c \ ../fish/domain.c \ ../fish/inspect.c \ ../fish/keys.c \ diff --git a/rescue/rescue.c b/rescue/rescue.c index 37b82f6..0f83f04 100644 --- a/rescue/rescue.c +++ b/rescue/rescue.c @@ -35,6 +35,7 @@ #include "guestfs.h" #include "options.h" +#include "display-options.h" static void add_scratch_disks (int n, struct drv **drvs); static void do_suggestion (struct drv *drvs); -- 2.7.4
Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 2/5] fuse: Implement --long-options and --short-options in guestunmount.
--- fuse/Makefile.am | 2 ++ fuse/guestunmount.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fuse/Makefile.am b/fuse/Makefile.am index c70f649..2848685 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -82,11 +82,13 @@ guestmount_LDADD = \ # guestunmount guestunmount_SOURCES = \ + ../fish/display-options.c \ guestunmount.c guestunmount_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/src -I$(top_builddir)/src \ + -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib guestunmount_CFLAGS = \ diff --git a/fuse/guestunmount.c b/fuse/guestunmount.c index c686f40..efd342f 100644 --- a/fuse/guestunmount.c +++ b/fuse/guestunmount.c @@ -39,6 +39,8 @@ #include "ignore-value.h" +#include "display-options.h" + static int do_fusermount (const char *mountpoint, char **error_rtn); static void do_fuser (const char *mountpoint); -- 2.7.4
Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 3/5] p2v: Implement --short-options and --long-options in virt-p2v-make-* scripts.
--- 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
Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 4/5] bash completions: Add tip for how to run bash completions locally to README.
--- bash/README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bash/README b/bash/README index db7d7bb..314bfd0 100644 --- a/bash/README +++ b/bash/README @@ -1,3 +1,6 @@ This directory contains the scripts for tab-completing commands in bash. Note these new-style demand-loaded scripts require 'bash-completion' >= 1.99. + +Tip: To test the bash completions without having to install them, +simply start a new shell and 'source ./virt-foo'. -- 2.7.4
Richard W.M. Jones
2016-Aug-25 12:15 UTC
[Libguestfs] [PATCH 5/5] bash completion: Add missing bash completion scripts (RHBZ#1367738).
Add new scripts for: - guestunmount - virt-copy-in - virt-copy-out - virt-customize - virt-dib - virt-diff - virt-get-kernel - virt-p2v-make-disk - virt-p2v-make-kickstart - virt-p2v-make-kiwi - virt-tar-in - virt-tar-out Also combine the separate virt-resize script into the general script virt-alignment-scan. There wasn't really any reason to have separate scripts. --- .gitignore | 13 +++++++ bash/Makefile.am | 38 +++++++++++++++---- bash/guestfish | 9 ++++- bash/virt-alignment-scan | 97 +++++++++++++++++++++++++++++++++++++++++++++--- bash/virt-resize | 78 -------------------------------------- fuse/guestunmount.c | 8 +++- 6 files changed, 149 insertions(+), 94 deletions(-) delete mode 100644 bash/virt-resize diff --git a/.gitignore b/.gitignore index 6f6a0b8..711782c 100644 --- a/.gitignore +++ b/.gitignore @@ -47,17 +47,30 @@ Makefile.in /appliance/stamp-supermin /appliance/supermin.d /autom4te.cache +/bash/guestunmount /bash/virt-builder /bash/virt-cat +/bash/virt-copy-in +/bash/virt-copy-out +/bash/virt-customize /bash/virt-df +/bash/virt-dib +/bash/virt-diff /bash/virt-edit /bash/virt-filesystems /bash/virt-format +/bash/virt-get-kernel /bash/virt-inspector /bash/virt-log /bash/virt-ls +/bash/virt-p2v-make-disk +/bash/virt-p2v-make-kickstart +/bash/virt-p2v-make-kiwi +/bash/virt-resize /bash/virt-sysprep /bash/virt-sparsify +/bash/virt-tar-in +/bash/virt-tar-out /build-aux/.gitignore /build-aux/ar-lib /build-aux/compile diff --git a/bash/Makefile.am b/bash/Makefile.am index 2c8e722..c95c99f 100644 --- a/bash/Makefile.am +++ b/bash/Makefile.am @@ -1,5 +1,5 @@ # libguestfs -# Copyright (C) 2013 Red Hat Inc. +# Copyright (C) 2013-2016 Red Hat Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,21 +22,34 @@ scripts = \ guestmount \ virt-alignment-scan \ virt-rescue \ - virt-resize \ virt-v2v +# Some of the scripts are simply symbolic links. symlinks = \ + guestunmount \ virt-builder \ virt-cat \ + virt-copy-in \ + virt-copy-out \ + virt-customize \ + virt-diff \ virt-df \ + virt-dib \ virt-edit \ virt-filesystems \ virt-format \ + virt-get-kernel \ virt-inspector \ virt-log \ virt-ls \ + virt-p2v-make-disk \ + virt-p2v-make-kickstart \ + virt-p2v-make-kiwi \ + virt-resize \ virt-sparsify \ - virt-sysprep + virt-sysprep \ + virt-tar-in \ + virt-tar-out # Note: Don't distribute the symbolic links, only the real files. EXTRA_DIST = \ @@ -46,15 +59,24 @@ EXTRA_DIST = \ CLEANFILES = \ $(symlinks) -# Some of the scripts are simply symbolic links. -virt-cat virt-df virt-edit virt-filesystems virt-format virt-inspector \ -virt-log virt-ls virt-sysprep: +# Any tool that has --short-options and --long-options is handled by +# this common script. However this script cannot deal with commands +# that use --ro/--rw (eg. virt-rescue), nor commands that have lots of +# exceptions (eg. guestfish). Those tools have to be handled +# individually. +guestunmount \ +virt-builder virt-cat virt-customize virt-df virt-dib virt-diff \ +virt-edit virt-filesystems virt-format virt-get-kernel virt-inspector \ +virt-log virt-ls \ +virt-p2v-make-disk virt-p2v-make-kickstart virt-p2v-make-kiwi \ +virt-resize virt-sparsify virt-sysprep: rm -f $@ $(LN_S) virt-alignment-scan $@ -virt-builder virt-sparsify: +# guestfish is handled specially. +virt-copy-in virt-copy-out virt-tar-in virt-tar-out: rm -f $@ - $(LN_S) virt-resize $@ + $(LN_S) guestfish $@ if HAVE_BASH_COMPLETION diff --git a/bash/guestfish b/bash/guestfish index 0f12690..dd0984a 100644 --- a/bash/guestfish +++ b/bash/guestfish @@ -73,5 +73,12 @@ _guestfish () COMPREPLY=( $(compgen -W "$cmds" -- "$cur") ) return ;; esac -} && +} + complete -o default -F _guestfish guestfish + +# virt-copy-in etc are literally the same as guestfish +complete -o default -F _guestfish virt-copy-in +complete -o default -F _guestfish virt-copy-out +complete -o default -F _guestfish virt-tar-in +complete -o default -F _guestfish virt-tar-out diff --git a/bash/virt-alignment-scan b/bash/virt-alignment-scan index edcc093..055bad1 100644 --- a/bash/virt-alignment-scan +++ b/bash/virt-alignment-scan @@ -36,10 +36,29 @@ _guestfs_virttools () _init_completion -s || return case "$prev" in + --align-first) + COMPREPLY=( $( compgen -W "never always auto" -- "$cur") ) + return ;; + --check-tmpdir) + COMPREPLY=( $( compgen -W "ignore i continue cont c warn warning w fail f error" -- "$cur") ) + return ;; -d|--domain) doms=$(_guestfs_virsh_list "$flag_ro") COMPREPLY=( $(compgen -W "$doms" -- "$cur") ) return ;; + -D) + doms=$(_guestfs_virsh_list "$flag_ro") + COMPREPLY=( $(compgen -W "$doms" -- "$cur") ) + return ;; + --list-format) + COMPREPLY=( $( compgen -W "short long json" -- "$cur") ) + return ;; + --password-crypto) + COMPREPLY=( $( compgen -W "md5 sha256 sha512" -- "$cur") ) + return ;; + --unknown-filesystems) + COMPREPLY=( $( compgen -W "ignore warn error" -- "$cur") ) + return ;; esac case "$cur" in @@ -60,24 +79,54 @@ _guestfs_virttools () esac } +_guestunmount () +{ + _guestfs_virttools "guestunmount" 1 +} && +complete -o default -F _guestunmount guestunmount + _virt_alignment_scan () { _guestfs_virttools "virt-alignment-scan" 1 } && complete -o default -F _virt_alignment_scan virt-alignment-scan +_virt_builder () +{ + _guestfs_virttools "virt-builder" 0 +} && +complete -o default -F _virt_builder virt-builder + _virt_cat () { _guestfs_virttools "virt-cat" 1 } && complete -o default -F _virt_cat virt-cat +_virt_customize () +{ + _guestfs_virttools "virt-customize" 0 +} && +complete -o default -F _virt_customize virt-customize + +_virt_dib () +{ + _guestfs_virttools "virt-dib" 0 +} && +complete -o default -F _virt_dib virt-dib + _virt_df () { _guestfs_virttools "virt-df" 1 } && complete -o default -F _virt_df virt-df +_virt_diff () +{ + _guestfs_virttools "virt-diff" 1 +} && +complete -o default -F _virt_diff virt-diff + _virt_edit () { _guestfs_virttools "virt-edit" 0 @@ -96,26 +145,62 @@ _virt_format () } && complete -o default -F _virt_format virt-format +_virt_get_kernel () +{ + _guestfs_virttools "virt-get-kernel" 1 +} && +complete -o default -F _virt_get_kernel virt-get-kernel + _virt_inspector () { _guestfs_virttools "virt-inspector" 1 } && complete -o default -F _virt_inspector virt-inspector +_virt_log () +{ + _guestfs_virttools "virt-log" 1 +} && +complete -o default -F _virt_log virt-log + _virt_ls () { _guestfs_virttools "virt-ls" 1 } && complete -o default -F _virt_ls virt-ls +_virt_p2v_make_disk () +{ + _guestfs_virttools "virt-p2v-make-disk" 1 +} && +complete -o default -F _virt_p2v_make_disk virt-p2v-make-disk + +_virt_p2v_make_kickstart () +{ + _guestfs_virttools "virt-p2v-make-kickstart" 1 +} && +complete -o default -F _virt_p2v_make_kickstart virt-p2v-make-kickstart + +_virt_p2v_make_kiwi () +{ + _guestfs_virttools "virt-p2v-make-kiwi" 1 +} && +complete -o default -F _virt_p2v_make_kiwi virt-p2v-make-kiwi + +_virt_resize () +{ + _guestfs_virttools "virt-resize" 0 +} && +complete -o default -F _virt_resize virt-resize + +_virt_sparsify () +{ + _guestfs_virttools "virt-sparsify" 0 +} && +complete -o default -F _virt_sparsify virt-sparsify + _virt_sysprep () { _guestfs_virttools "virt-sysprep" 0 } && complete -o default -F _virt_sysprep virt-sysprep - -_virt_log () -{ - _guestfs_virttools "virt-log" 1 -} && -complete -o default -F _virt_log virt-log diff --git a/bash/virt-resize b/bash/virt-resize deleted file mode 100644 index bdd392e..0000000 --- a/bash/virt-resize +++ /dev/null @@ -1,78 +0,0 @@ -# virt-resize, virt-builder, virt-sparsify bash completion script -# -*- shell-script -*- -# Copyright (C) 2010-2016 Red Hat Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -_guestfs_options_only () -{ - local cur prev words cword split - local shortopts longopts tool="$1" - - _init_completion -s || return - - case "$prev" in - --align-first) - COMPREPLY=( $( compgen -W "never always auto" -- "$cur") ) - return ;; - --check-tmpdir) - COMPREPLY=( $( compgen -W "ignore i continue cont c warn warning w fail f error" -- "$cur") ) - return ;; - --list-format) - COMPREPLY=( $( compgen -W "short long json" -- "$cur") ) - return ;; - --password-crypto) - COMPREPLY=( $( compgen -W "md5 sha256 sha512" -- "$cur") ) - return ;; - --unknown-filesystems) - COMPREPLY=( $( compgen -W "ignore warn error" -- "$cur") ) - return ;; - esac - - case "$cur" in - --*) - # --options - longopts="$($tool --long-options)" - COMPREPLY=( $(compgen -W "$longopts" -- "$cur") ) - return ;; - -*) - # -o and --options - shortopts="$($tool --short-options)" - longopts="$($tool --long-options)" - COMPREPLY=( $(compgen -W "$shortopts $longopts" -- "$cur") ) - return ;; - *) - COMPREPLY=( $(compgen "$cur") ) - return ;; - esac -} - -_virt_builder () -{ - _guestfs_options_only "virt-builder" -} && -complete -o default -F _virt_builder virt-builder - -_virt_resize () -{ - _guestfs_options_only "virt-resize" -} && -complete -o default -F _virt_resize virt-resize - -_virt_sparsify () -{ - _guestfs_options_only "virt-sparsify" -} && -complete -o default -F _virt_sparsify virt-sparsify diff --git a/fuse/guestunmount.c b/fuse/guestunmount.c index efd342f..fe86706 100644 --- a/fuse/guestunmount.c +++ b/fuse/guestunmount.c @@ -83,8 +83,10 @@ main (int argc, char *argv[]) { "fd", 1, 0, 0 }, { "help", 0, 0, HELP_OPTION }, { "quiet", 0, 0, 'q' }, + { "long-options", 0, 0, 0 }, { "no-retry", 0, 0, 0 }, { "retry", 1, 0, 0 }, + { "short-options", 0, 0, 0 }, { "verbose", 0, 0, 'v' }, { "version", 0, 0, 'V' }, { 0, 0, 0, 0 } @@ -108,7 +110,11 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ - if (STREQ (long_options[option_index].name, "fd")) { + if (STREQ (long_options[option_index].name, "long-options")) + display_long_options (long_options); + else if (STREQ (long_options[option_index].name, "short-options")) + display_short_options (options); + else if (STREQ (long_options[option_index].name, "fd")) { if (sscanf (optarg, "%d", &fd) != 1 || fd < 0) error (EXIT_FAILURE, 0, _("cannot parse fd option '%s'"), optarg); } else if (STREQ (long_options[option_index].name, "no-retry")) { -- 2.7.4
Pino Toscano
2016-Aug-25 12:48 UTC
Re: [Libguestfs] [PATCH 5/5] bash completion: Add missing bash completion scripts (RHBZ#1367738).
On Thursday, 25 August 2016 13:15:29 CEST Richard W.M. Jones wrote:> Add new scripts for: > > - guestunmount > - virt-copy-in > - virt-copy-out > - virt-customize > - virt-dib > - virt-diff > - virt-get-kernel > - virt-p2v-make-disk > - virt-p2v-make-kickstart > - virt-p2v-make-kiwi > - virt-tar-in > - virt-tar-out > > Also combine the separate virt-resize script into the general script > virt-alignment-scan. There wasn't really any reason to have separate > scripts. > ---I guess ...> diff --git a/fuse/guestunmount.c b/fuse/guestunmount.c > index efd342f..fe86706 100644 > --- a/fuse/guestunmount.c > +++ b/fuse/guestunmount.c > @@ -83,8 +83,10 @@ main (int argc, char *argv[]) > { "fd", 1, 0, 0 }, > { "help", 0, 0, HELP_OPTION }, > { "quiet", 0, 0, 'q' }, > + { "long-options", 0, 0, 0 }, > { "no-retry", 0, 0, 0 }, > { "retry", 1, 0, 0 }, > + { "short-options", 0, 0, 0 }, > { "verbose", 0, 0, 'v' }, > { "version", 0, 0, 'V' }, > { 0, 0, 0, 0 } > @@ -108,7 +110,11 @@ main (int argc, char *argv[]) > > switch (c) { > case 0: /* options which are long only */ > - if (STREQ (long_options[option_index].name, "fd")) { > + if (STREQ (long_options[option_index].name, "long-options")) > + display_long_options (long_options); > + else if (STREQ (long_options[option_index].name, "short-options")) > + display_short_options (options); > + else if (STREQ (long_options[option_index].name, "fd")) { > if (sscanf (optarg, "%d", &fd) != 1 || fd < 0) > error (EXIT_FAILURE, 0, _("cannot parse fd option '%s'"), optarg); > } else if (STREQ (long_options[option_index].name, "no-retry")) { >... this should be part of patch #2, shouldn't it? Thanks, -- Pino Toscano
Pino Toscano
2016-Aug-25 12:51 UTC
Re: [Libguestfs] [PATCH 0/5] bash completion: Add missing bash completion scripts (RHBZ#1367738).
On Thursday, 25 August 2016 13:15:24 CEST Richard W.M. Jones wrote:> This implements most of RHBZ#1367738. I didn't bother > with virt-v2v-copy-to-local and virt-win-reg, but all the > other tools now have full bash completion.Mostly LGTM -- only a commit-related note left. Thanks, -- Pino Toscano
Seemingly Similar Threads
- [PATCH] bash: Implement tab completion for virt-win-reg (RHBZ#1367738).
- [PATCH 0/5] bash completion: Add missing bash completion scripts (RHBZ#1367738).
- [PATCH] bash: Add a bash completion script for virt-v2v-copy-to-local (RHBZ#1367738).
- [p2v PATCH] Add bash completion scripts
- [PATCH] tools: implement --short-options