diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2010-09-18 09:38:05 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2010-09-18 09:38:05 +0100 |
commit | 0003ea2c3dbaa7e22f4f616539136821d80694b8 (patch) | |
tree | 1a5bcededb436fb9f1a0e8e046599fdd0d5ae7f1 /fish | |
parent | 585fceb3350c17a3d6ed7f2daffd5e2b3e5fc3e1 (diff) | |
download | libguestfs-0003ea2c3dbaa7e22f4f616539136821d80694b8.tar.gz libguestfs-0003ea2c3dbaa7e22f4f616539136821d80694b8.tar.xz libguestfs-0003ea2c3dbaa7e22f4f616539136821d80694b8.zip |
generator: Generate guestfish-only commands.
The guestfish-only commands such as 'alloc' and 'edit' are
now generated from one place in the generator instead of being
spread around ad-hoc in the C code.
Diffstat (limited to 'fish')
-rw-r--r-- | fish/Makefile.am | 8 | ||||
-rw-r--r-- | fish/alloc.c | 4 | ||||
-rw-r--r-- | fish/copy.c | 4 | ||||
-rw-r--r-- | fish/echo.c | 2 | ||||
-rw-r--r-- | fish/edit.c | 2 | ||||
-rw-r--r-- | fish/fish.c | 210 | ||||
-rw-r--r-- | fish/fish.h | 40 | ||||
-rw-r--r-- | fish/glob.c | 2 | ||||
-rw-r--r-- | fish/guestfish.pod | 139 | ||||
-rw-r--r-- | fish/lcd.c | 2 | ||||
-rw-r--r-- | fish/man.c | 2 | ||||
-rw-r--r-- | fish/more.c | 2 | ||||
-rw-r--r-- | fish/reopen.c | 2 | ||||
-rw-r--r-- | fish/supported.c | 2 | ||||
-rw-r--r-- | fish/time.c | 2 |
15 files changed, 35 insertions, 388 deletions
diff --git a/fish/Makefile.am b/fish/Makefile.am index 906d362f..4d17aa1b 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -23,6 +23,7 @@ generator_built = \ cmds.c \ completion.c \ guestfish-actions.pod \ + guestfish-commands.pod \ prepopts.h \ prepopts.c @@ -109,14 +110,15 @@ guestfish.static$(EXEEXT): $(guestfish_OBJECTS) $(guestfish_DEPENDENCIES) $(guestfish_LINK) $(guestfish_OBJECTS) -static $(guestfish_LDADD) $(guestfish_LIBS) -ltinfo -lpcre -lhivex -lmagic -lz -lm # Manual page. -# guestfish-actions.pod is autogenerated. There is no include -# mechanism for POD, so we have to do it by hand. +# guestfish-actions.pod and guestfish-commands.pod are autogenerated. +# There is no include mechanism for POD, so we have to do it by hand. man_MANS = guestfish.1 -guestfish.1: guestfish.pod guestfish-actions.pod +guestfish.1: guestfish.pod guestfish-actions.pod guestfish-commands.pod sed \ -e '/@ACTIONS@/rguestfish-actions.pod' -e 's/@ACTIONS@//' \ + -e '/@FISH_COMMANDS@/rguestfish-commands.pod' -e 's/@FISH_COMMANDS@//' \ < $< | \ $(POD2MAN) \ --section 1 \ diff --git a/fish/alloc.c b/fish/alloc.c index 29d9845b..0470d202 100644 --- a/fish/alloc.c +++ b/fish/alloc.c @@ -31,7 +31,7 @@ #include "fish.h" int -do_alloc (const char *cmd, int argc, char *argv[]) +run_alloc (const char *cmd, int argc, char *argv[]) { if (argc != 2) { fprintf (stderr, _("use 'alloc file size' to create an image\n")); @@ -45,7 +45,7 @@ do_alloc (const char *cmd, int argc, char *argv[]) } int -do_sparse (const char *cmd, int argc, char *argv[]) +run_sparse (const char *cmd, int argc, char *argv[]) { if (argc != 2) { fprintf (stderr, _("use 'sparse file size' to create a sparse image\n")); diff --git a/fish/copy.c b/fish/copy.c index a7274f35..bb6334c4 100644 --- a/fish/copy.c +++ b/fish/copy.c @@ -33,7 +33,7 @@ static int make_tar_output (const char *local, const char *basename); static int split_path (char *buf, size_t buf_size, const char *path, const char **dirname, const char **basename); int -do_copy_in (const char *cmd, int argc, char *argv[]) +run_copy_in (const char *cmd, int argc, char *argv[]) { if (argc < 2) { fprintf (stderr, @@ -176,7 +176,7 @@ tar_create (const char *dir, const char *path) } int -do_copy_out (const char *cmd, int argc, char *argv[]) +run_copy_out (const char *cmd, int argc, char *argv[]) { if (argc < 2) { fprintf (stderr, diff --git a/fish/echo.c b/fish/echo.c index 33992d4f..783c0f69 100644 --- a/fish/echo.c +++ b/fish/echo.c @@ -25,7 +25,7 @@ #include "fish.h" int -do_echo (const char *cmd, int argc, char *argv[]) +run_echo (const char *cmd, int argc, char *argv[]) { int i; diff --git a/fish/edit.c b/fish/edit.c index 10950f93..4c06e86e 100644 --- a/fish/edit.c +++ b/fish/edit.c @@ -32,7 +32,7 @@ /* guestfish edit command, suggested by Ján Ondrej, implemented by RWMJ */ int -do_edit (const char *cmd, int argc, char *argv[]) +run_edit (const char *cmd, int argc, char *argv[]) { char filename[] = "/tmp/guestfishXXXXXX"; char buf[256]; diff --git a/fish/fish.c b/fish/fish.c index 43b7eee2..88518313 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1070,39 +1070,6 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) quit = 1; r = 0; } - else if (STRCASEEQ (cmd, "alloc") || - STRCASEEQ (cmd, "allocate")) - r = do_alloc (cmd, argc, argv); - else if (STRCASEEQ (cmd, "copy-in") || - STRCASEEQ (cmd, "copy_in")) - r = do_copy_in (cmd, argc, argv); - else if (STRCASEEQ (cmd, "copy-out") || - STRCASEEQ (cmd, "copy_out")) - r = do_copy_out (cmd, argc, argv); - else if (STRCASEEQ (cmd, "echo")) - r = do_echo (cmd, argc, argv); - else if (STRCASEEQ (cmd, "edit") || - STRCASEEQ (cmd, "vi") || - STRCASEEQ (cmd, "emacs")) - r = do_edit (cmd, argc, argv); - else if (STRCASEEQ (cmd, "lcd")) - r = do_lcd (cmd, argc, argv); - else if (STRCASEEQ (cmd, "glob")) - r = do_glob (cmd, argc, argv); - else if (STRCASEEQ (cmd, "man") || - STRCASEEQ (cmd, "manual")) - r = do_man (cmd, argc, argv); - else if (STRCASEEQ (cmd, "more") || - STRCASEEQ (cmd, "less")) - r = do_more (cmd, argc, argv); - else if (STRCASEEQ (cmd, "reopen")) - r = do_reopen (cmd, argc, argv); - else if (STRCASEEQ (cmd, "sparse")) - r = do_sparse (cmd, argc, argv); - else if (STRCASEEQ (cmd, "supported")) - r = do_supported (cmd, argc, argv); - else if (STRCASEEQ (cmd, "time")) - r = do_time (cmd, argc, argv); else r = run_action (cmd, argc, argv); @@ -1133,39 +1100,12 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) void list_builtin_commands (void) { - /* help, man and quit should appear at the top */ + /* help and quit should appear at the top */ printf ("%-20s %s\n", "help", _("display a list of commands or help on a command")); printf ("%-20s %s\n", - "man", _("read the manual")); - printf ("%-20s %s\n", "quit", _("quit guestfish")); - printf ("%-20s %s\n", - "alloc", _("allocate an image")); - printf ("%-20s %s\n", - "copy-in", _("copy files into an image")); - printf ("%-20s %s\n", - "copy-out", _("copy files out of an image")); - printf ("%-20s %s\n", - "echo", _("display a line of text")); - printf ("%-20s %s\n", - "edit", _("edit a file in the image")); - printf ("%-20s %s\n", - "lcd", _("local change directory")); - printf ("%-20s %s\n", - "glob", _("expand wildcards in command")); - printf ("%-20s %s\n", - "more", _("view a file in the pager")); - printf ("%-20s %s\n", - "reopen", _("close and reopen libguestfs handle")); - printf ("%-20s %s\n", - "sparse", _("allocate a sparse image file")); - printf ("%-20s %s\n", - "supported", _("list supported groups of commands")); - printf ("%-20s %s\n", - "time", _("measure time taken to run command")); - /* actions are printed after this (see list_commands) */ } @@ -1174,108 +1114,12 @@ display_builtin_command (const char *cmd) { /* help for actions is auto-generated, see display_command */ - if (STRCASEEQ (cmd, "alloc") || - STRCASEEQ (cmd, "allocate")) { - printf (_("alloc - allocate an image\n" - " alloc <filename> <size>\n" - "\n" - " This creates an empty (zeroed) file of the given size,\n" - " and then adds so it can be further examined.\n" - "\n" - " For more advanced image creation, see qemu-img utility.\n" - "\n" - " Size can be specified using standard suffixes, eg. '1M'.\n" - )); - return 0; - } - else if (STRCASEEQ (cmd, "copy-in") || - STRCASEEQ (cmd, "copy_in")) { - printf (_("copy-in - copy files into an image\n" - " copy-in <local> [<local> ...] <remotedir>\n" - "\n" - " Copy local files or directories recursively into the\n" - " image, placing them on a remote directory.\n" - )); - return 0; - } - else if (STRCASEEQ (cmd, "copy-out") || - STRCASEEQ (cmd, "copy_out")) { - printf (_("copy-out - copy files out of an image\n" - " copy-out <remote> [<remote> ...] <localdir>\n" - "\n" - " Copy remote files or directories recursively out of the\n" - " image, placing them in a local directory.\n" - )); - return 0; - } - else if (STRCASEEQ (cmd, "echo")) { - printf (_("echo - display a line of text\n" - " echo [<params> ...]\n" - "\n" - " This echos the parameters to the terminal.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "edit") || - STRCASEEQ (cmd, "vi") || - STRCASEEQ (cmd, "emacs")) { - printf (_("edit - edit a file in the image\n" - " edit <filename>\n" - "\n" - " This is used to edit a file.\n" - "\n" - " It is the equivalent of (and is implemented by)\n" - " running \"cat\", editing locally, and then \"write\".\n" - "\n" - " Normally it uses $EDITOR, but if you use the aliases\n" - " \"vi\" or \"emacs\" you will get those editors.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "lcd")) { - printf (_("lcd - local change directory\n" - " lcd <directory>\n" - "\n" - " Change guestfish's current directory. This command is\n" - " useful if you want to download files to a particular\n" - " place.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "glob")) { - printf (_("glob - expand wildcards in command\n" - " glob <command> [<args> ...]\n" - "\n" - " Glob runs <command> with wildcards expanded in any\n" - " command args. Note that the command is run repeatedly\n" - " once for each expanded argument.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "man") || - STRCASEEQ (cmd, "manual")) { - printf (_("man - read the manual\n" - " man\n" - "\n" - " Opens the manual page for guestfish.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "help")) { + if (STRCASEEQ (cmd, "help")) { printf (_("help - display a list of commands or help on a command\n" " help cmd\n" " help\n")); return 0; } - else if (STRCASEEQ (cmd, "more") || - STRCASEEQ (cmd, "less")) { - printf (_("more - view a file in the pager\n" - " more <filename>\n" - "\n" - " This is used to view a file in the pager.\n" - "\n" - " It is the equivalent of (and is implemented by)\n" - " running \"cat\" and using the pager.\n" - "\n" - " Normally it uses $PAGER, but if you use the alias\n" - " \"less\" then it always uses \"less\".\n")); - return 0; - } else if (STRCASEEQ (cmd, "quit") || STRCASEEQ (cmd, "exit") || STRCASEEQ (cmd, "q")) { @@ -1283,56 +1127,6 @@ display_builtin_command (const char *cmd) " quit\n")); return 0; } - else if (STRCASEEQ (cmd, "reopen")) { - printf (_("reopen - close and reopen the libguestfs handle\n" - " reopen\n" - "\n" - "Close and reopen the libguestfs handle. It is not necessary to use\n" - "this normally, because the handle is closed properly when guestfish\n" - "exits. However this is occasionally useful for testing.\n")); - return 0; - } - else if (STRCASEEQ (cmd, "sparse")) { - printf (_("sparse - allocate a sparse image file\n" - " sparse <filename> <size>\n" - "\n" - " This creates an empty sparse file of the given size,\n" - " and then adds so it can be further examined.\n" - "\n" - " In all respects it works the same as the 'alloc'\n" - " command, except that the image file is allocated\n" - " sparsely, which means that disk blocks are not assigned\n" - " to the file until they are needed. Sparse disk files\n" - " only use space when written to, but they are slower\n" - " and there is a danger you could run out of real disk\n" - " space during a write operation.\n" - "\n" - " For more advanced image creation, see qemu-img utility.\n" - "\n" - " Size can be specified using standard suffixes, eg. '1M'.\n" - )); - return 0; - } - else if (STRCASEEQ (cmd, "supported")) { - printf (_("supported - list supported groups of commands\n" - " supported\n" - "\n" - " This command returns a list of the optional groups\n" - " known to the daemon, and indicates which ones are\n" - " supported by this build of the libguestfs appliance.\n" - "\n" - " See also guestfs(3) section AVAILABILITY.\n" - )); - return 0; - } - else if (STRCASEEQ (cmd, "time")) { - printf (_("time - measure time taken to run command\n" - " time <command> [<args> ...]\n" - "\n" - " This runs <command> as usual, and prints the elapsed\n" - " time afterwards.\n")); - return 0; - } else { fprintf (stderr, _("%s: command not known, use -h to list all commands\n"), cmd); diff --git a/fish/fish.h b/fish/fish.h index f908a222..609cbc29 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -88,37 +88,37 @@ extern int complete_dest_paths; extern char *complete_dest_paths_generator (const char *text, int state); /* in alloc.c */ -extern int do_alloc (const char *cmd, int argc, char *argv[]); -extern int do_sparse (const char *cmd, int argc, char *argv[]); +extern int run_alloc (const char *cmd, int argc, char *argv[]); +extern int run_sparse (const char *cmd, int argc, char *argv[]); extern int alloc_disk (const char *filename, const char *size, int add, int sparse); extern int parse_size (const char *str, off_t *size_rtn); /* in copy.c */ -extern int do_copy_in (const char *cmd, int argc, char *argv[]); -extern int do_copy_out (const char *cmd, int argc, char *argv[]); +extern int run_copy_in (const char *cmd, int argc, char *argv[]); +extern int run_copy_out (const char *cmd, int argc, char *argv[]); /* in echo.c */ -extern int do_echo (const char *cmd, int argc, char *argv[]); +extern int run_echo (const char *cmd, int argc, char *argv[]); /* in edit.c */ -extern int do_edit (const char *cmd, int argc, char *argv[]); +extern int run_edit (const char *cmd, int argc, char *argv[]); /* in inspect.c */ extern void inspect_mount (void); extern void print_inspect_prompt (void); /* in lcd.c */ -extern int do_lcd (const char *cmd, int argc, char *argv[]); +extern int run_lcd (const char *cmd, int argc, char *argv[]); /* in glob.c */ -extern int do_glob (const char *cmd, int argc, char *argv[]); +extern int run_glob (const char *cmd, int argc, char *argv[]); /* in man.c */ -extern int do_man (const char *cmd, int argc, char *argv[]); +extern int run_man (const char *cmd, int argc, char *argv[]); /* in more.c */ -extern int do_more (const char *cmd, int argc, char *argv[]); +extern int run_more (const char *cmd, int argc, char *argv[]); /* in prep.c */ struct prep_data { @@ -147,13 +147,13 @@ extern int rc_remote (int pid, const char *cmd, int argc, char *argv[], int exit_on_error); /* in reopen.c */ -extern int do_reopen (const char *cmd, int argc, char *argv[]); +extern int run_reopen (const char *cmd, int argc, char *argv[]); /* in supported.c */ -extern int do_supported (const char *cmd, int argc, char *argv[]); +extern int run_supported (const char *cmd, int argc, char *argv[]); /* in time.c */ -extern int do_time (const char *cmd, int argc, char *argv[]); +extern int run_time (const char *cmd, int argc, char *argv[]); /* in tilde.c */ extern char *try_tilde_expansion (char *path); @@ -166,19 +166,7 @@ extern int add_libvirt_drives (const char *guest); */ #define BUILTIN_COMMANDS_FOR_COMPLETION \ "help", \ - "quit", "exit", "q", \ - "alloc", "allocate", \ - "copy-in", "copy-out", \ - "echo", \ - "edit", "vi", "emacs", \ - "lcd", \ - "glob", \ - "man", "manual", \ - "more", "less", \ - "reopen", \ - "sparse", \ - "supported", \ - "time" + "quit", "exit", "q" static inline char * bad_cast (char const *s) diff --git a/fish/glob.c b/fish/glob.c index 1a18b370..41f2bcdd 100644 --- a/fish/glob.c +++ b/fish/glob.c @@ -31,7 +31,7 @@ static void glob_issue (char *cmd, int argc, char ***globs, int *posn, int *count, int *r); int -do_glob (const char *cmd, int argc, char *argv[]) +run_glob (const char *cmd, int argc, char *argv[]) { /* For 'glob cmd foo /s* /usr/s*' this could be: * diff --git a/fish/guestfish.pod b/fish/guestfish.pod index f9269a16..ed2e7980 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -770,77 +770,6 @@ I<--no-progress-bars>. The commands in this section are guestfish convenience commands, in other words, they are not part of the L<guestfs(3)> API. -=head2 alloc | allocate - - alloc filename size - -This creates an empty (zeroed) file of the given size, and then adds -so it can be further examined. - -For more advanced image creation, see L<qemu-img(1)> utility. - -Size can be specified using standard suffixes, eg. C<1M>. - -=head2 copy-in - - copy-in local [local ...] /remotedir - -C<copy-in> copies local files or directories recursively into the disk -image, placing them in the directory called C</remotedir> (which must -exist). This guestfish meta-command turns into a sequence of -L</tar-in> and other commands as necessary. - -Multiple local files and directories can be specified, but the last -parameter must always be a remote directory. Wildcards cannot be -used. - -=head2 copy-out - - copy-out remote [remote ...] localdir - -C<copy-out> copies remote files or directories recursively out of the -disk image, placing them on the host disk in a local directory called -C<localdir> (which must exist). This guestfish meta-command turns -into a sequence of L</download>, L</tar-out> and other commands as -necessary. - -Multiple remote files and directories can be specified, but the last -parameter must always be a local directory. To download to the -current directory, use C<.> as in: - - copy-out /home . - -Wildcards cannot be used in the ordinary command, but you can use -them with the help of L</glob> like this: - - glob copy-out /home/* . - -=head2 echo - - echo [params ...] - -This echos the parameters to the terminal. - -=head2 edit | vi | emacs - - edit filename - -This is used to edit a file. It downloads the file, edits it -locally using your editor, then uploads the result. - -The editor is C<$EDITOR>. However if you use the alternate -commands C<vi> or C<emacs> you will get those corresponding -editors. - -=head2 glob - - glob command args... - -Expand wildcards in any paths in the args list, and run C<command> -repeatedly on each matching path. - -See section WILDCARDS AND GLOBBING. - =head2 help help @@ -849,77 +778,11 @@ See section WILDCARDS AND GLOBBING. Without any parameter, this lists all commands. With a C<cmd> parameter, this displays detailed help for a command. -=head2 lcd - - lcd directory - -Change the local directory, ie. the current directory of guestfish -itself. - -Note that C<!cd> won't do what you might expect. - -=head2 man | manual - - man - -Opens the manual page for guestfish. - -=head2 more | less - - more filename - - less filename - -This is used to view a file. - -The default viewer is C<$PAGER>. However if you use the alternate -command C<less> you will get the C<less> command specifically. - =head2 quit | exit This exits guestfish. You can also use C<^D> key. -=head2 reopen - - reopen - -Close and reopen the libguestfs handle. It is not necessary to use -this normally, because the handle is closed properly when guestfish -exits. However this is occasionally useful for testing. - -=head2 sparse - - sparse filename size - -This creates an empty sparse file of the given size, and then adds -so it can be further examined. - -In all respects it works the same as the C<alloc> command, except that -the image file is allocated sparsely, which means that disk blocks are -not assigned to the file until they are needed. Sparse disk files -only use space when written to, but they are slower and there is a -danger you could run out of real disk space during a write operation. - -For more advanced image creation, see L<qemu-img(1)> utility. - -Size can be specified using standard suffixes, eg. C<1M>. - -=head2 supported - - supported - -This command returns a list of the optional groups -known to the daemon, and indicates which ones are -supported by this build of the libguestfs appliance. - -See also L<guestfs(3)/AVAILABILITY>. - -=head2 time - - time command args... - -Run the command as usual, but print the elapsed time afterwards. This -can be useful for benchmarking operations. +@FISH_COMMANDS@ =head1 COMMANDS @@ -28,7 +28,7 @@ /* guestfish lcd command (similar to the lcd command in BSD ftp) */ int -do_lcd (const char *cmd, int argc, char *argv[]) +run_lcd (const char *cmd, int argc, char *argv[]) { if (argc != 1) { fprintf (stderr, _("use 'lcd directory' to change local directory\n")); @@ -28,7 +28,7 @@ /* guestfish man command */ int -do_man (const char *cmd, int argc, char *argv[]) +run_man (const char *cmd, int argc, char *argv[]) { if (argc != 0) { fprintf (stderr, _("use 'man' without parameters to open the manual\n")); diff --git a/fish/more.c b/fish/more.c index 55faefa8..27fc5481 100644 --- a/fish/more.c +++ b/fish/more.c @@ -28,7 +28,7 @@ #include "fish.h" int -do_more (const char *cmd, int argc, char *argv[]) +run_more (const char *cmd, int argc, char *argv[]) { char filename[] = "/tmp/guestfishXXXXXX"; char buf[256]; diff --git a/fish/reopen.c b/fish/reopen.c index 9e190183..1b162c19 100644 --- a/fish/reopen.c +++ b/fish/reopen.c @@ -26,7 +26,7 @@ #include "fish.h" int -do_reopen (const char *cmd, int argc, char *argv[]) +run_reopen (const char *cmd, int argc, char *argv[]) { guestfs_h *g2; int r; diff --git a/fish/supported.c b/fish/supported.c index c97af143..3a0c93c0 100644 --- a/fish/supported.c +++ b/fish/supported.c @@ -26,7 +26,7 @@ #include "fish.h" int -do_supported (const char *cmd, int argc, char *argv[]) +run_supported (const char *cmd, int argc, char *argv[]) { char **groups; diff --git a/fish/time.c b/fish/time.c index ed00c18e..f2fa0fcf 100644 --- a/fish/time.c +++ b/fish/time.c @@ -26,7 +26,7 @@ #include "fish.h" int -do_time (const char *cmd, int argc, char *argv[]) +run_time (const char *cmd, int argc, char *argv[]) { struct timeval start_t, end_t; int64_t start_us, end_us, elapsed_us; |