diff --git a/src/main.cpp b/src/main.cpp index 745e778..01399c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include #include -namespace logger = spdlog; #include #include @@ -13,19 +12,10 @@ namespace logger = spdlog; #include "spec.hpp" #include "fileformats.hpp" -int main(int argc, char** argv) { - xwim::log::init(); - - xwim::argparse::XwimPath xwim_path; - - try { - xwim_path = xwim::argparse::parse(argc, argv); - } catch (xwim::argparse::ArgParseException& ex) { - logger::error("{}\n", ex.what()); - std::cout << xwim::argparse::usage(); - std::exit(1); - } +namespace logger = spdlog; +using namespace xwim::argparse; +void extract(const XwimPath& xwim_path) { try { xwim::Archive archive{xwim_path.path()}; xwim::ArchiveSpec archive_spec = archive.check(); @@ -54,3 +44,26 @@ int main(int argc, char** argv) { logger::error("{}", ae.what()); } } + +void compress(const XwimPath& xwim_path) { + return; +} + +XwimPath parse_args(int argc, char** argv) { + try { + return parse(argc, argv); + } catch (ArgParseException& ex) { + logger::error("{}\n", ex.what()); + std::cout << usage(); + std::exit(1); + } +} + +int main(int argc, char** argv) { + xwim::log::init(); + + XwimPath xwim_path = parse_args(argc, argv); + + if(xwim_path.is_archive()) { extract(xwim_path); } + else { compress(xwim_path); } +} diff --git a/src/util/argparse.cpp b/src/util/argparse.cpp index 0464ca6..30966a4 100644 --- a/src/util/argparse.cpp +++ b/src/util/argparse.cpp @@ -13,9 +13,6 @@ namespace argparse { if (argc > 2) throw ArgParseException{"Too many arguments provided"}; this->_path = std::filesystem::path{argv[1]}; - - // Remove when compression in place - if(!is_archive()) throw ArgParseException{"Not a known archive format"}; } bool XwimPath::is_archive() {