Skip to content

Commit 257a963

Browse files
committed
cli: Add -q/--quiet option
1 parent 1a09099 commit 257a963

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

src/cli/action_convert.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace opts
4646
static int width, height;
4747
static int nomips;
4848
static int toDX;
49+
static int quiet;
4950
} // namespace opts
5051

5152
static bool get_version_from_str(const std::string& str, int& major, int& minor);
@@ -226,6 +227,15 @@ const OptionList& ActionConvert::get_options() const {
226227
.value(false)
227228
.type(OptType::Bool)
228229
.help("Treat the incoming normal map as an OpenGL normal map"));
230+
231+
opts::quiet = opts.add(
232+
ActionOption()
233+
.long_opt("--quiet")
234+
.short_opt("-q")
235+
.value(false)
236+
.type(OptType::Bool)
237+
.help("Silence output messages that aren't errors")
238+
);
229239
};
230240
return opts;
231241
}
@@ -398,12 +408,14 @@ bool ActionConvert::process_file(
398408
}
399409

400410
// Report file sizes
401-
if (initialSize != 0) {
402-
fmt::print(
403-
"{} ({} bytes) -> {} ({} bytes)\n", srcFile.string(), initialSize, outFile.string(), vtfFile->GetSize());
404-
}
405-
else {
406-
fmt::print("{} -> {} ({} bytes)\n", srcFile.string(), outFile.string(), vtfFile->GetSize());
411+
if (!opts.get<bool>(opts::quiet)) {
412+
if (initialSize != 0) {
413+
fmt::print(
414+
"{} ({} KiB) -> {} ({} KiB)\n", srcFile.string(), initialSize / 1024, outFile.string(), vtfFile->GetSize() / 1024);
415+
}
416+
else {
417+
fmt::print("{} -> {} ({} KiB)\n", srcFile.string(), outFile.string(), vtfFile->GetSize() / 1024);
418+
}
407419
}
408420

409421
return true;
@@ -524,7 +536,7 @@ bool ActionConvert::add_image_data(
524536
// Hack for VTFLib; Ensure we have an alpha channel because that's well supported in that horrible code
525537
if (image->channels() < 4 && image->type() != imglib::ChannelType::UInt8) {
526538
if (!image->convert(image->type(), 4)) {
527-
std::cerr << fmt::format("Failed to convert {}\n", imageSrc.c_str());
539+
std::cerr << fmt::format("Failed to convert {}\n", imageSrc.string());
528540
return false;
529541
}
530542
}

src/cli/action_extract.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace opts
2424
static int mip;
2525
static int recursive;
2626
static int noalpha;
27+
static int quiet;
2728
} // namespace opts
2829

2930
std::string ActionExtract::get_help() const {
@@ -82,6 +83,15 @@ const OptionList& ActionExtract::get_options() const {
8283
.type(OptType::Bool)
8384
.value(false)
8485
.help("Exclude alpha channel from converted image"));
86+
87+
opts::quiet = opts.add(
88+
ActionOption()
89+
.short_opt("-q")
90+
.long_opt("--quiet")
91+
.type(OptType::Bool)
92+
.value(false)
93+
.help("Silence output messages that aren't errors")
94+
);
8595
};
8696
return opts;
8797
}
@@ -152,7 +162,8 @@ bool ActionExtract::extract_file(
152162
outFile = vtfPath.parent_path() / vtfPath.filename().replace_extension(ext);
153163
}
154164

155-
fmt::print("{} -> {}\n", vtfPath.string(), outFile.string());
165+
if (!opts.get<bool>(opts::quiet))
166+
fmt::print("{} -> {}\n", vtfPath.string(), outFile.string());
156167

157168
// Validate mipmap selection
158169
if (mip > file_->GetMipmapCount()) {

src/cli/action_pack.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace opts
3030
static int width, height, mips;
3131
static int mconst, rconst, aoconst, hconst;
3232
static int toDX;
33+
static int quiet;
3334
} // namespace opts
3435

3536
std::string ActionPack::get_help() const {
@@ -176,6 +177,15 @@ const OptionList& ActionPack::get_options() const {
176177
.value(false)
177178
.type(OptType::Bool)
178179
.help("Treat the incoming normal map as a OpenGL normal map"));
180+
181+
opts::quiet = opts.add(
182+
ActionOption()
183+
.long_opt("--quiet")
184+
.short_opt("-q")
185+
.value(false)
186+
.type(OptType::Bool)
187+
.help("Silence output messages that aren't errors")
188+
);
179189
};
180190
return opts;
181191
}
@@ -467,8 +477,8 @@ bool ActionPack::pack_normal(
467477

468478
success = save_vtf(outpath, outImage, opts, true);
469479

470-
if (success)
471-
std::cout << fmt::format("Finished processing {}\n", outpath.string());
480+
if (success && !opts.get<bool>(opts::quiet))
481+
std::cout << fmt::format("Finished {} ({} KiB)\n", outpath.string(), file_->GetSize() / 1024);
472482
return success;
473483
}
474484

0 commit comments

Comments
 (0)