diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 9d22453..43726e8 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -457,6 +457,7 @@ try handler.prepareOptions(common_args); catch (Exception e) { + if (options.noColors) setLoggingColorsEnabled(false); logError("Error processing arguments: %s", e.msg); logDiagnostic("Full exception: %s", e.toString().sanitize); logInfo("Run 'dub help' for usage information."); @@ -537,7 +538,7 @@ */ struct CommonOptions { bool verbose, vverbose, quiet, vquiet, verror, version_; - bool help, annotate, bare; + bool help, annotate, bare, noColors; string[] registry_urls; string root_path; SkipPackageSuppliers skipRegistry = SkipPackageSuppliers.none; @@ -567,6 +568,7 @@ args.getopt("q|quiet", &quiet, ["Only print warnings and errors"]); args.getopt("verror", &verror, ["Only print errors"]); args.getopt("vquiet", &vquiet, ["Print no messages"]); + args.getopt("no-colors", &noColors, ["Disable color output"]); args.getopt("cache", &placementLocation, ["Puts any fetched packages in the specified location [local|system|user]."]); version_ = args.hasAppVersion; diff --git a/source/dub/logging.d b/source/dub/logging.d index 41f0781..9865e8a 100644 --- a/source/dub/logging.d +++ b/source/dub/logging.d @@ -4,7 +4,7 @@ and stderr are not a TTY in order to avoid ASCII escape sequences in piped output. The module can autodetect and configure itself in this regard by calling initLogging() at the beginning of the program. But, whether to color - text or not can also be set manually with printColorsInLog(bool). + text or not can also be set manually with setLoggingColorsEnabled(bool). The output for the log levels error, warn and info is formatted like this: @@ -38,8 +38,9 @@ The log(..) function can also be used. Check the signature and documentation of the functions for more information. - The minimum log level to print can be configured using setLogLevel(..), and - whether to color outputted text or not can be set with printColorsInLog(..). + The minimum log level to print can be configured using setLogLevel(..), + and whether to color outputted text or not can be set with + setLoggingColorsEnabled(..) The color(str, color) function can be used to color text within a log message, for instance like this: @@ -157,7 +158,7 @@ } /// Set whether to print colors or not -void printColorsInLog(bool enabled) +void setLoggingColorsEnabled(bool enabled) { _printColors = enabled; }