Skip to content

Commit

Permalink
Add a --markdown flag to GN to be able to output help in markdown.
Browse files Browse the repository at this point in the history
With this change, we can now generate a markdown page containing all
of the built-in help from GN, so that it will be visible on the web.

The changes to GN to support markdown are, so far, minimal, but the
resulting format is also pretty lame: we just wrap the body of the each
help command in a code block (markdown's equivalent of <pre>).

R=brettw@chromium.org
BUG=468851

Review URL: https://codereview.chromium.org/1024783002

Cr-Commit-Position: refs/heads/master@{#325730}
  • Loading branch information
dpranke authored and Commit bot committed Apr 17, 2015
1 parent 4d95908 commit e7700dd
Show file tree
Hide file tree
Showing 6 changed files with 4,407 additions and 7 deletions.
1 change: 1 addition & 0 deletions tools/gn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Read these links:
* [FAQ](docs/faq.md)
* [GYP conversion cookbook](docs/cookbook.md)
* [Language and operation details](docs/language.md)
* [Reference](docs/reference.md) The built-in `gn help` documentation.
* [Style guide](docs/style_guide.md)
* [Cross compiling and toolchains](docs/cross_compiles.md)
* [Hacking on GN itself](docs/hacking.md)
Expand Down
19 changes: 18 additions & 1 deletion tools/gn/command_help.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,35 @@ void PrintToplevelHelp() {
}

void PrintSwitchHelp() {
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
bool use_markdown = cmdline->HasSwitch(switches::kMarkdown);

OutputString("Available global switches\n", DECORATION_YELLOW);
OutputString(
" Do \"gn help --the_switch_you_want_help_on\" for more. Individual\n"
" commands may take command-specific switches not listed here. See the\n"
" help on your specific command for more.\n\n");

if (use_markdown)
OutputString("```\n\n", DECORATION_NONE);

for (const auto& s : switches::GetSwitches())
PrintShortHelp(s.second.short_help);

if (use_markdown)
OutputString("\n```\n", DECORATION_NONE);
}

void PrintAllHelp() {
PrintToplevelHelp();
const base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess();
if (cmdline->HasSwitch(switches::kMarkdown)) {
OutputString("# GN Reference\n\n");
OutputString("[TOC]\n\n");
OutputString("*This page is automatically generated from* "
"`gn help --markdown all`.\n\n");
} else {
PrintToplevelHelp();
}

for (const auto& s : switches::GetSwitches())
PrintLongHelp(s.second.long_help);
Expand Down
Loading

0 comments on commit e7700dd

Please sign in to comment.