.
This commit is contained in:
84
src/main.cpp
Normal file
84
src/main.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include "dropshell.hpp"
|
||||
#include <iostream>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace po = boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
// Define command line options
|
||||
po::options_description desc("Usage: dropshell <command> [options]");
|
||||
desc.add_options()
|
||||
("help,h", "Show help message")
|
||||
("version,V", "Show version information")
|
||||
("command", po::value<std::string>(), "Command to execute")
|
||||
("directory", po::value<std::string>(), "Directory path for init command")
|
||||
("verbose,v", "Enable verbose output");
|
||||
|
||||
po::positional_options_description p;
|
||||
p.add("command", 1);
|
||||
p.add("directory", 1); // Add directory as a positional argument
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::command_line_parser(argc, argv)
|
||||
.options(desc)
|
||||
.positional(p)
|
||||
.run(), vm);
|
||||
po::notify(vm);
|
||||
|
||||
// Load configuration
|
||||
if (!dropshell::load_config()) {
|
||||
std::cerr << "Error: Failed to load configuration" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Handle commands
|
||||
if (vm.count("help") || (vm.count("command") && vm["command"].as<std::string>() == "help")) {
|
||||
dropshell::print_help(desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("version") || (vm.count("command") && vm["command"].as<std::string>() == "version")) {
|
||||
dropshell::print_version();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("command")) {
|
||||
std::string cmd = vm["command"].as<std::string>();
|
||||
if (cmd == "status") {
|
||||
dropshell::check_status();
|
||||
return 0;
|
||||
} else if (cmd == "servers") {
|
||||
dropshell::list_servers();
|
||||
return 0;
|
||||
} else if (cmd == "init") {
|
||||
if (!vm.count("directory")) {
|
||||
std::cerr << "Error: init command requires a directory argument" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
dropshell::init_user_directory(vm["directory"].as<std::string>());
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Error: Unknown command '" << cmd << "'" << std::endl;
|
||||
dropshell::print_help(desc);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// No command provided
|
||||
std::cerr << "Error: No command provided" << std::endl;
|
||||
dropshell::print_help(desc);
|
||||
return 1;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user