@@ -721,22 +721,14 @@ impl Agree {
721721 /// choosing, using the file name "{bin}.bash".
722722 pub fn write_bash < P > ( & self , dir : P ) -> Result < ( ) , String >
723723 where P : AsRef < Path > {
724- let mut path = std:: fs:: canonicalize ( dir. as_ref ( ) ) . map_err ( |_| format ! (
725- "Missing BASH completion directory: {:?}" ,
726- dir. as_ref( )
727- ) ) ?;
728-
729- if path. is_dir ( ) {
730- path. push ( [ & self . bin , ".bash" ] . concat ( ) ) ;
731- write_to ( & path, self . bash ( ) . as_bytes ( ) , false )
732- . map_err ( |_| format ! (
733- "Unable to write BASH completions: {:?}" ,
734- path
735- ) )
736- }
737- else {
738- Err ( format ! ( "Invalid BASH completion directory: {:?}" , dir. as_ref( ) ) )
739- }
724+ let mut path = std:: fs:: canonicalize ( dir. as_ref ( ) )
725+ . ok ( )
726+ . filter ( |x| x. is_dir ( ) )
727+ . ok_or_else ( || format ! ( "Invalid BASH completion directory: {:?}" , dir. as_ref( ) ) ) ?;
728+
729+ path. push ( [ & self . bin , ".bash" ] . concat ( ) ) ;
730+ write_to ( & path, self . bash ( ) . as_bytes ( ) , false )
731+ . map_err ( |_| format ! ( "Unable to write BASH completions: {:?}" , path) )
740732 }
741733
742734 /// # Write MAN Page!
@@ -753,23 +745,15 @@ impl Agree {
753745 /// either the "{bin}.1" or "{bin}.1.gz" version, not both. ;)
754746 pub fn write_man < P > ( & self , dir : P ) -> Result < ( ) , String >
755747 where P : AsRef < Path > {
756- let mut path = std:: fs:: canonicalize ( dir. as_ref ( ) ) . map_err ( |_| format ! (
757- "Missing MAN directory: {:?}" ,
758- dir . as_ref ( )
759- ) ) ?;
748+ let mut path = std:: fs:: canonicalize ( dir. as_ref ( ) )
749+ . ok ( )
750+ . filter ( |x| x . is_dir ( ) )
751+ . ok_or_else ( || format ! ( "Invalid MAN directory: {:?}" , dir . as_ref ( ) ) ) ?;
760752
761753 // The main file.
762- if path. is_dir ( ) {
763- path. push ( [ & self . bin , ".1" ] . concat ( ) ) ;
764- write_to ( & path, self . man ( ) . as_bytes ( ) , true )
765- . map_err ( |_| format ! (
766- "Unable to write MAN page: {:?}" ,
767- path
768- ) ) ?;
769- }
770- else {
771- return Err ( format ! ( "Invalid MAN directory: {:?}" , dir. as_ref( ) ) )
772- }
754+ path. push ( [ & self . bin , ".1" ] . concat ( ) ) ;
755+ write_to ( & path, self . man ( ) . as_bytes ( ) , true )
756+ . map_err ( |_| format ! ( "Unable to write MAN page: {:?}" , path) ) ?;
773757
774758 // Write subcommand pages.
775759 for ( bin, man) in self . args . iter ( )
@@ -780,10 +764,7 @@ impl Agree {
780764 path. pop ( ) ;
781765 path. push ( [ & self . bin , "-" , & bin, ".1" ] . concat ( ) ) ;
782766 write_to ( & path, man. as_bytes ( ) , true )
783- . map_err ( |_| format ! (
784- "Unable to write MAN page: {:?}" ,
785- path
786- ) ) ?;
767+ . map_err ( |_| format ! ( "Unable to write SUB-MAN page: {:?}" , path) ) ?;
787768 }
788769
789770 Ok ( ( ) )
@@ -1040,16 +1021,14 @@ complete -F chooser_{fname} -o bashdefault -o default {bname}
10401021 }
10411022
10421023 // Generated ARGUMENTS Section.
1043- {
1044- self . args . iter ( )
1045- . filter_map ( AgreeKind :: if_arg)
1046- . for_each ( |x| {
1047- pre. push (
1048- AgreeSection :: new ( & [ & x. name , ":" ] . concat ( ) , true )
1049- . with_item ( AgreeKind :: paragraph ( & x. description ) )
1050- ) ;
1051- } ) ;
1052- }
1024+ self . args . iter ( )
1025+ . filter_map ( AgreeKind :: if_arg)
1026+ . for_each ( |x| {
1027+ pre. push (
1028+ AgreeSection :: new ( & [ & x. name , ":" ] . concat ( ) , true )
1029+ . with_item ( AgreeKind :: paragraph ( & x. description ) )
1030+ ) ;
1031+ } ) ;
10531032
10541033 // Generated SUBCOMMANDS Section.
10551034 {
@@ -1136,9 +1115,9 @@ fn man_tagline(short: Option<&str>, long: Option<&str>, value: Option<&str>) ->
11361115/// This writes data to a file, optionally recursing to save a `GZipped`
11371116/// version (for MAN pages).
11381117fn write_to ( file : & PathBuf , data : & [ u8 ] , compress : bool ) -> Result < ( ) , ( ) > {
1139- let mut out = std:: fs:: File :: create ( file) . map_err ( |_| ( ) ) ? ;
1140- out. write_all ( data) . map_err ( |_| ( ) ) ? ;
1141- out . flush ( ) . map_err ( |_| ( ) ) ?;
1118+ std:: fs:: File :: create ( file)
1119+ . and_then ( | mut out| out . write_all ( data) . and_then ( |_| out . flush ( ) ) )
1120+ . map_err ( |_| ( ) ) ?;
11421121
11431122 // Save a compressed copy?
11441123 if compress {
0 commit comments