Skip to content

Commit

Permalink
Update README and CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele77 committed Jan 17, 2023
1 parent e508a70 commit 31ff1b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Nest namespace rang (issue [#167](https://github.com/daniele77/cli/issues/167))
- Add ascii value 8 for backspace (issue [#124](https://github.com/daniele77/cli/issues/124))
- Add check for CMAKE_SKIP_INSTALL_RULES (issue [#160](https://github.com/daniele77/cli/issues/160))
- Add enter action (issue [#177](https://github.com/daniele77/cli/issues/177) - PR [#180](https://github.com/daniele77/cli/pull/177))

## [2.0.2] - 2022-08-18

Expand Down
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ ioc.run();
You must provide at least a root menu for your cli:
```
```C++
// create a menu (this is the root menu of our cli)
auto rootMenu = make_unique<Menu>("myprompt");
Expand All @@ -311,7 +311,7 @@ Cli cli(std::move(rootMenu));

You can add menus to existing menus, to get a hierarchy:

```
```C++
auto rootMenu = make_unique<Menu>("myprompt");

auto menuA = make_unique<Menu>("a_prompt");
Expand Down Expand Up @@ -368,7 +368,7 @@ The library supports adding commands handler via:
- `std::function`
- lambdas
```
```C++
static void foo(std::ostream& out, int x) { out << x << std::endl; }
Expand All @@ -387,7 +387,7 @@ myMenu->Insert("lambda", [](std::ostream& out, int x){ out << x << std::endl; }
There is no limit to the number of parameters that a command handler can take.
They can be basic types and `std::string`s

```
```C++
myMenu->Insert(
"mycmd",
[](std::ostream& out, int a, double b, const std::string& c, bool d, long e)
Expand All @@ -405,7 +405,7 @@ myMenu->Insert(
or they can be custom types overloading the `std::istream << operator`:
```
```C++
struct Foo
{
friend istream & operator >> (istream &in, Foo& p);
Expand All @@ -430,7 +430,7 @@ myMenu->Insert(
If you need it, you can have a command handlers taking an arbitrary
number of `std::string` parameters:

```
```C++
myMenu->Insert(
"mycmd",
[](std::ostream& out, const std::vector<std::string>& pars)
Expand All @@ -443,6 +443,20 @@ myMenu->Insert(
Please note that in this case your command handler must take *only one*
parameter of type `std::vector<std::string>`.
## Enter and exit actions
You can add an enter action and/or an exit action (for example to print a welcome/goodbye message
every time a user opens/closes a session, even a remote one):
```C++
Cli cli(std::move(rootMenu));
cli.EnterAction(
[&enterActionDone](std::ostream& out) { out << "Welcome\n"; });
cli.ExitAction(
[&enterActionDone](std::ostream& out) { out << "Goodbye\n"; });
```


## License

Distributed under the Boost Software License, Version 1.0.
Expand Down
12 changes: 5 additions & 7 deletions include/cli/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,14 @@ namespace cli

void EnterAction(std::ostream& out)
{
if (enterAction) {
if (enterAction)
enterAction(out);
}
}

void ExitAction( std::ostream& out )
void ExitAction(std::ostream& out)
{
if ( exitAction )
exitAction( out );
if (exitAction)
exitAction(out);
}

void StdExceptionHandler(std::ostream& out, const std::string& cmd, const std::exception& e)
Expand Down Expand Up @@ -318,9 +317,8 @@ namespace cli
{
cli.EnterAction(out);

if (enterAction) {
if (enterAction)
enterAction(out);
}
}

void Exit()
Expand Down

0 comments on commit 31ff1b9

Please sign in to comment.