File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ pub struct Opts {
3131 #[ cfg_attr( feature = "clap" , arg( long) ) ]
3232 pub no_helpers : bool ,
3333 /// Set component string encoding
34- #[ cfg_attr( feature = "clap" , arg( long) ) ]
34+ #[ cfg_attr( feature = "clap" , arg( long, default_value_t = StringEncoding :: default ( ) ) ) ]
3535 pub string_encoding : StringEncoding ,
3636}
3737
Original file line number Diff line number Diff line change 33#![ deny( missing_docs) ]
44
55use anyhow:: { bail, Result } ;
6+ use std:: fmt:: Display ;
67use std:: str:: FromStr ;
78use wasm_encoder:: CanonicalOption ;
89
@@ -37,6 +38,16 @@ impl Default for StringEncoding {
3738 }
3839}
3940
41+ impl Display for StringEncoding {
42+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
43+ match self {
44+ StringEncoding :: UTF8 => write ! ( f, "utf8" ) ,
45+ StringEncoding :: UTF16 => write ! ( f, "utf16" ) ,
46+ StringEncoding :: CompactUTF16 => write ! ( f, "compact-utf16" ) ,
47+ }
48+ }
49+ }
50+
4051impl FromStr for StringEncoding {
4152 type Err = anyhow:: Error ;
4253
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ struct World {
126126 /// The top-level name of the generated bindings, which may be used for
127127 /// naming modules/files/etc.
128128 #[ clap( long, short) ]
129- name : String ,
129+ name : Option < String > ,
130130}
131131
132132fn parse_named_interface ( s : & str ) -> Result < Interface > {
@@ -283,7 +283,19 @@ fn gen_world(
283283 exports,
284284 default : world. default ,
285285 } ;
286- generator. generate ( & world. name , & interfaces, files) ;
286+ let name = match & world. name {
287+ Some ( name) => name,
288+ None => {
289+ if let Some ( default) = & interfaces. default {
290+ & default. name
291+ } else {
292+ return Err ( anyhow ! (
293+ "--name flag is required unless setting the interface via --default"
294+ ) ) ;
295+ }
296+ }
297+ } ;
298+ generator. generate ( name, & interfaces, files) ;
287299 Ok ( ( ) )
288300}
289301
You can’t perform that action at this time.
0 commit comments