Skip to content

Commit fea8f2c

Browse files
author
Daniele Pallastrelli
committed
Submenu direct commands
1 parent 68d86e4 commit fea8f2c

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

cli/cli.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,18 @@ namespace cli
344344
{
345345
if ( cmdLine[ 0 ] == Name() )
346346
{
347-
session.Current( this );
348-
return true;
347+
if ( cmdLine.size() == 1 )
348+
{
349+
session.Current( this );
350+
return true;
351+
}
352+
else
353+
{
354+
// check also for subcommands
355+
std::vector<std::string > subCmdLine( cmdLine.begin()+1, cmdLine.end() );
356+
for ( auto& cmd: cmds )
357+
if ( cmd -> Exec( subCmdLine, session ) ) return true;
358+
}
349359
}
350360
return false;
351361
}

samples/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ int main()
6262
"hello",
6363
[](std::ostream& out){ out << "Hello, submenu world\n"; },
6464
"Print hello world in the submenu" );
65+
66+
auto subSubMenu = make_unique< Menu >( "subsub" );
67+
subSubMenu -> Add(
68+
"hello",
69+
[](std::ostream& out){ out << "Hello, subsubmenu world\n"; },
70+
"Print hello world in the sub-submenu" );
71+
subMenu -> Add( std::move(subSubMenu));
72+
6573
rootMenu -> Add( std::move(subMenu) );
6674

6775

0 commit comments

Comments
 (0)