Prepare compression implementation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Remove bailout on non-archive argument. Extract extraction and compression into two conditionally called methods.
This commit is contained in:
parent
7058c326c6
commit
9230a606ae
2 changed files with 26 additions and 16 deletions
39
src/main.cpp
39
src/main.cpp
|
@ -1,6 +1,5 @@
|
|||
#include <spdlog/common.h>
|
||||
#include <cstdlib>
|
||||
namespace logger = spdlog;
|
||||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
@ -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); }
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue