Skip to content

Commit 4ace70a

Browse files
Levi08040x009922
authored andcommitted
remove dedicated profile argument
Signed-off-by: Levi0804 <levi080404@gmail.com>
1 parent 707bc18 commit 4ace70a

File tree

2 files changed

+18
-48
lines changed

2 files changed

+18
-48
lines changed

crates/iroha_kagami/src/main.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ mod tests {
196196
"kagami",
197197
"wasm",
198198
"build",
199-
"--profile=release",
200199
"./path",
201200
"--cargo-args=--profile deploy",
202201
"--out-file=test.wasm",
@@ -213,15 +212,5 @@ mod tests {
213212
])
214213
.unwrap();
215214

216-
Args::try_parse_from([
217-
"kagami",
218-
"wasm",
219-
"build",
220-
"./path",
221-
"--profile=release",
222-
"--cargo-args=--locked --frozen --profile deploy",
223-
"--out-file=test.wasm",
224-
])
225-
.unwrap();
226215
}
227216
}

crates/iroha_kagami/src/wasm.rs

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{
44
str::FromStr,
55
};
66

7-
use clap::{command, Args as ClapArgs, CommandFactory, FromArgMatches, Parser, Subcommand};
7+
use clap::{arg, command, Args as ClapArgs, Subcommand};
88
use color_eyre::eyre::{eyre, Context};
99
use iroha_wasm_builder::{Builder, Profile};
1010
use owo_colors::OwoColorize;
@@ -24,22 +24,12 @@ pub enum Args {
2424
Build {
2525
#[command(flatten)]
2626
common: CommonArgs,
27-
/// Build profile
28-
#[arg(long)]
29-
profile: Option<Profile>,
3027
/// Where to store the output WASM. If the file exists, it will be overwritten.
3128
#[arg(long)]
3229
out_file: PathBuf,
3330
},
3431
}
3532

36-
#[derive(Parser, Debug, Default)]
37-
#[command(no_binary_name = true, disable_help_flag = true)]
38-
struct ProfileArg {
39-
#[arg(long, value_enum)]
40-
profile: Profile,
41-
}
42-
4333
#[derive(ClapArgs, Debug, Clone)]
4434
pub struct CommonArgs {
4535
/// Path to the smartcontract
@@ -75,34 +65,25 @@ impl<T: Write> RunArgs<T> for Args {
7565
Args::Build {
7666
common: CommonArgs { path, cargo_args },
7767
out_file,
78-
profile,
7968
} => {
80-
let mut args = cargo_args.0.clone();
81-
let mut profile_arg = Vec::<String>::with_capacity(2);
82-
83-
if let Some(arg_idx) = args.iter().position(|arg| arg.contains("--profile")) {
84-
if profile.is_some() {
85-
eprintln!("warning: value from \"--profile\" is ignored in favor of profile in \"--cargo-args\"");
69+
let mut args = cargo_args.0;
70+
let profile = match args.iter().position(|arg| arg.contains("--profile")) {
71+
Some(idx) => {
72+
let profile = args
73+
.get(idx + 1)
74+
.expect("--profile requires a value in the form: --cargo-args=\"--profile <PROFILE>..\"");
75+
let profile = profile.parse::<Profile>().expect(&format!(
76+
"unknown profile `{}`, valid options are: deploy, release",
77+
profile
78+
));
79+
args.drain(idx..idx + 2);
80+
profile
8681
}
87-
args.get(arg_idx + 1)
88-
.expect("expected format --cargo-args='--profile <PROFILE>..'")
89-
.parse::<Profile>()
90-
.expect(&format!("Unknown Profile ({})", args[arg_idx + 1]));
91-
profile_arg.extend(args.drain(arg_idx..arg_idx + 2));
92-
} else if profile.is_some() {
93-
eprintln!("warning: \"--profile\" arg is deprecated; please use \"--cargo-args='--profile ..'\" instead");
94-
} else {
95-
eprintln!("warning: \"--cargo-args\" missing \"--profile\"; using `release` by default. Use \"--cargo-args='--profile ..'\" to specify one.");
96-
}
97-
98-
let matches = ProfileArg::command()
99-
.no_binary_name(true)
100-
.ignore_errors(true)
101-
.try_get_matches_from(&profile_arg)
102-
.unwrap_or_default();
103-
let profile_arg = ProfileArg::from_arg_matches(&matches).unwrap_or_default();
104-
105-
let profile = profile_arg.profile;
82+
None => {
83+
eprintln!("warning: \"--cargo-args\" missing \"--profile\"; using `release` by default. Use --cargo-args=\"--profile <PROFILE>..\" to specify one.");
84+
Profile::Release
85+
}
86+
};
10687

10788
let builder = Builder::new(&path, profile).cargo_args(args).show_output();
10889

0 commit comments

Comments
 (0)