Pino Toscano
2016-Apr-11 15:16 UTC
[Libguestfs] [PATCH] fish: improve formatting of help text of generated commands
In the generated description of the guestfish commands, wrap and indent
the help text, so it is a multiline string instead of a very long single
one.
This has no behaviour changes, only makes cmds.c more readable (and
easier to diff when the description of actions change).
---
generator/fish.ml | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/generator/fish.ml b/generator/fish.ml
index 864f65d..646674d 100644
--- a/generator/fish.ml
+++ b/generator/fish.ml
@@ -71,6 +71,11 @@ let all_functions_commands_and_aliases_sorted )
(fish_functions_sorted @ fish_commands) [] in
List.sort func_compare all
+let c_quoted_indented ~indent str + let str = c_quote str in
+ let str = replace_str str "\\n" ("\\n\"\n" ^ indent
^ "\"") in
+ str
+
(* Generate a lot of different functions for guestfish. *)
let generate_fish_cmds () generate_header CStyle GPLv2plus;
@@ -138,7 +143,7 @@ let generate_fish_cmds ()
pr "struct command_entry %s_cmd_entry = {\n" name;
pr " .name = \"%s\",\n" name2;
- pr " .help = \"%s\",\n" (c_quote text);
+ pr " .help = \"%s\",\n" (c_quoted_indented
~indent:" " text);
pr " .synopsis = NULL,\n";
pr " .run = run_%s\n" name;
pr "};\n";
@@ -200,7 +205,7 @@ Guestfish will prompt for these separately."
pr "struct command_entry %s_cmd_entry = {\n" name;
pr " .name = \"%s\",\n" name2;
- pr " .help = \"%s\",\n" (c_quote text);
+ pr " .help = \"%s\",\n" (c_quoted_indented
~indent:" " text);
pr " .synopsis = \"%s\",\n" (c_quote synopsis);
pr " .run = run_%s\n" name;
pr "};\n";
--
2.5.5
Richard W.M. Jones
2016-Apr-11 16:54 UTC
Re: [Libguestfs] [PATCH] fish: improve formatting of help text of generated commands
On Mon, Apr 11, 2016 at 05:16:19PM +0200, Pino Toscano wrote:> In the generated description of the guestfish commands, wrap and indent > the help text, so it is a multiline string instead of a very long single > one. > > This has no behaviour changes, only makes cmds.c more readable (and > easier to diff when the description of actions change). > --- > generator/fish.ml | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/generator/fish.ml b/generator/fish.ml > index 864f65d..646674d 100644 > --- a/generator/fish.ml > +++ b/generator/fish.ml > @@ -71,6 +71,11 @@ let all_functions_commands_and_aliases_sorted > ) (fish_functions_sorted @ fish_commands) [] in > List.sort func_compare all > > +let c_quoted_indented ~indent str > + let str = c_quote str in > + let str = replace_str str "\\n" ("\\n\"\n" ^ indent ^ "\"") in > + str > + > (* Generate a lot of different functions for guestfish. *) > let generate_fish_cmds () > generate_header CStyle GPLv2plus; > @@ -138,7 +143,7 @@ let generate_fish_cmds () > > pr "struct command_entry %s_cmd_entry = {\n" name; > pr " .name = \"%s\",\n" name2; > - pr " .help = \"%s\",\n" (c_quote text); > + pr " .help = \"%s\",\n" (c_quoted_indented ~indent:" " text); > pr " .synopsis = NULL,\n"; > pr " .run = run_%s\n" name; > pr "};\n"; > @@ -200,7 +205,7 @@ Guestfish will prompt for these separately." > > pr "struct command_entry %s_cmd_entry = {\n" name; > pr " .name = \"%s\",\n" name2; > - pr " .help = \"%s\",\n" (c_quote text); > + pr " .help = \"%s\",\n" (c_quoted_indented ~indent:" " text); > pr " .synopsis = \"%s\",\n" (c_quote synopsis); > pr " .run = run_%s\n" name; > pr "};\n"; > -- > 2.5.5ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Possibly Parallel Threads
- [PATCH v2] fish: show synopsis if command syntax is wrong
- [PATCH 0/4] generator: Some work to split large C files
- Re: [PATCH v2] fish: show synopsis if command syntax is wrong
- [PATCH] fish: show synopsis if command syntax is wrong
- [PATCH] generator: Add visibility to action struct