@@ -15,6 +15,10 @@ impl Generator for Zsh {
1515 }
1616
1717 fn generate ( & self , app : & App , buf : & mut dyn Write ) {
18+ let bin_name = app
19+ . get_bin_name ( )
20+ . expect ( "crate::generate should have set the bin_name" ) ;
21+
1822 w ! (
1923 buf,
2024 format!(
@@ -41,7 +45,7 @@ _{name}() {{
4145
4246_{name} \" $@\"
4347" ,
44- name = app . get_bin_name ( ) . unwrap ( ) ,
48+ name = bin_name ,
4549 initial_args = get_args_of( app, None ) ,
4650 subcommands = get_subcommands_of( app) ,
4751 subcommand_details = subcommand_details( app)
@@ -81,7 +85,9 @@ _{name} \"$@\"
8185fn subcommand_details ( p : & App ) -> String {
8286 debug ! ( "subcommand_details" ) ;
8387
84- let name = p. get_bin_name ( ) . unwrap ( ) ;
88+ let bin_name = p
89+ . get_bin_name ( )
90+ . expect ( "crate::generate should have set the bin_name" ) ;
8591
8692 let mut ret = vec ! [ ] ;
8793
@@ -93,8 +99,8 @@ _{bin_name_underscore}_commands() {{
9399 local commands; commands=({subcommands_and_args})
94100 _describe -t commands '{bin_name} commands' commands \" $@\"
95101}}" ,
96- bin_name_underscore = name . replace( ' ' , "__" ) ,
97- bin_name = name ,
102+ bin_name_underscore = bin_name . replace( ' ' , "__" ) ,
103+ bin_name = bin_name ,
98104 subcommands_and_args = subcommands_of( p)
99105 ) ;
100106 ret. push ( parent_text) ;
@@ -247,6 +253,10 @@ fn get_subcommands_of(parent: &App) -> String {
247253 all_subcommands. push ( segments. join ( "\n " ) ) ;
248254 }
249255
256+ let parent_bin_name = parent
257+ . get_bin_name ( )
258+ . expect ( "crate::generate should have set the bin_name" ) ;
259+
250260 format ! (
251261 "
252262 case $state in
@@ -260,7 +270,7 @@ fn get_subcommands_of(parent: &App) -> String {
260270 ;;
261271esac" ,
262272 name = parent. get_name( ) ,
263- name_hyphen = parent . get_bin_name ( ) . unwrap ( ) . replace( ' ' , "-" ) ,
273+ name_hyphen = parent_bin_name . replace( ' ' , "-" ) ,
264274 subcommands = all_subcommands. join( "\n " ) ,
265275 pos = parent. get_positionals( ) . count( ) + 1
266276 )
@@ -327,9 +337,12 @@ fn get_args_of(parent: &App, p_global: Option<&App>) -> String {
327337 }
328338
329339 if parent. has_subcommands ( ) {
340+ let parent_bin_name = parent
341+ . get_bin_name ( )
342+ . expect ( "crate::generate should have set the bin_name" ) ;
330343 let subcommand_bin_name = format ! (
331344 "\" :: :_{name}_commands\" \\ " ,
332- name = parent . get_bin_name ( ) . as_ref ( ) . unwrap ( ) . replace( ' ' , "__" )
345+ name = parent_bin_name . replace( ' ' , "__" )
333346 ) ;
334347 segments. push ( subcommand_bin_name) ;
335348
0 commit comments