Skip to content

Commit

Permalink
Add possibility to set up custom help printer in help.
Browse files Browse the repository at this point in the history
  • Loading branch information
igormironchik committed Aug 7, 2021
1 parent aea827e commit 83418d9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
41 changes: 36 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ as `StringList`

# Q/A

Why not to add description, long description, etc into constructors of
arguments, so it will be possible to initialize argument in one line?
**Why not to add description, long description, etc into constructors of
arguments, so it will be possible to initialize argument in one line?**

* This is impossible because constructors will be ambiguous but you can use
auxiliary API that allows to define arguments in one line of code.

How can I add args-parser to my project?
**How can I add args-parser to my project?**

* The simplest way is just copy args-parser directory with headers to any location in
your project. With CMake you can clone entire `args-parser` project somewhere in your
Expand All @@ -75,7 +75,7 @@ add include directory path to your project with
case it will be possible to use `find_package( args-parser )` in CMakeLists.txt of
your project.

Why should I use this library?
**Why should I use this library?**

* There are tons of libraries for parsing command line arguments on the
Internet. But args-parser also provides the possibility to define commands, like
Expand All @@ -97,7 +97,7 @@ Internet. But args-parser also provides the possibility to define commands, like
that library can do? This library is very flexible with powerfull help
printing. What do you need more?

How to print help programmatically?
**How to print help programmatically?**

* For those, who use old style syntax the answer should be on the plate, as developer
can look at the code of `Help` class, that implements help argument. But for those, who
Expand All @@ -124,6 +124,33 @@ what syntax you use, new (one-line) syntax is just a wrapper for old one. I.e. l
printer.print( outStream() );
```

**Why doesn't args-parser provide bindings of variables to arguments?**

* This is a question of why doesn't `args-parser` provide validators? It's the same.
I decided that this aspect is very application specific. There is no need for such library
to do any conversions of arguments' values, to bind them to some variables. This will
do API very complex only. I know what you will say: this is very nice feature, it helps...
Really? How often and hom much it helped you? Arguments parser should handle the string
that user provided to the application, it should separate arguments, commands, values,
store it in internal state of parser, and allow to developer just write some `if`
operators to choose branch of the programm logic. What will give you, as to developer,
if values will be bind to concrete variables? Will not you write the same code with `if`
operators? So why I should do the library more complex?

**Why don't you provide comparisons with othe CLI libraries?**

* I found only one library at GitHub that can compete with `args-parser`, and this is
[CLI11](https://github.com/CLIUtils/CLI11). And here is the question of the taste more.
But `CLI11` can handle commands as usual arguments, it's doesn't matter how much times
they presend in command line, whereas 'args-parser' handles commands as commands. Theirs
approach possibly more flexible, but when I designed `args-parser` I thought on commands
as on some action to do in application's logic, whereas arguments are for data. I can do
the same, but is it needed?

`CLI11` has possibility to set formatter of the help, `args-parser` allow to set
custom `HelpPrinterIface` on the `Help` argument. But who and when will do it?
And I believe that help in `args-parser` is a little better than in `CLI11`.

# Changelog

* 6.0.0.0
Expand All @@ -142,6 +169,10 @@ what syntax you use, new (one-line) syntax is just a wrapper for old one. I.e. l
Improved API with new syntax, now it's impossible to mess with end() methods.
Fixed issue with printing help of global argument under command.

* 6.1.1.1

Added possibility to set up custom help printer in help argument.

# Example

First of all you must know that practically all classes of the args-parser throws exceptions on errors
Expand Down
9 changes: 9 additions & 0 deletions args-parser/help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class Help final
//! Set line length for the help.
void setLineLength( String::size_type length );

//! Set printer.
void setPrinter( std::unique_ptr< HelpPrinterIface > p );

protected:
/*!
Process argument's staff, for example take values from
Expand Down Expand Up @@ -134,6 +137,12 @@ Help::setLineLength( String::size_type length )
m_printer->setLineLength( length );
}

inline void
Help::setPrinter( std::unique_ptr< HelpPrinterIface > p )
{
m_printer.reset( p.release() );
}

inline void
Help::process( Context & context )
{
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = args-parser
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 6.1.1.0
PROJECT_NUMBER = 6.1.1.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down

0 comments on commit 83418d9

Please sign in to comment.