diff options
author | Quentin Monnet <quentin.monnet@6wind.com> | 2016-03-02 15:56:16 +0100 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2016-03-18 14:01:30 -0700 |
commit | 20174b74619bfe85fa8e4948a368e3600b557412 (patch) | |
tree | 04b63565bc54aeaee7899fea7d461ea94a92e149 /utilities | |
parent | 3e76999536ec0615681df70efd243774cf4da82a (diff) | |
download | openvswitch-20174b74619bfe85fa8e4948a368e3600b557412.tar.gz |
ovs-ofctl: Add option for color output to dump-flows command.
Add an option to ovs-ofctl utility so as to obtain colorized output in
tty, for easier reading. Currently, only the dump-flows command supports
colors.
A new `--color` option has been added to ovs-ofctl so as to indicate
whether color markers should be used or not. It can be set to `always`
(force colors), `never` (no colors) or `auto` (use colors only if output
is a tty). If provided without any value, it is the same as `auto`. If
the option is not provided at all, colors are disabled by default.
Examples:
This first call will output colorized flows:
ovs-ofctl dump-flows br0 --color=always
These two calls will produce colorized output on a tty, but they will
not use color markers if the output is redirected to a file or piped
into another command:
ovs-ofctl dump-flows br0 --color=auto
ovs-ofctl dump-flows br0 --color
These two calls will not use color markers:
ovs-ofctl dump-flows br0 --color=never
ovs-ofctl dump-flows br0
The result of this option is stored into a variable which is to be
forwarded (in next commits) as a function argument until it reaches the
functions that print the elements of the flows.
Signed-off-by: Quentin Monnet <quentin.monnet@6wind.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'utilities')
-rw-r--r-- | utilities/ovs-ofctl.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index 7bcfc66a3..db59ff671 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -75,6 +75,9 @@ VLOG_DEFINE_THIS_MODULE(ofctl); */ static bool bundle = false; +/* --color: Use color markers. */ +static bool enable_color; + /* --strict: Use strict matching for flow mod commands? Additionally governs * use of nx_pull_match() instead of nx_pull_match_loose() in parse-nx-match. */ @@ -170,6 +173,7 @@ parse_options(int argc, char *argv[]) OPT_RSORT, OPT_UNIXCTL, OPT_BUNDLE, + OPT_COLOR, DAEMON_OPTION_ENUMS, OFP_VERSION_OPTION_ENUMS, VLOG_OPTION_ENUMS @@ -188,6 +192,7 @@ parse_options(int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"option", no_argument, NULL, 'o'}, {"bundle", no_argument, NULL, OPT_BUNDLE}, + {"color", optional_argument, NULL, OPT_COLOR}, DAEMON_LONG_OPTIONS, OFP_VERSION_LONG_OPTIONS, VLOG_LONG_OPTIONS, @@ -289,6 +294,30 @@ parse_options(int argc, char *argv[]) unixctl_path = optarg; break; + case OPT_COLOR: + if (optarg) { + if (!strcasecmp(optarg, "always") + || !strcasecmp(optarg, "yes") + || !strcasecmp(optarg, "force")) { + enable_color = true; + } else if (!strcasecmp(optarg, "never") + || !strcasecmp(optarg, "no") + || !strcasecmp(optarg, "none")) { + enable_color = false; + } else if (!strcasecmp(optarg, "auto") + || !strcasecmp(optarg, "tty") + || !strcasecmp(optarg, "if-tty")) { + /* Determine whether we need colors, i.e. whether standard + * output is a tty. */ + enable_color = is_stdout_a_tty(); + } else { + ovs_fatal(0, "incorrect value `%s' for --color", optarg); + } + } else { + enable_color = is_stdout_a_tty(); + } + break; + DAEMON_OPTION_HANDLERS OFP_VERSION_OPTION_HANDLERS VLOG_OPTION_HANDLERS @@ -417,6 +446,7 @@ usage(void) " --sort[=field] sort in ascending order\n" " --rsort[=field] sort in descending order\n" " --unixctl=SOCKET set control socket name\n" + " --color[=always|never|auto] control use of color in output\n" " -h, --help display this help message\n" " -V, --version display version information\n"); exit(EXIT_SUCCESS); |