Expand libtooling CommonOptionsParser arguments

Hello,

I would like to expand CommonOptionsParser class with a new argument to specify an output file (something like -o “generated.cpp”). What would be the best way to do that?

Hello,

I would like to expand CommonOptionsParser class with a new argument to
specify an output file (something like -o "generated.cpp"). What would be
the best way to do that?

As this sounds like something that is not common to pretty much all tools,
I'd say - put it into the actual tool you're writing?

Cheers,
/Manuel

Hi Manuel,

Haha, yes, It’s exactly what I’m intending to do. The problem is that CommonOptionsParser calls cl::ParseCommandLineOptions(argc, argv) and I was trying to figure on how to inject custom arguments inside it.

Cheers,

Victor

Take a look at the class comment in
llvm/tools/clang/include/clang/Tooling/CommonOptionsParser.h

If something doesn’t work as described there (or if we can make it clearer) let me know :slight_smile:

Cheers,
/Manuel

Ah, figured it out, just placing this code:

static llvm::cl::optstd::string OutputPath(

“o”, llvm::cl::desc(“Output file”), llvm::cl::Optional);

before calling:

CommonOptionsParser parser( argc, argv );

on my tool does some static black magic that automagically adds the option to the application.

Thanks,

Victor