Skip to content

Commit ae20930

Browse files
committed
update to clap v4
1 parent b585e97 commit ae20930

File tree

3 files changed

+50
-39
lines changed

3 files changed

+50
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
- Update `clap` to 3.2, use `irx-config` instead of `clap_conf`
10+
- Update `clap` to 4.0, use `irx-config` instead of `clap_conf`
1111
- Add #[must_use] to prevent hanging field writers
1212

1313
## [v0.26.0] - 2022-10-07

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ json = ["dep:serde_json"]
4343
yaml = ["dep:serde_yaml"]
4444

4545
[dependencies]
46-
clap = { version = "3.2", optional = true }
47-
irx-config = { version = "2.3.1", features = ["cmd", "toml-parser"], optional = true }
46+
clap = { version = "4.0", optional = true }
47+
irx-config = { version = "3.1", features = ["cmd", "toml-parser"], optional = true }
4848
env_logger = { version = "0.9", optional = true }
4949
inflections = "1.1"
5050
log = { version = "~0.4", features = ["std"] }

src/main.rs

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::io::Write;
77
use std::process;
88

99
use anyhow::{Context, Result};
10-
use clap::{Arg, Command};
10+
use clap::{Arg, ArgAction, Command};
1111

1212
use svd2rust::{
1313
generate, load_from,
@@ -18,11 +18,7 @@ fn parse_configs(app: Command) -> Result<Config> {
1818
use irx_config::parsers::{cmd, toml};
1919
use irx_config::ConfigBuilder;
2020
let irxconfig = ConfigBuilder::default()
21-
.append_parser(
22-
cmd::ParserBuilder::new(app)
23-
.single_flags_as_bool(true)
24-
.build()?,
25-
)
21+
.append_parser(cmd::ParserBuilder::new(app).build()?)
2622
.append_parser(
2723
toml::ParserBuilder::default()
2824
.default_path("svd2rust.toml")
@@ -38,116 +34,131 @@ fn parse_configs(app: Command) -> Result<Config> {
3834
fn run() -> Result<()> {
3935
use std::io::Read;
4036

41-
let log_help = format!(
42-
"Choose which messages to log (overrides {})",
43-
env_logger::DEFAULT_FILTER_ENV
44-
);
45-
4637
let app = Command::new("svd2rust")
4738
.about("Generate a Rust API from SVD files")
4839
.arg(
49-
Arg::with_name("input")
40+
Arg::new("input")
5041
.help("Input SVD file")
5142
.short('i')
52-
.takes_value(true)
43+
.action(ArgAction::Set)
5344
.value_name("FILE"),
5445
)
5546
.arg(
56-
Arg::with_name("output_dir")
47+
Arg::new("output_dir")
5748
.long("output-dir")
5849
.help("Directory to place generated files")
5950
.short('o')
60-
.takes_value(true)
51+
.action(ArgAction::Set)
6152
.value_name("PATH"),
6253
)
6354
.arg(
64-
Arg::with_name("config")
55+
Arg::new("config")
6556
.long("config")
6657
.help("Config TOML file")
6758
.short('c')
68-
.takes_value(true)
59+
.action(ArgAction::Set)
6960
.value_name("TOML_FILE"),
7061
)
7162
.arg(
72-
Arg::with_name("target")
63+
Arg::new("target")
7364
.long("target")
7465
.help("Target architecture")
75-
.takes_value(true)
66+
.action(ArgAction::Set)
7667
.value_name("ARCH"),
7768
)
7869
.arg(
79-
Arg::with_name("nightly")
70+
Arg::new("nightly")
8071
.long("nightly")
72+
.action(ArgAction::SetTrue)
8173
.help("Enable features only available to nightly rustc"),
8274
)
8375
.arg(
84-
Arg::with_name("const_generic").long("const_generic").help(
76+
Arg::new("const_generic")
77+
.long("const_generic")
78+
.action(ArgAction::SetTrue)
79+
.help(
8580
"Use const generics to generate writers for same fields with different offsets",
8681
),
8782
)
8883
.arg(
89-
Arg::with_name("ignore_groups")
84+
Arg::new("ignore_groups")
9085
.long("ignore_groups")
86+
.action(ArgAction::SetTrue)
9187
.help("Don't add alternateGroup name as prefix to register name"),
9288
)
93-
.arg(Arg::with_name("keep_list").long("keep_list").help(
89+
.arg(
90+
Arg::new("keep_list")
91+
.long("keep_list")
92+
.action(ArgAction::SetTrue)
93+
.help(
9494
"Keep lists when generating code of dimElement, instead of trying to generate arrays",
9595
))
9696
.arg(
97-
Arg::with_name("generic_mod")
97+
Arg::new("generic_mod")
9898
.long("generic_mod")
9999
.short('g')
100+
.action(ArgAction::SetTrue)
100101
.help("Push generic mod in separate file"),
101102
)
102103
.arg(
103-
Arg::with_name("feature_group")
104+
Arg::new("feature_group")
104105
.long("feature_group")
106+
.action(ArgAction::SetTrue)
105107
.help("Use group_name of peripherals as feature"),
106108
)
107109
.arg(
108-
Arg::with_name("feature_peripheral")
110+
Arg::new("feature_peripheral")
109111
.long("feature_peripheral")
112+
.action(ArgAction::SetTrue)
110113
.help("Use independent cfg feature flags for each peripheral"),
111114
)
112115
.arg(
113-
Arg::with_name("max_cluster_size")
116+
Arg::new("max_cluster_size")
114117
.long("max_cluster_size")
118+
.action(ArgAction::SetTrue)
115119
.help("Use array increment for cluster size"),
116120
)
117121
.arg(
118-
Arg::with_name("make_mod")
122+
Arg::new("make_mod")
119123
.long("make_mod")
120124
.short('m')
125+
.action(ArgAction::SetTrue)
121126
.help("Create mod.rs instead of lib.rs, without inner attributes"),
122127
)
123128
.arg(
124-
Arg::with_name("strict")
129+
Arg::new("strict")
125130
.long("strict")
126131
.short('s')
132+
.action(ArgAction::SetTrue)
127133
.help("Make advanced checks due to parsing SVD"),
128134
)
129135
.arg(
130-
Arg::with_name("pascal_enum_values")
136+
Arg::new("pascal_enum_values")
131137
.long("pascal_enum_values")
138+
.action(ArgAction::SetTrue)
132139
.help("Use PascalCase in stead of UPPER_CASE for enumerated values"),
133140
)
134141
.arg(
135-
Arg::with_name("derive_more")
142+
Arg::new("derive_more")
136143
.long("derive_more")
144+
.action(ArgAction::SetTrue)
137145
.help("Use derive_more procedural macros to implement Deref and From"),
138146
)
139147
.arg(
140-
Arg::with_name("source_type")
148+
Arg::new("source_type")
141149
.long("source_type")
142150
.help("Specify file/stream format"),
143151
)
144152
.arg(
145-
Arg::with_name("log_level")
153+
Arg::new("log_level")
146154
.long("log")
147155
.short('l')
148-
.help(log_help.as_ref())
149-
.takes_value(true)
150-
.possible_values(&["off", "error", "warn", "info", "debug", "trace"]),
156+
.help(format!(
157+
"Choose which messages to log (overrides {})",
158+
env_logger::DEFAULT_FILTER_ENV
159+
))
160+
.action(ArgAction::Set)
161+
.value_parser(["off", "error", "warn", "info", "debug", "trace"]),
151162
)
152163
.version(concat!(
153164
env!("CARGO_PKG_VERSION"),

0 commit comments

Comments
 (0)