[PATCH 1/2] irqtop: use standard 'always/never' arguments instead of 'enable/disable'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Most other util-linux tools that accept the option argument "auto"
additionally accept "always" and "never", not "enable" / "disable".

So, make option --cpu-stat accept those standard words (besides the
deviant ones), and adjust the documentation to use the standard words.

Furthermore, make --cpu-stat accept also "on", "off", "yes", "no",
"1", and "0", to allow the user to use shorter words.  The per-CPU
stats can now be suppressed with a succinct: `irqtop -c0`.

CC: Zhenwei Pi <pizhenwei@xxxxxxxxxxxxx>
Signed-off-by: Benno Schulenberg <bensberg@xxxxxxxxxx>
---
 bash-completion/irqtop  |  2 +-
 sys-utils/irqtop.1.adoc |  6 ++++--
 sys-utils/irqtop.c      | 11 +++++------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/bash-completion/irqtop b/bash-completion/irqtop
index 5faf122e5..0dd2f1981 100644
--- a/bash-completion/irqtop
+++ b/bash-completion/irqtop
@@ -9,7 +9,7 @@ _irqtop_module()
 			return 0
 			;;
 		'-c'|'--cpu-stat')
-			COMPREPLY=( $(compgen -W "auto enable disable" -- $cur) )
+			COMPREPLY=( $(compgen -W "auto enable disable always never" -- $cur) )
 			return 0
 			;;
 		'-C'|'--cpu-list')
diff --git a/sys-utils/irqtop.1.adoc b/sys-utils/irqtop.1.adoc
index cf258d085..63675f076 100644
--- a/sys-utils/irqtop.1.adoc
+++ b/sys-utils/irqtop.1.adoc
@@ -29,8 +29,10 @@ Specify which output columns to print. Use *--help* to get a list of all support
 Send the produced tables to stdout instead of to a static screen.
 This can be used for sending the output to other programs or to a file.
 
-*-c*, *--cpu-stat* _mode_::
-Show per-cpu statistics by specified mode. Available modes are: *auto*, *enable*, *disable*. The default option *auto* detects the width of window, then shows the per-cpu statistics if the width of window is large enough to show a full line of statistics.
+*-c*, *--cpu-stat* _when_::
+Whether to show the per-CPU statistics. Possible arguments are: *auto*, *never*, *always*.
+The default is *auto*: the per-CPU statistics are shown when the window is wide enough
+for the full list of CPUs.
 
 *-C*, *--cpu-list* _list_::
 Specify cpus in list format to show.
diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c
index 3dbd030e0..51e04ee85 100644
--- a/sys-utils/irqtop.c
+++ b/sys-utils/irqtop.c
@@ -307,7 +307,7 @@ static void __attribute__((__noreturn__)) usage(void)
 
 	fputs(USAGE_OPTIONS, stdout);
 	fputs(_(" -b, --batch            send tables to stdout, not to a static screen\n"), stdout);
-	fputs(_(" -c, --cpu-stat <mode>  whether to show the per-cpu stats (auto|enable|disable)\n"), stdout);
+	fputs(_(" -c, --cpu-stat <when>  whether to show the per-cpu stats (auto|never|always)\n"), stdout);
 	fputs(_(" -C, --cpu-list <list>  show IRQs only for the specified cpus\n"), stdout);
 	fputs(_(" -d, --delay <secs>     wait this number of seconds between updates\n"), stdout);
 	fputs(_(" -J, --json             use JSON output format (implies --batch)\n"), stdout);
@@ -364,12 +364,11 @@ static void parse_args(	struct irqtop_ctl *ctl,
 		case 'c':
 			if (!strcmp(optarg, "auto"))
 				ctl->cpustat_mode = IRQTOP_CPUSTAT_AUTO;
-			else if (!strcmp(optarg, "enable"))
-				ctl->cpustat_mode = IRQTOP_CPUSTAT_ENABLE;
-			else if (!strcmp(optarg, "disable"))
-				ctl->cpustat_mode = IRQTOP_CPUSTAT_DISABLE;
 			else
-				errx(EXIT_FAILURE, _("unsupported mode '%s'"), optarg);
+				ctl->cpustat_mode = IRQTOP_CPUSTAT_DISABLE - parse_switch(optarg,
+							_("unsupported argument"), "yes", "no",
+							"always", "never", "enable", "disable",
+							"on", "off", "1", "0", NULL);
 			break;
 		case 'C':
 			{
-- 
2.48.1





[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux