igormironchik / args-parser Goto Github PK
View Code? Open in Web Editor NEWargs-parser is a small C++ header-only library for parsing command line arguments.
Home Page: http://igormironchik.github.io/args-parser/
args-parser is a small C++ header-only library for parsing command line arguments.
Home Page: http://igormironchik.github.io/args-parser/
I have in my program 2 arguments that should Ideally work with a command to achieve different behavior than if used alone.
the idea is that if used alone the load specific files but if used as arguments of the init
command would set the location of those files.
I don't know if this would be a common use case, but I thought it might be worth mentioning.
Is this the same with http://code.google.com/p/qtargparser or another one? Google Code redirected me here.
Hi,
This args parser looks great, but would it be possible to document all the features more exhaustively?
Thanks.
what's the difference between addCommand and addArgWithFlagAndName?
I realized that with one-line
syntax it's impossible to add command into any group. But it's very useful feature. So I'm going to implement it.
This library looks well featured and nicely designed.
Please add at least one more example to the README page that shows simple usage. Not subcommands. Just a simple example with parsing for a boolean flag, and an option with an argument. I'm an idiot, but nevertheless it still took me far me too long to find how to do this. For something as simple as an argparser, people want to copy and paste an example and edit it so they can get up and running quickly - putting only one example program (of the new version) on the README page that is subcommands is confusing.
Even better would be an example program showcasing several types of options, flags, options with argument(s), groups (if supported) etc.
All the best. In case it matters, I'm now using this library via conan after trying to use argh and being unable to understand it too.
I am fully aware that this is a stupid question (but I also know I won't figure it out on my own)
I can't figure out how to connect and of my defined argument to actual functions to do anything useful
ie. unzip extract some-file
or unzip -c directory
would extract and compress things respectively
or even to set a value like in the help example example.help --host localhost --port 44
could set int port = 44
This looks like a cool library, and I plan to use it in a lot of current and past projects once I know how.
There exist several and apparent;y more popular libraries for parsing command-line arguments e.g.:
and probably others. Your README.md
should explain you your conception of command-like argument parsing is different than theirs.
I've integrated the library v. 6.3.3 in a project, where one of the classes in the global namespace is named Command. This shouldn't be a problem, as the entire args-parser lirary is implemented in the namespace Args.
However, the class Args::ArgIface declares the class Commad to a friend:
class ArgIface {
friend class CmdLine;
friend class GroupIface;
friend class Command; // this is meant to be Args::Command, not ::Command!
...
Because this is done before the class Args::Command declaration and after ::Command declaration, the compiler makes ::Command a friend instead of Args::Command. This leads to the protected member access compilation error.
The solution is to use a forward declaration of Command just before ArgIface declaration. Probably the same should be done to GroupIface (CmdLine is already forward-declared). Forward declaration makes the compiler aware of Args::Command class, and it is able to pick the correct one to make friend when declaring Args::ArgIface as expected.
When used in header only mode, during compilation I'm getting errors like:
/bin/ld: /tmp/ccItTpC3.o: in function `Args::details::isMisspelledName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
setup.cpp:(.text+0x86): multiple definition of `Args::details::isMisspelledName(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'; /tmp/ccvkSDm2.o:main.cpp:(.text+0x86): first defined here
/bin/ld: /tmp/ccItTpC3.o:(.bss+0x0): multiple definition of `Args::MultiArg::m_emptyString[abi:cxx11]'; /tmp/ccvkSDm2.o:(.bss+0x0): first defined here
/bin/ld: /tmp/ccItTpC3.o:(.bss+0x20): multiple definition of `Args::GroupIface::m_dummyEmptyString[abi:cxx11]'; /tmp/ccvkSDm2.o:(.bss+0x20): first defined here
/bin/ld: /tmp/ccItTpC3.o:(.bss+0x40): multiple definition of `Args::g_argsOutStream'; /tmp/ccvkSDm2.o:(.bss+0x40): first defined here
/bin/ld: /tmp/ccItTpC3.o: in function `Args::details::formatCorrectNamesString(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)':
setup.cpp:(.text+0x1d0): multiple definition of `Args::details::formatCorrectNamesString(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)'; /tmp/ccvkSDm2.o:main.cpp:(.text+0x1d0): first defined here
collect2: error: ld returned 1 exit status
My software is g++ 10.2.1, Void GNU/Linux 5.18.7_1
#include "args-parser/args-parser/all.hpp"
#include "setup.h"
int main(int argc, char* argv[])
{
Args::CmdLine cmd{argc, argv};
SetupCMD(cmd);
return 0;
}
#ifndef SETUP_FUNCS_H
#define SETUP_FUNCS_H
#include "args-parser/args-parser/all.hpp"
void SetupCMD(Args::CmdLine &cmd);
#endif
#include "setup.h"
void SetupCMD(Args::CmdLine &cmd)
{
cmd.addArgWithNameOnly("foo", true, true, "bar");
cmd.parse();
}
g++ main.cpp setup.cpp
I'm playing around with the args-parser and our (quite restrictive) compiler settings generate a compilation error in help_printer.hpp at line 638:
declaration of 'cmd' shadows a previous local [-Werror=shadow]
Perhaps you should rename the lambda function's argument cmd
.
Implement fully featured sub-commands, that can have their children, as ArgAsCommand
is just an argument with name without dashes.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.