chiark / gitweb /
clap: Use ArgAction::Count for debug level
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 15 Jun 2023 18:41:41 +0000 (19:41 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 15 Jun 2023 20:15:29 +0000 (21:15 +0100)
Removes a deprecation warning (this is recommended by the clap 3 to 4
migration guide).

    Checking hippotat v1.1.7 (/volatile/rustcargo/Rustup/Hippotat/hippotat)
warning: use of deprecated function `<reporter::LogOpts as clap::Args>::augment_args::parse_from_occurrences`: Replaced with `#[clap(action = ArgAction::Count)]` with a field type of `u8`
  --> src/reporter.rs:18:33
   |
18 |   #[clap(long, short='D', parse(from_occurrences))]
   |                                 ^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/reporter.rs

index e12c6d2d430e026ca8ccc2c2cd220dfc5bf63b67..cc2d098a94dfacdf4d8fb4cdd6d6a9cd570c044e 100644 (file)
@@ -15,8 +15,8 @@ pub struct LogOpts {
   /// and two -`D` means to send to syslog even messages from lower layers
   /// (normally just the hippotat modules log to
   /// syslog).
-  #[clap(long, short='D', parse(from_occurrences))]
-  debug: usize,
+  #[clap(long, short='D', action=clap::ArgAction::Count)]
+  debug: u8,
 
   /// Syslog facility to use
   #[clap(long, parse(try_from_str=parse_syslog_facility))]
@@ -30,7 +30,7 @@ fn parse_syslog_facility(s: &str) -> syslog::Facility {
 
 #[derive(Debug)]
 struct LogWrapper<T>{
-  debug: usize,
+  debug: u8,
   output: T,
 }
 
@@ -112,7 +112,7 @@ impl LogOpts {
       logb.filter(Some("hippotat"),
                   *[ log::LevelFilter::Info,
                      log::LevelFilter::Debug ]
-                  .get(self.debug)
+                  .get(usize::from(self.debug))
                   .unwrap_or(
                     &log::LevelFilter::Trace
                   ));