MCPcopy Create free account
hub / github.com/daniele77/cli / main

Function main

examples/filesession.cpp:38–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38int main()
39{
40 // setup cli
41
42 auto rootMenu = make_unique< Menu >( "cli" );
43 rootMenu -> Insert(
44 "hello",
45 [](std::ostream& out){ out << "Hello, world\n"; },
46 "Print hello world" );
47 rootMenu -> Insert(
48 "hello_everysession",
49 [](std::ostream&){ Cli::cout() << "Hello, everybody" << std::endl; },
50 "Print hello everybody on all open sessions" );
51 rootMenu -> Insert(
52 "answer",
53 [](std::ostream& out, int x){ out << "The answer is: " << x << "\n"; },
54 "Print the answer to Life, the Universe and Everything " );
55 rootMenu -> Insert(
56 "color",
57 [](std::ostream& out){ out << "Colors ON\n"; SetColor(); },
58 "Enable colors in the cli" );
59 rootMenu -> Insert(
60 "nocolor",
61 [](std::ostream& out){ out << "Colors OFF\n"; SetNoColor(); },
62 "Disable colors in the cli" );
63
64 auto subMenu = make_unique< Menu >( "sub" );
65 subMenu -> Insert(
66 "hello",
67 [](std::ostream& out){ out << "Hello, submenu world\n"; },
68 "Print hello world in the submenu" );
69 subMenu -> Insert(
70 "demo",
71 [](std::ostream& out){ out << "This is a sample!\n"; },
72 "Print a demo string" );
73
74 auto subSubMenu = make_unique< Menu >( "subsub" );
75 subSubMenu -> Insert(
76 "hello",
77 [](std::ostream& out){ out << "Hello, subsubmenu world\n"; },
78 "Print hello world in the sub-submenu" );
79 subMenu -> Insert(std::move(subSubMenu));
80
81 rootMenu -> Insert(std::move(subMenu));
82
83
84 Cli cli( std::move(rootMenu) );
85 // global exit action
86 cli.ExitAction( [](auto& out){ out << "Goodbye and thanks for all the fish.\n"; } );
87
88 std::ifstream infile("input.txt");
89 if (!infile)
90 {
91 std::cerr << "File input.txt not found in current directory!\n";
92 return 1;
93 }
94 std::ofstream outfile("output.txt");
95 if (!outfile)

Callers

nothing calls this directly

Calls 5

SetColorFunction · 0.85
SetNoColorFunction · 0.85
InsertMethod · 0.45
ExitActionMethod · 0.45
StartMethod · 0.45

Tested by

no test coverage detected