From ec4160f771c91297ffff181490b9ca0672aa5f4a Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 11 Sep 2013 11:51:57 +0000 Subject: [PATCH] sensors-detect: Rework option handling Rework the way command line options are handled. If we ever need more than this, we should consider moving to some GetOpt perl module. --- CHANGES | 1 + prog/detect/sensors-detect | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index d392de15..ca2d1cda 100644 --- a/CHANGES +++ b/CHANGES @@ -12,6 +12,7 @@ SVN HEAD Add a PCI ID for new family 15h AMD processors Introduce automatic mode (--auto) Detect incorrect non-interactive runs + Rework option handling 3.3.4 (2013-05-27) sensors.conf.5: Mention "sensors -u" to get the raw feature names diff --git a/prog/detect/sensors-detect b/prog/detect/sensors-detect index 34ef5347..a0f763b2 100755 --- a/prog/detect/sensors-detect +++ b/prog/detect/sensors-detect @@ -6824,14 +6824,22 @@ sub main { my ($input, $superio_features); - # Handle special command line cases first - if (defined $ARGV[0] && $ARGV[0] eq "--stat") { - show_i2c_stats(); - exit 0; + # Parse command line options + while (defined $ARGV[0]) { + if ($ARGV[0] eq "--stat") { + $opt{stat} = 1; + } elsif ($ARGV[0] eq "--auto") { + $opt{auto} = 1; + } else { + print STDERR "Error: unknown option $ARGV[0]\n"; + exit 1; + } + shift @ARGV; } - if (defined $ARGV[0] && $ARGV[0] eq "--auto") { - $opt{auto} = 1; + if ($opt{stat}) { + show_i2c_stats(); + exit 0; } # We won't go very far if not root