Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update clap version to ^4.5 #466

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dbus-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ xml-rs = "0.8.3"
dbus = { path = "../dbus", version = "0.9", optional = true }
dbus-tree = { path = "../dbus-tree", version = "0.9", optional = true }
dbus-crossroads = { path = "../dbus-crossroads", version = "0.5", optional = true }
clap = { version = "2.20", optional = true }
clap = { version = "4.5", optional = true }

[badges]
maintenance = { status = "actively-developed" }


[[example]]
name = "adv_server_codegen"
required-features = ["dbus", "dbus-tree"]
Expand Down
58 changes: 29 additions & 29 deletions dbus-codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,50 @@ mod connect_to_dbus {
// Unwrapping is fine here, this is just a test program.

fn main() {
let app = clap::App::new("D-Bus Rust code generator").about("Generates Rust code from xml introspection data")
.arg(clap::Arg::with_name("interfaces").short("f").long("interfaces").takes_value(true).value_name("FILTER")
let app = clap::Command::new("D-Bus Rust code generator").about("Generates Rust code from xml introspection data")
.arg(clap::Arg::new("interfaces").short('f').long("interfaces").value_name("FILTER")
.help("Comma separated list of filter strings. Only matching interfaces are generated if set."))
.arg(clap::Arg::with_name("genericvariant").short("g").long("generic-variant")
.arg(clap::Arg::new("genericvariant").short('g').long("generic-variant").action(clap::ArgAction::SetTrue)
.help("If present, will try to make variant arguments generic instead of Variant<Box<dyn RefArg>>. \
Experimental, does not work with dbus-tree."))
.arg(clap::Arg::with_name("methodtype").short("m").long("methodtype").takes_value(true).value_name("Fn")
.arg(clap::Arg::new("methodtype").short('m').long("methodtype").value_name("Fn")
.help("Type of server method for dbus-tree; valid values are: 'Fn', 'FnMut', 'Sync', 'Generic', and 'None'. Defaults to 'None'."))
.arg(clap::Arg::with_name("methodaccess").short("a").long("methodaccess").takes_value(true).value_name("RefClosure")
.arg(clap::Arg::new("methodaccess").short('a').long("methodaccess").value_name("RefClosure")
.help("Specifies how to access the type implementing the interface for dbus-tree (experimental). Valid values are: 'RefClosure', 'AsRefClosure', 'MethodInfo'. \
Defaults to 'RefClosure'."))
.arg(clap::Arg::with_name("dbuscrate").long("dbuscrate").takes_value(true).value_name("dbus")
.arg(clap::Arg::new("dbuscrate").long("dbuscrate").value_name("dbus")
.help("Name of dbus crate, defaults to 'dbus'."))
.arg(clap::Arg::with_name("skipprefix").short("i").long("skipprefix").takes_value(true).value_name("PREFIX")
.arg(clap::Arg::new("skipprefix").short('i').long("skipprefix").value_name("PREFIX")
.help("If present, skips a specific prefix for interface names, e g 'org.freedesktop.DBus.'."))
.arg(clap::Arg::with_name("client").short("c").long("client").takes_value(true).value_name("client")
.arg(clap::Arg::new("client").short('c').long("client").value_name("client")
.help("Type of client connection. Valid values are: 'blocking', 'nonblock', 'ffidisp'."))
.arg(clap::Arg::with_name("propnewtype").short("n").long("prop-newtype")
.arg(clap::Arg::new("propnewtype").short('n').long("prop-newtype").action(clap::ArgAction::SetTrue)
.help("If present, will generate a struct wrapping PropMap to get properties from it with their expected types."))
.arg(clap::Arg::with_name("crossroads").short("r").long("crossroads")
.arg(clap::Arg::new("crossroads").short('r').long("crossroads").action(clap::ArgAction::SetTrue)
.help("Generate dbus-crossroads server code."))
.arg(clap::Arg::with_name("output").short("o").long("output").takes_value(true).value_name("FILE")
.arg(clap::Arg::new("output").short('o').long("output").value_name("FILE")
.help("Write output into the specified file"))
.arg(clap::Arg::with_name("file").long("file").required(false).takes_value(true).value_name("FILE")
.arg(clap::Arg::new("file").long("file").required(false).value_name("FILE")
.help("D-Bus XML Introspection file"));

#[cfg(feature = "dbus")]
let app = app
.arg(clap::Arg::with_name("destination").short("d").long("destination").takes_value(true).value_name("BUSNAME")
.arg(clap::Arg::new("destination").short('d').long("destination").value_name("BUSNAME")
.help("If present, connects to the supplied service to get introspection data. Reads from stdin otherwise."))
.arg(clap::Arg::with_name("path").short("p").long("path").takes_value(true).value_name("PATH")
.arg(clap::Arg::new("path").short('p').long("path").value_name("PATH")
.help("The path to ask for introspection data. Defaults to '/'. (Ignored if destination is not specified.)"))
.arg(clap::Arg::with_name("systembus").short("s").long("system-bus")
.arg(clap::Arg::new("systembus").short('s').long("system-bus").action(clap::ArgAction::SetTrue)
.help("Connects to system bus, if not specified, the session bus will be used. (Ignored if destination is not specified.)"));

let matches = app.get_matches();

let s = match (matches.value_of("destination"), matches.value_of("file")) {
let s = match (matches.get_one::<String>("destination"), matches.get_one::<String>("file")) {
(Some(_), Some(_)) => panic!("'destination' and 'file' are mutually exclusive arguments - you can't provide both"),
(None, Some(file_path)) => std::fs::read_to_string(file_path.to_string()).unwrap(),
(None, Some(file_path)) => std::fs::read_to_string(file_path.clone()).unwrap(),
#[cfg(feature = "dbus")]
(Some(dest), None) => {
let path = matches.value_of("path").unwrap_or("/");
connect_to_dbus::do_introspect(dest, path, matches.is_present("systembus"))
let path = matches.get_one::<String>("path").map(|s| &**s).unwrap_or("/");
connect_to_dbus::do_introspect(dest, path, matches.get_flag("systembus"))
},
#[cfg(not(feature = "dbus"))]
(Some(_), None) => unreachable!(),
Expand All @@ -85,9 +85,9 @@ Defaults to 'RefClosure'."))
}
};

let dbuscrate = matches.value_of("dbuscrate").unwrap_or("dbus");
let dbuscrate = matches.get_one::<String>("dbuscrate").map(|s| &**s).unwrap_or("dbus");

let mtype = matches.value_of("methodtype").map(|s| s.to_lowercase());
let mtype = matches.get_one::<String>("methodtype").map(|s| s.to_lowercase());
let mtype = match mtype.as_ref().map(|s| &**s) {
Some("fn") => Some("MTFn"),
Some("fnmut") => Some("MTFnMut"),
Expand All @@ -97,38 +97,38 @@ Defaults to 'RefClosure'."))
_ => panic!("Invalid methodtype specified"),
};

let maccess = matches.value_of("methodaccess").map(|s| s.to_lowercase());
let maccess = matches.get_one::<String>("methodaccess").map(|s| s.to_lowercase());
let maccess = match maccess.as_ref().map(|s| &**s) {
None | Some("refclosure") => ServerAccess::RefClosure,
Some("asrefclosure") => ServerAccess::AsRefClosure,
Some("methodinfo") => ServerAccess::MethodInfo,
_ => panic!("Invalid methodaccess specified"),
};

let client = matches.value_of("client").map(|s| s.to_lowercase());
let client = matches.get_one::<String>("client").map(|s| s.to_lowercase());
let client = match client.as_ref().map(|s| &**s) {
None | Some("blocking") => ConnectionType::Blocking,
Some("nonblock") => ConnectionType::Nonblock,
Some("ffidisp") => ConnectionType::Ffidisp,
_ => panic!("Invalid client connection type specified"),
};

let interfaces = matches.value_of("interfaces").map(|s| s.split(",").map(|e| e.trim().to_owned()).collect());
let interfaces = matches.get_one::<String>("interfaces").map(|s| s.split(",").map(|e| e.trim().to_owned()).collect());

let opts = generate::GenOpts {
methodtype: mtype.map(|x| x.into()),
dbuscrate: dbuscrate.into(),
skipprefix: matches.value_of("skipprefix").map(|x| x.into()),
skipprefix: matches.get_one::<String>("skipprefix").map(|x| x.into()),
serveraccess: maccess,
genericvariant: matches.is_present("genericvariant"),
genericvariant: matches.get_flag("genericvariant"),
connectiontype: client,
propnewtype: matches.is_present("propnewtype"),
crossroads: matches.is_present("crossroads"),
propnewtype: matches.get_flag("propnewtype"),
crossroads: matches.get_flag("crossroads"),
interfaces,
command_line: std::env::args().skip(1).collect::<Vec<String>>().join(" ")
};

let mut h: Box<dyn std::io::Write> = match matches.value_of("output") {
let mut h: Box<dyn std::io::Write> = match matches.get_one::<String>("output") {
Some(file_path) => Box::new(std::fs::File::create(file_path)
.unwrap_or_else(|e| {
panic!("Failed to open {}", e);
Expand Down
Loading