Skip to content

Commit 2b0fb4b

Browse files
committed
Updating command line display
1 parent 01aac9a commit 2b0fb4b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

dependencies.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"argum": {
3-
"version": "521524bd56692f62a0c1bcf1c7ec0295feb9bb34",
3+
"version": "60b5687c48db889d27d0e97d62065bfe3f916a1e",
44
"url": "https://github.com/gershnik/argum/tarball/${version}",
55
"homepage": "https://github.com/gershnik/argum",
6-
"sha256": "a1e02a6bfd515af95acc5ebca0a90a58bea2ceea4bea7e6e28c1efdd681baac1",
7-
"md5": "da11ade8bab8cabbbcfe121bb805895c"
6+
"sha256": "45dca7e68eb08093e738e778f588c75a35f0f8f30cd9e8e2e45b75fcdee1d1ce",
7+
"md5": "be79f48e21b79c7d4ef4d9bba13b0e89"
88
},
99
"asio": {
1010
"version": "1.36.0",

src/command_line.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,17 @@ static auto setChrootDir(CommandLine & cmdline, std::string_view val) {
199199

200200
void CommandLine::parse(int argc, char * argv[]) {
201201

202-
const char * progname = (argc ? argv[0] : WSDDN_PROGNAME);
202+
const char * const progname = (argc ? argv[0] : WSDDN_PROGNAME);
203+
ColorStatus envColorStatus = environmentColorStatus();
203204

204205
Argum::Parser parser;
205206
//Program options
206207
parser.add(Option("--help", "-h").
207208
help("show this help message and exit").
208209
handler([&]() {
209-
fmt::print("{}", parser.formatHelp(progname).c_str());
210+
211+
auto colorizer = colorizerForFile(envColorStatus, stdout);
212+
fmt::print("{}", parser.formatHelp(progname, terminalWidth(stdout), colorizer));
210213
exit(EXIT_SUCCESS);
211214
}));
212215
parser.add(Option("--version", "-v").
@@ -335,7 +338,7 @@ void CommandLine::parse(int argc, char * argv[]) {
335338
//Behavior options
336339
parser.add(Option("--log-level").
337340
argName("LEVEL").
338-
help("set log level (default = 4). Log levels range from 0 (disable logging) to 6 (detailed trace)."
341+
help("set log level (default = 4). Log levels range from 0 (disable logging) to 6 (detailed trace).\n"
339342
"Passing values bigger than 6 is equivalent to 6").
340343
occurs(Argum::neverOrOnce).
341344
handler([this](std::string_view val){
@@ -386,8 +389,9 @@ void CommandLine::parse(int argc, char * argv[]) {
386389
try {
387390
parser.parse(argc, argv);
388391
} catch (ParsingException & ex) {
389-
fmt::print(stderr, "{}\n\n", ex.message());
390-
fmt::print(stderr, "{}", parser.formatUsage(progname));
392+
auto colorizer = colorizerForFile(envColorStatus, stderr);
393+
fmt::print(stderr, "{}\n\n", colorizer.error(ex.message()));
394+
fmt::print(stderr, "{}", parser.formatUsage(progname, terminalWidth(stderr), colorizer));
391395
exit(EXIT_FAILURE);
392396
}
393397
}

src/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <argum/parser.h>
3030
#include <argum/type-parsers.h>
3131
#include <argum/validators.h>
32+
#include <argum/detect-system.h>
3233

3334
#include <spdlog/fmt/fmt.h>
3435

0 commit comments

Comments
 (0)