r181617 - Reformat clang-format help strings, filter out irrelevant options.

Daniel Jasper djasper at google.com
Mon May 13 03:20:43 PDT 2013


On Fri, May 10, 2013 at 8:12 PM, Alexander Kornienko <alexfh at google.com>wrote:

> Author: alexfh
> Date: Fri May 10 13:12:00 2013
> New Revision: 181617
>
> URL: http://llvm.org/viewvc/llvm-project?rev=181617&view=rev
> Log:
> 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
>
> Modified:
>     cfe/trunk/docs/ClangFormat.rst
>     cfe/trunk/tools/clang-format/ClangFormat.cpp
>
> Modified: cfe/trunk/docs/ClangFormat.rst
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=181617&r1=181616&r2=181617&view=diff
>
> ==============================================================================
> --- cfe/trunk/docs/ClangFormat.rst (original)
> +++ cfe/trunk/docs/ClangFormat.rst Fri May 10 13:12:00 2013
> @@ -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 <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
>
> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=181617&r1=181616&r2=181617&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Fri May 10 13:12:00 2013
> @@ -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 ClangFormatCategory("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(ClangFormatCategory));
>

I think we should try to keep clang-format's files "clang-format clean". Is
there something you found particularly bad about the way clang-format
formats this? Can we fix it?


> +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(ClangFormatCategory));
> +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(ClangFormatCategory));
>  static cl::opt<bool> Inplace("i",
> -                             cl::desc("Inplace edit <file>s, if
> specified."));
> +                             cl::desc("Inplace edit <file>s, if
> specified."),
> +                             cl::cat(ClangFormatCategory));
>
> -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(ClangFormatCategory));
>  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(ClangFormatCategory));
>
> -static cl::list<std::string> FileNames(cl::Positional,
> -                                       cl::desc("[<file> ...]"));
> +static cl::list<std::string> FileNames(cl::Positional, cl::desc("[<file>
> ...]"),
> +                                       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<cl::Option*> Options;
> +  cl::getRegisteredOptions(Options);
> +  for (StringMap<cl::Option *>::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"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130513/01270e6a/attachment.html>


More information about the cfe-commits mailing list