From: Alexander Kornienko Date: Fri, 10 May 2013 18:12:00 +0000 (+0000) Subject: Reformat clang-format help strings, filter out irrelevant options. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46529e5bf7f46ec8771a091ff3ab9877620f7036;p=clang Reformat clang-format help strings, filter out irrelevant options. Summary: +updated ClangFormat.rst Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D780 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181617 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/ClangFormat.rst b/docs/ClangFormat.rst index 964fc84d7b..a9687bc9e4 100644 --- a/docs/ClangFormat.rst +++ b/docs/ClangFormat.rst @@ -20,21 +20,43 @@ to format C/C++/Obj-C code. If no arguments are specified, it formats the code from standard input and writes the result to the standard output. - If is given, it reformats the file. If -i is specified together - with , the file is edited in-place. Otherwise, the result is - written to the standard output. + If s are given, it reformats the files. If -i is specified + together with s, the files are edited in-place. Otherwise, the + result is written to the standard output. - USAGE: clang-format [options] [] + USAGE: clang-format [options] [ ...] OPTIONS: - -fatal-assembler-warnings - Consider warnings as error - -help - Display available options (-help-hidden for more) - -i - Inplace edit , if specified. - -length= - Format a range of this length, -1 for end of file. - -offset= - Format a range starting at this file offset. - -stats - Enable statistics output from program - -style= - 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 s, if specified. + -length= - 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= - 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= - 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 diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp index ea70dafe03..f779348f0f 100644 --- a/tools/clang-format/ClangFormat.cpp +++ b/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 Help("h", cl::desc("Alias for -help"), cl::Hidden); -static cl::list 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 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 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 ClangFormatCategory("Clang-format options"); + +static cl::list + 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(ClangFormatCategory)); +static cl::list + 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(ClangFormatCategory)); +static cl::opt + 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(ClangFormatCategory)); static cl::opt Inplace("i", - cl::desc("Inplace edit s, if specified.")); + cl::desc("Inplace edit s, if specified."), + cl::cat(ClangFormatCategory)); -static cl::opt OutputXML( - "output-replacements-xml", cl::desc("Output replacements as XML.")); +static cl::opt OutputXML("output-replacements-xml", + cl::desc("Output replacements as XML."), + cl::cat(ClangFormatCategory)); static cl::opt 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(ClangFormatCategory)); -static cl::list FileNames(cl::Positional, - cl::desc("[ ...]")); +static cl::list FileNames(cl::Positional, cl::desc("[ ...]"), + cl::cat(ClangFormatCategory)); namespace clang { namespace format { @@ -196,6 +210,17 @@ static bool format(std::string FileName) { int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); + + // Hide unrelated options. + StringMap Options; + cl::getRegisteredOptions(Options); + for (StringMap::iterator I = Options.begin(), E = Options.end(); + I != E; ++I) { + if (I->second->Category != &ClangFormatCategory && 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"