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

Benno Schulenberg <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
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 <[email protected]>
Signed-off-by: Benno Schulenberg <[email protected]>
---
 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.