[PATCH] Reformat clang-format help strings, filter out irrelevant options.
Alexander Kornienko
alexfh at google.com
Fri May 10 10:54:51 PDT 2013
Hi djasper, klimek,
+updated ClangFormat.rst
http://llvm-reviews.chandlerc.com/D780
Files:
docs/ClangFormat.rst
tools/clang-format/ClangFormat.cpp
Index: docs/ClangFormat.rst
===================================================================
--- docs/ClangFormat.rst
+++ docs/ClangFormat.rst
@@ -20,21 +20,43 @@
If no arguments are specified, it formats the code from standard input
and writes the result to the standard output.
- If <file> is given, it reformats the file. If -i is specified together
- with <file>, the file is edited in-place. Otherwise, the result is
- written to the standard output.
+ If <file>s are given, it reformats the files. If -i is specified
+ together with <file>s, the files are edited in-place. Otherwise, the
+ result is written to the standard output.
- USAGE: clang-format [options] [<file>]
+ USAGE: clang-format [options] [<file> ...]
OPTIONS:
- -fatal-assembler-warnings - Consider warnings as error
- -help - Display available options (-help-hidden for more)
- -i - Inplace edit <file>, if specified.
- -length=<int> - Format a range of this length, -1 for end of file.
- -offset=<int> - Format a range starting at this file offset.
- -stats - Enable statistics output from program
- -style=<string> - Coding style, currently supports: LLVM, Google, Chromium.
- -version - Display the version of this program
+
+ Clang-format options:
+
+ -dump-config - Dump configuration options to stdout and exit.
+ Can be used with -style option.
+ -i - Inplace edit <file>s, if specified.
+ -length=<uint> - Format a range of this length (in bytes).
+ Multiple ranges can be formatted by specifying
+ several -offset and -length pairs.
+ When only a single -offset is specified without
+ -length, clang-format will format up to the end
+ of the file.
+ Can only be used with one input file.
+ -offset=<uint> - Format a range starting at this byte offset.
+ Multiple ranges can be formatted by specifying
+ several -offset and -length pairs.
+ Can only be used with one input file.
+ -output-replacements-xml - Output replacements as XML.
+ -style=<string> - Coding style, currently supports:
+ LLVM, Google, Chromium, Mozilla.
+ Use '-style file' to load style configuration from
+ .clang-format file located in one of the parent
+ directories of the source file (or current
+ directory for stdin).
+
+ General options:
+
+ -help - Display available options (-help-hidden for more)
+ -help-list - Display list of available options (-help-list-hidden for more)
+ -version - Display the version of this program
Vim Integration
Index: tools/clang-format/ClangFormat.cpp
===================================================================
--- tools/clang-format/ClangFormat.cpp
+++ tools/clang-format/ClangFormat.cpp
@@ -23,43 +23,57 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Signals.h"
+#include "llvm/ADT/StringMap.h"
using namespace llvm;
static cl::opt<bool> Help("h", cl::desc("Alias for -help"), cl::Hidden);
-static cl::list<unsigned> Offsets(
- "offset",
- cl::desc(
- "Format a range starting at this byte offset. Multiple ranges can be "
- "formatted by specifying several -offset and -length pairs. Can "
- "only be used with one input file."));
-static cl::list<unsigned> Lengths(
- "length",
- cl::desc("Format a range of this length (in bytes). Multiple ranges can be "
- "formatted by specifying several -offset and -length pairs. When "
- "only a single -offset is specified without -length, clang-format "
- "will format up to the end of the file. Can only be used with one "
- "input file."));
-static cl::opt<std::string> Style(
- "style",
- cl::desc(
- "Coding style, currently supports: LLVM, Google, Chromium, Mozilla. "
- "Use '-style file' to load style configuration from .clang-format file "
- "located in one of the parent directories of the source file (or "
- "current directory for stdin)."),
- cl::init("LLVM"));
+// Mark all our options with this category, everything else (except for -version
+// and -help) will be hidden.
+cl::OptionCategory ClangFormatCat("Clang-format options");
+
+static cl::list<unsigned>
+ Offsets("offset",
+ cl::desc("Format a range starting at this byte offset.\n"
+ "Multiple ranges can be formatted by specifying\n"
+ "several -offset and -length pairs.\n"
+ "Can only be used with one input file."),
+ cl::cat(ClangFormatCat));
+static cl::list<unsigned>
+ Lengths("length",
+ cl::desc("Format a range of this length (in bytes).\n"
+ "Multiple ranges can be formatted by specifying\n"
+ "several -offset and -length pairs.\n"
+ "When only a single -offset is specified without\n"
+ "-length, clang-format will format up to the end\n"
+ "of the file.\n"
+ "Can only be used with one input file."),
+ cl::cat(ClangFormatCat));
+static cl::opt<std::string>
+ Style("style",
+ cl::desc("Coding style, currently supports:\n"
+ " LLVM, Google, Chromium, Mozilla.\n"
+ "Use '-style file' to load style configuration from\n"
+ ".clang-format file located in one of the parent\n"
+ "directories of the source file (or current\n"
+ "directory for stdin)."),
+ cl::init("LLVM"), cl::cat(ClangFormatCat));
static cl::opt<bool> Inplace("i",
- cl::desc("Inplace edit <file>s, if specified."));
+ cl::desc("Inplace edit <file>s, if specified."),
+ cl::cat(ClangFormatCat));
-static cl::opt<bool> OutputXML(
- "output-replacements-xml", cl::desc("Output replacements as XML."));
+static cl::opt<bool> OutputXML("output-replacements-xml",
+ cl::desc("Output replacements as XML."),
+ cl::cat(ClangFormatCat));
static cl::opt<bool>
DumpConfig("dump-config",
- cl::desc("Dump configuration options to stdout and exit. Can be used with -style option."));
+ cl::desc("Dump configuration options to stdout and exit.\n"
+ "Can be used with -style option."),
+ cl::cat(ClangFormatCat));
-static cl::list<std::string> FileNames(cl::Positional,
- cl::desc("[<file> ...]"));
+static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file> ...]"),
+ cl::cat(ClangFormatCat));
namespace clang {
namespace format {
@@ -196,6 +210,17 @@
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
+
+ // Hide unrelated options.
+ StringMap<cl::Option*> Options;
+ cl::getRegisteredOptions(Options);
+ for (StringMap<cl::Option *>::iterator I = Options.begin(), E = Options.end();
+ I != E; ++I) {
+ if (I->second->Category != &ClangFormatCat && I->first() != "help" &&
+ I->first() != "version")
+ I->second->setHiddenFlag(cl::ReallyHidden);
+ }
+
cl::ParseCommandLineOptions(
argc, argv,
"A tool to format C/C++/Obj-C code.\n\n"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D780.1.patch
Type: text/x-patch
Size: 8009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130510/cf7fefb5/attachment.bin>
More information about the cfe-commits
mailing list