Restructure CompressSingleIntent

This commit is contained in:
Armin Friedl 2024-03-02 15:16:19 +01:00
parent c8e6f51e1b
commit 92ac6586de
Signed by: armin
GPG key ID: 48C726EEE7FBCBC8
2 changed files with 18 additions and 14 deletions

View file

@ -180,21 +180,23 @@ void ExtractIntent::execute() {
} }
}; };
void CompressSingleIntent::execute() { path CompressSingleIntent::out_path() {
if (this->out.has_value()) { if (this->out.has_value()) {
if (!can_handle_archive(this->out.value())) { if (!can_handle_archive(this->out.value())) {
throw XwimError("Unknown archive format {}", this->out.value()); throw XwimError("Unknown archive format {}", this->out.value());
} }
unique_ptr<Archiver> archiver = make_archiver(this->out.value()); return this->out.value();
set<path> ins{this->in}; }
archiver->compress(ins, this->out.value());
} else { return default_archive(strip_archive_extension(this->in).stem());
path out = default_archive(strip_archive_extension(this->in).stem()); }
void CompressSingleIntent::execute() {
path out = this->out_path();
unique_ptr<Archiver> archiver = make_archiver(out); unique_ptr<Archiver> archiver = make_archiver(out);
set<path> ins{this->in}; set<path> ins{this->in};
archiver->compress(ins, out); archiver->compress(ins, out);
}
}; };
void CompressManyIntent::execute() { void CompressManyIntent::execute() {

View file

@ -57,6 +57,8 @@ private:
path in; path in;
optional<path> out; optional<path> out;
path out_path();
public: public:
CompressSingleIntent(path in, optional<path> out) : UserIntent(), in(in), out(out) {}; CompressSingleIntent(path in, optional<path> out) : UserIntent(), in(in), out(out) {};
~CompressSingleIntent() override = default; ~CompressSingleIntent() override = default;