Skip to content

Commit e1a2916

Browse files
committed
Modified --help command
1 parent 60d6f06 commit e1a2916

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

httpserver.userprefs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<Properties>
2-
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release" />
3-
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/Server.cpp">
2+
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3+
<MonoDevelop.Ide.Workbench ActiveDocument="httpserver/Server.h">
44
<Files>
5-
<File FileName="httpserver/Server.cpp" Line="1085" Column="4" />
6-
<File FileName="httpserver/Server.h" Line="1" Column="1" />
7-
<File FileName="httpserver/Main.cpp" Line="1" Column="1" />
5+
<File FileName="httpserver/Server.cpp" Line="1360" Column="6" />
6+
<File FileName="httpserver/Server.h" Line="74" Column="3" />
7+
<File FileName="httpserver/Main.cpp" Line="12" Column="4" />
88
<File FileName="httpserver/Main.h" Line="1" Column="1" />
99
<File FileName="httpserver/DataVariantMultipartFormData.h" Line="1" Column="1" />
1010
<File FileName="httpserver/DataVariantMultipartFormData.cpp" Line="1" Column="1" />
@@ -14,17 +14,18 @@
1414
<File FileName="httpserver/DataVariantAbstract.h" Line="1" Column="1" />
1515
<File FileName="httpserver/DataVariantFormUrlencoded.h" Line="1" Column="1" />
1616
<File FileName="httpserver/DataVariantFormUrlencoded.cpp" Line="1" Column="1" />
17-
<File FileName="httpserver/ServerApplicationSettings.h" Line="1" Column="1" />
18-
<File FileName="httpserver/ServerApplicationsTree.h" Line="1" Column="1" />
19-
<File FileName="httpserver/ServerApplicationsTree.cpp" Line="1" Column="1" />
17+
<File FileName="httpserver/ServerApplicationSettings.h" Line="14" Column="12" />
18+
<File FileName="httpserver/ServerApplicationsTree.h" Line="32" Column="3" />
19+
<File FileName="httpserver/ServerApplicationsTree.cpp" Line="151" Column="4" />
2020
<File FileName="httpserver/System.h" Line="1" Column="1" />
2121
<File FileName="httpserver/DataVariantTextPlain.h" Line="1" Column="1" />
2222
<File FileName="httpserver/DataVariantTextPlain.cpp" Line="1" Column="1" />
2323
<File FileName="httpserver/System.cpp" Line="1" Column="1" />
2424
<File FileName="httpserver/Utils.h" Line="1" Column="1" />
2525
<File FileName="httpserver/Utils.cpp" Line="1" Column="1" />
26-
<File FileName="httpserver/Socket.cpp" Line="1" Column="1" />
26+
<File FileName="httpserver/Socket.cpp" Line="253" Column="21" />
2727
<File FileName="httpserver/Event.h" Line="1" Column="1" />
28+
<File FileName="httpserver/Socket.h" Line="59" Column="29" />
2829
</Files>
2930
</MonoDevelop.Ide.Workbench>
3031
<MonoDevelop.Ide.DebuggingService.Breakpoints>

httpserver/Main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
int main(const int argc, const char *argv[])
1010
{
11-
const std::unordered_map<std::string, std::function<int(HttpServer::Server &)> > commands {
11+
const std::unordered_map<std::string, std::function<int(HttpServer::Server *, const int, const char *[])> > commands {
1212
{"--help", std::mem_fn(&HttpServer::Server::help)},
1313
{"--start", std::mem_fn(&HttpServer::Server::start)},
1414
{"--restart", std::mem_fn(&HttpServer::Server::restart)},
@@ -17,7 +17,7 @@ int main(const int argc, const char *argv[])
1717

1818
int exitcode = EXIT_FAILURE;
1919

20-
if (2 == argc)
20+
if (1 < argc)
2121
{
2222
auto command = commands.find(argv[1]);
2323

@@ -27,7 +27,7 @@ int main(const int argc, const char *argv[])
2727

2828
if (bindSignalsHandles(&server) )
2929
{
30-
exitcode = command->second(server);
30+
exitcode = command->second(&server, argc, argv);
3131

3232
#ifdef WIN32
3333
System::sendSignal(GetCurrentProcessId(), SIGINT);
@@ -37,7 +37,7 @@ int main(const int argc, const char *argv[])
3737
}
3838
else
3939
{
40-
std::cout << "Unknown command" << std::endl;
40+
std::cout << "Unknown command, see --help" << std::endl;
4141
}
4242
}
4343
else if (1 == argc)
@@ -46,7 +46,7 @@ int main(const int argc, const char *argv[])
4646
}
4747
else
4848
{
49-
std::cout << "Arguments failure" << std::endl;
49+
std::cout << "Arguments failure, see --help command" << std::endl;
5050
}
5151

5252
return exitcode;

httpserver/Server.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "ServerResponse.h"
1212

1313
#include <iostream>
14+
#include <iomanip>
1415
#include <map>
1516
#include <thread>
1617
#include <fstream>
@@ -1356,9 +1357,13 @@ namespace HttpServer
13561357
}
13571358
}
13581359

1359-
int Server::help() const
1360+
int Server::help(const int argc, const char *argv[]) const
13601361
{
1361-
std::cout << "You call help command" << std::endl;
1362+
std::cout << "Available arguments:" << std::endl
1363+
<< std::setw(4) << ' ' << "--start" << '\t' << "Start http server" << std::endl
1364+
<< std::setw(4) << ' ' << "--restart" << '\t' << "Restart http server" << std::endl
1365+
<< std::setw(4) << ' ' << "--kill" << '\t' << "Shutdown http server" << std::endl
1366+
<< std::setw(4) << ' ' << "--help" << '\t' << "This help" << std::endl << std::endl;
13621367

13631368
return EXIT_SUCCESS;
13641369
}
@@ -1540,7 +1545,7 @@ namespace HttpServer
15401545
}
15411546
}
15421547

1543-
int Server::start()
1548+
int Server::start(const int argc, const char *argv[])
15441549
{
15451550
std::string pid_file_name = "httpserver.pid";
15461551

@@ -1601,7 +1606,7 @@ namespace HttpServer
16011606
return pid;
16021607
}
16031608

1604-
int Server::restart() const
1609+
int Server::restart(const int argc, const char *argv[]) const
16051610
{
16061611
const System::native_processid_type pid = getPidFromFile();
16071612

@@ -1613,7 +1618,7 @@ namespace HttpServer
16131618
return EXIT_FAILURE;
16141619
}
16151620

1616-
int Server::terminate() const
1621+
int Server::terminate(const int argc, const char *argv[]) const
16171622
{
16181623
const System::native_processid_type pid = getPidFromFile();
16191624

httpserver/Server.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ namespace HttpServer
7272
restart_flag = true;
7373
}
7474

75-
int help() const;
76-
int start();
77-
int restart() const;
78-
int terminate() const;
75+
int help(const int argc, const char *argv[]) const;
76+
int start(const int argc, const char *argv[]);
77+
int restart(const int argc, const char *argv[]) const;
78+
int terminate(const int argc, const char *argv[]) const;
7979
};
8080
};

0 commit comments

Comments
 (0)