兼容linux
This commit is contained in:
108
tests/main.cpp
108
tests/main.cpp
@@ -2,52 +2,88 @@
|
||||
#include <iostream>
|
||||
#include "core/entry.h"
|
||||
#include <filesystem>
|
||||
std::string config_filepath;
|
||||
void* fastweb_app_ptr = nullptr;
|
||||
void start()
|
||||
{
|
||||
fastweb_app_ptr = fastweb_start(config_filepath.c_str());
|
||||
}
|
||||
void close()
|
||||
{
|
||||
if(fastweb_app_ptr == nullptr)
|
||||
fastweb_close(fastweb_app_ptr);
|
||||
fastweb_app_ptr = nullptr;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
config_filepath = std::filesystem::current_path().string() + "/config.ini";
|
||||
#include "util/file.h"
|
||||
#include "util/strutils.h"
|
||||
#define QUIT_WAIT std::cout << "Please exit after entering any character...";std::cin.get();return -1
|
||||
|
||||
std::string input = "restart";
|
||||
while (true)
|
||||
void* start(const char* config_filepath)
|
||||
{
|
||||
return fastweb_start(config_filepath);
|
||||
}
|
||||
void close(void* app)
|
||||
{
|
||||
if(app == nullptr)
|
||||
fastweb_close(app);
|
||||
}
|
||||
void ouput_help()
|
||||
{
|
||||
std::cerr << "No configuration file path provided. Please provide the path to a config.ini file as an argument." << std::endl;
|
||||
|
||||
std::cout << "------------------------------------------------------------------------------" << std::endl;
|
||||
std::cout << "| The instructions are as follows:" << std::endl;
|
||||
std::cout << "| 1、fastweb start config.ini\t\t [load the specified configuration and start Fastweb]" << std::endl;
|
||||
std::cout << "| 2、fastweb create config .\t\t [create a default configuration file]" << std::endl;
|
||||
std::cout << "| 3、fastweb create website .\t\t [create a default website directory]" << std::endl;
|
||||
std::cout << "------------------------------------------------------------------------------" << std::endl;
|
||||
}
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2) { ouput_help(); QUIT_WAIT; }
|
||||
std::string type = argv[1];
|
||||
if (type == "help")
|
||||
{
|
||||
if (input == "restart")
|
||||
ouput_help();
|
||||
QUIT_WAIT;
|
||||
}
|
||||
|
||||
if (argc < 3){ouput_help();QUIT_WAIT;}
|
||||
|
||||
void* app = nullptr;
|
||||
std::string value = argv[2];
|
||||
if (type == "start")
|
||||
{
|
||||
if (ylib::file::exist(std::filesystem::absolute(value).string()))
|
||||
{
|
||||
std::cout << "closing..." << std::endl;
|
||||
close();
|
||||
std::cout << "starting..." << std::endl;
|
||||
start();
|
||||
if (fastweb_app_ptr == nullptr)
|
||||
app = start(std::filesystem::absolute(value).string().c_str());
|
||||
if (app == nullptr)
|
||||
{
|
||||
std::cin.get();
|
||||
return -1;
|
||||
QUIT_WAIT;
|
||||
}
|
||||
while (true) {
|
||||
std::string input;
|
||||
std::cin >> input;
|
||||
if (input == "quit" || input == "exit")
|
||||
{
|
||||
close(app);
|
||||
std::cout << "closed";
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Enter \"quit\" or \"exit\" to exit the application" << std::endl;
|
||||
std::cout << "Enter \"restart\" to restart the application" << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << "started" << std::endl;
|
||||
}
|
||||
else if (input == "quit" || input == "exit")
|
||||
{
|
||||
close();
|
||||
std::cout << "closed";
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Enter \"quit\" or \"exit\" to exit the application" << std::endl;
|
||||
std::cout << "Enter \"restart\" to restart the application" << std::endl;
|
||||
std::cerr << "file not found: " << std::filesystem::absolute(value).string() << std::endl;
|
||||
QUIT_WAIT;
|
||||
}
|
||||
}
|
||||
if (argc < 4) { ouput_help(); QUIT_WAIT; }
|
||||
|
||||
|
||||
std::cin >> input;
|
||||
if (type == "create")
|
||||
{
|
||||
std::string path = std::filesystem::absolute(argv[3]).string();
|
||||
if (value == "config")
|
||||
{
|
||||
ylib::file::copy("/usr/local/share/fastweb/config.ini",path);
|
||||
}
|
||||
else if (value == "website")
|
||||
{
|
||||
ylib::file::copy_dir("/usr/local/share/fastweb", path);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user