diff --git a/src/UserIntent.cpp b/src/UserIntent.cpp index 0316ff6..33f7ee4 100644 --- a/src/UserIntent.cpp +++ b/src/UserIntent.cpp @@ -180,21 +180,23 @@ void ExtractIntent::execute() { } }; -void CompressSingleIntent::execute() { - if (this->out.has_value()) { - if (!can_handle_archive(this->out.value())) { - throw XwimError("Unknown archive format {}", this->out.value()); - } +path CompressSingleIntent::out_path() { + if (this->out.has_value()) { + if (!can_handle_archive(this->out.value())) { + throw XwimError("Unknown archive format {}", this->out.value()); + } - unique_ptr archiver = make_archiver(this->out.value()); - set ins{this->in}; - archiver->compress(ins, this->out.value()); - } else { - path out = default_archive(strip_archive_extension(this->in).stem()); - unique_ptr archiver = make_archiver(out); - set ins{this->in}; - archiver->compress(ins, out); - } + return this->out.value(); + } + + return default_archive(strip_archive_extension(this->in).stem()); +} + +void CompressSingleIntent::execute() { + path out = this->out_path(); + unique_ptr archiver = make_archiver(out); + set ins{this->in}; + archiver->compress(ins, out); }; void CompressManyIntent::execute() { diff --git a/src/UserIntent.hpp b/src/UserIntent.hpp index 4750199..a305be0 100644 --- a/src/UserIntent.hpp +++ b/src/UserIntent.hpp @@ -57,6 +57,8 @@ private: path in; optional out; + path out_path(); + public: CompressSingleIntent(path in, optional out) : UserIntent(), in(in), out(out) {}; ~CompressSingleIntent() override = default;