@@ -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 } ;
88use color_eyre:: eyre:: { eyre, Context } ;
99use iroha_wasm_builder:: { Builder , Profile } ;
1010use 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 ) ]
4434pub 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