]> sourceware.org Git - systemtap.git/commitdiff
PR14927: lay groundwork for colors
authorJonathan Lebon <jlebon@redhat.com>
Fri, 21 Jun 2013 15:34:47 +0000 (11:34 -0400)
committerJonathan Lebon <jlebon@redhat.com>
Fri, 28 Jun 2013 14:26:59 +0000 (10:26 -0400)
Created a new command-line option '--color' which is capable of taking
in an argument as well. Added a new member 'color_errors' to the
systemtap_session class which gets set upon treating the new switch's
logic. Also created an entry in the man page.

cmdline.cxx
cmdline.h
man/stap.1
session.cxx
session.h

index 8fe12f1ef91b84e1a3295af3d3906d97ac4db560..7392dea8978a168e5291e69c933c89391b1babb2 100644 (file)
@@ -56,5 +56,7 @@ struct option stap_long_options[] = {
   { "dyninst", 0, NULL, LONG_OPT_RUNTIME_DYNINST },
   { "benchmark-sdt-loops", 1, NULL, LONG_OPT_BENCHMARK_SDT_LOOPS },
   { "benchmark-sdt-threads", 1, NULL, LONG_OPT_BENCHMARK_SDT_THREADS },
+  { "color", 2, NULL, LONG_OPT_COLOR_ERRS },
+  { "colour", 2, NULL, LONG_OPT_COLOR_ERRS },
   { NULL, 0, NULL, 0 }
 };
index c551e7f5ebf57fabdde7f30f3971f6c65a536694..e729ac33b292687ab7f030bc7f58e88458cde8de 100644 (file)
--- a/cmdline.h
+++ b/cmdline.h
@@ -55,6 +55,7 @@ enum {
   LONG_OPT_RUNTIME_DYNINST,
   LONG_OPT_BENCHMARK_SDT_LOOPS,
   LONG_OPT_BENCHMARK_SDT_THREADS,
+  LONG_OPT_COLOR_ERRS,
 };
 
 // NB: when adding new options, consider very carefully whether they
index 806ed45b922533004b4a13ef0b4eae89c38ebec5..1e96983d158196b1c3458fc4cfe8c6f5fb990176 100644 (file)
@@ -293,6 +293,12 @@ done automatically after successful runs, but this option will trigger the
 cleanup manually and then exit.  See the CACHING section for more details about
 cache limits.
 
+.TP
+\fB\-\-color\fR[=\fIWHEN\fR], \fB\-\-colour\fR[=\fIWHEN\fR]
+This option enables colored error messages, which is turned off by default.
+WHEN can be either 'never', 'always', or 'auto' (i.e. enable only if at a
+terminal). Defaults to 'auto' if not specified.
+
 .TP
 .BI \-\-disable\-cache
 This option disables all use of the cache directory.  No files will be either
index 9364e1071603073120b53461e4029438d364dd21..aa74391570e93f5d2a55a8cd58348bfa0c8a887e 100644 (file)
@@ -161,6 +161,7 @@ systemtap_session::systemtap_session ():
   sysroot = "";
   update_release_sysroot = false;
   suppress_time_limits = false;
+  color_errors = false;
 
   // PR12443: put compiled-in / -I paths in front, to be preferred during 
   // tapset duplicate-file elimination
@@ -334,6 +335,7 @@ systemtap_session::systemtap_session (const systemtap_session& other,
   update_release_sysroot = other.update_release_sysroot;
   sysenv = other.sysenv;
   suppress_time_limits = other.suppress_time_limits;
+  color_errors = other.color_errors;
 
   include_path = other.include_path;
   runtime_path = other.runtime_path;
@@ -1274,6 +1276,18 @@ systemtap_session::parse_cmdline (int argc, char * const argv [])
           benchmark_sdt_threads = strtoul(optarg, NULL, 10);
           break;
 
+        case LONG_OPT_COLOR_ERRS:
+          if (optarg && strcmp(optarg, "auto")
+                     && strcmp(optarg, "never")
+                     && strcmp(optarg, "always")) {
+            cerr << _F("Invalid argument '%s' for --color.", optarg) << endl;
+            return 1;
+          }
+          // --color without arg is equivalent to auto
+          color_errors = ((optarg && !strcmp(optarg, "always"))
+                || ((!optarg || !strcmp(optarg, "auto")) && isatty(STDERR_FILENO)));
+          break;
+
        case '?':
          // Invalid/unrecognized option given or argument required, but
          // not given. In both cases getopt_long() will have printed the
index 952e938e73a08a349895205743cd2ff653edde40..e742b02407655d8e99aeef32ee86eee4018756a8 100644 (file)
--- a/session.h
+++ b/session.h
@@ -213,6 +213,7 @@ public:
   int download_dbinfo;
   bool suppress_handler_errors;
   bool suppress_time_limits;
+  bool color_errors;
 
   enum { kernel_runtime, dyninst_runtime } runtime_mode;
   bool runtime_usermode_p() const { return runtime_mode == dyninst_runtime; }
This page took 0.038239 seconds and 5 git commands to generate.