summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-03 23:47:47 +0100
committerRichard Jones <rjones@redhat.com>2009-04-03 23:47:47 +0100
commitbc0b3d6f473e607972d29be27f7ae6b1d0489c3b (patch)
treea2129e7328c1adff8c32890d57a86c36b908ecff /src
parentb72ec21d24824720385c9cd024b7f1eae734f4a4 (diff)
downloadlibguestfs-bc0b3d6f473e607972d29be27f7ae6b1d0489c3b.tar.gz
libguestfs-bc0b3d6f473e607972d29be27f7ae6b1d0489c3b.tar.xz
libguestfs-bc0b3d6f473e607972d29be27f7ae6b1d0489c3b.zip
Added outline of shell command, added generator support.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/generator.ml b/src/generator.ml
index 5868e170..b26ea3c1 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -74,7 +74,7 @@ calling C<guestfs_close>.");
"Update file timestamps or create a new file",
"\
Touch acts like the L<touch(1)> command. It can be used to
-update the filesystems on a file, or, if the file does not exist,
+update the timestamps on a file, or, if the file does not exist,
to create a new zero-length file.");
]
@@ -87,6 +87,11 @@ let iter_args f = function
| P1 arg1 -> f arg1
| P2 (arg1, arg2) -> f arg1; f arg2
+let map_args f = function
+ | P0 -> []
+ | P1 arg1 -> [f arg1]
+ | P2 (arg1, arg2) -> [f arg1; f arg2]
+
type comment_style = CStyle | HashStyle | OCamlStyle
type license = GPLv2 | LGPLv2
@@ -446,7 +451,60 @@ and generate_daemon_actions () =
pr " default:\n";
pr " reply_with_error (\"dispatch_incoming_message: unknown procedure number %%d\", proc_nr);\n";
pr " }\n";
+ pr "}\n"
+
+and generate_fish_cmds () =
+ generate_header CStyle GPLv2;
+
+ pr "#include <stdio.h>\n";
+ pr "#include <stdlib.h>\n";
+ pr "#include <string.h>\n";
+ pr "\n";
+ pr "#include \"fish.h\"\n";
+ pr "\n";
+
+ (* list_commands function, which implements guestfish -h *)
+ pr "void list_commands (void)\n";
+ pr "{\n";
+ pr " printf (\"%%-20s %%s\\n\", \"Command\", \"Description\");\n";
+ List.iter (
+ fun (name, _, _, shortdesc, _) ->
+ pr " printf (\"%%-20s %%s\\n\", \"%s\", \"%s\");\n"
+ name shortdesc
+ ) functions;
+ pr " printf (\"Use -h <cmd> to show detailed help for a command.\\n\");\n";
pr "}\n";
+ pr "\n";
+
+ (* display_command function, which implements guestfish -h cmd *)
+ pr "void display_command (const char *cmd)\n";
+ pr "{\n";
+ List.iter (
+ fun (name, style, _, shortdesc, longdesc) ->
+ let synopsis =
+ match style with
+ | (Err, P0) -> name
+ | (Err, args) ->
+ sprintf "%s <%s>"
+ name (
+ String.concat "> <" (
+ map_args (function
+ | String n -> n) args
+ )
+ ) in
+
+ pr " if (strcasecmp (cmd, \"%s\") == 0)\n" name;
+ pr " pod2text (\"%s - %s\", %S);\n"
+ name shortdesc
+ (" " ^ synopsis ^ "\n\n" ^ longdesc);
+ pr " else\n"
+ ) functions;
+ pr " {\n";
+ pr " fprintf (stderr, \"%%s: command not known, use -h to list all commands\\n\", cmd);\n";
+ pr " exit (1);\n";
+ pr " }\n";
+ pr "}\n";
+ pr "\n"
(* Generate a C function prototype. *)
and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true)
@@ -527,6 +585,10 @@ let () =
generate_daemon_actions ();
close ();
+ let close = output_to "fish/cmds.c" in
+ generate_fish_cmds ();
+ close ();
+
let close = output_to "guestfs-actions.pod" in
generate_pod ();
close ()