Skip to content

Commit

Permalink
Merge pull request tkeksa#3 from tkeksa/clap31
Browse files Browse the repository at this point in the history
Migrate to clap v3.1
  • Loading branch information
tkeksa committed Feb 19, 2022
2 parents 25f79c7 + d04c8ef commit 716bab2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ ctrl-pipe = ["async-api", "tokio/fs", "tokio-util/codec"]

[dependencies]
bytes = "1.1.0"
clap = "3.0.5"
clap = "3.1.0"
log = "0.4.14"
pcap-file = "1.1.1"
futures = { version = "0.3.19", optional = true }
tokio = { version = "1.15.0", optional = true }
tokio-util = { version = "0.6.9", optional = true }
futures = { version = "0.3.21", optional = true }
tokio = { version = "1.17.0", optional = true }
tokio-util = { version = "0.7.0", optional = true }

[dev-dependencies]
ctrlc = "3.2.1"
rand = "0.8.4"
rand = "0.8.5"
serialport = "4.0.1"
simplelog = "0.11.1"
futures = "0.3.19"
simplelog = "0.11.2"
futures = "0.3.21"
tokio-serial = "5.4.1"
tokio = { version = "1.15.0", features = ["macros", "rt-multi-thread"] }
tokio-util = { version = "0.6.9", features = ["codec"] }
tokio = { version = "1.17.0", features = ["macros", "rt-multi-thread"] }
tokio-util = { version = "0.7.0", features = ["codec"] }

[[example]]
name = "test_serial_dump"
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl From<clap::Error> for ExtcapError {
fn from(error: clap::Error) -> Self {
ExtcapError {
kind: ExtcapErrorKind::Clap,
message: format!("{:?}: {}", error.kind, error.to_string()),
message: format!("{:?}: {}", error.kind(), error),
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use std::fmt::Display;
use std::fs::File;
use std::io::{self, Stdout, Write};

use clap::{App, AppSettings, Arg, ArgGroup, ArgMatches};
use clap::{Arg, ArgGroup, ArgMatches, Command};
#[cfg(feature = "ctrl-pipe")]
use futures::future;
#[cfg(feature = "async-api")]
Expand Down Expand Up @@ -232,7 +232,7 @@ type TillCaptureResult<T> = Result<TillCaptureOutcome<T>, ExtcapError>;
#[derive(Default)]
pub struct Extcap<'a> {
step: ExtcapStep,
app: Option<App<'a>>,
app: Option<Command<'a>>,
app_args: HashSet<String>, // optional user arguments added from interfaces
matches: Option<ArgMatches>,
version: Option<String>,
Expand All @@ -248,8 +248,8 @@ pub struct Extcap<'a> {
impl<'a> Extcap<'a> {
/// Creates a new instance of an `Extcap` requiring a name.
pub fn new(name: &'a str) -> Self {
let app = App::new(name)
.setting(AppSettings::AllowNegativeNumbers)
let app = Command::new(name)
.allow_negative_numbers(true)
//.template(HELP_TEMPLATE)
.arg(
Arg::new(OPT_EXTCAP_VERSION)
Expand Down Expand Up @@ -321,13 +321,13 @@ impl<'a> Extcap<'a> {
&self.step
}

fn take_app(&mut self) -> App<'a> {
fn take_app(&mut self) -> Command<'a> {
self.app.take().expect("Extcap invalid state: already run")
}

fn update_app<F>(&mut self, f: F)
where
F: FnOnce(App<'a>) -> App<'a>,
F: FnOnce(Command<'a>) -> Command<'a>,
{
self.app = Some(f(self.take_app()));
}
Expand Down Expand Up @@ -531,9 +531,9 @@ impl<'a> Extcap<'a> {
// Save matches for listener
self.matches = match self.take_app().try_get_matches() {
Ok(m) => Some(m),
Err(cerr) => match cerr.kind {
Err(cerr) => match cerr.kind() {
clap::ErrorKind::DisplayHelp | clap::ErrorKind::DisplayVersion => {
print!("{}", cerr.to_string());
print!("{}", cerr);
return Ok(TillCaptureOutcome::Finish(()));
}
_ => return Err(cerr.into()),
Expand Down

0 comments on commit 716bab2

Please sign in to comment.