@@ -552,6 +552,109 @@ where
552552 }
553553}
554554
555+ #[ uucore:: main]
556+ pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
557+ let args = args. collect_ignore ( ) ;
558+
559+ let matches = uu_app ( ) . try_get_matches_from ( args) ?;
560+
561+ // get the file to split
562+ let file_name = matches. get_one :: < String > ( options:: FILE ) . unwrap ( ) ;
563+
564+ // get the patterns to split on
565+ let patterns: Vec < String > = matches
566+ . get_many :: < String > ( options:: PATTERN )
567+ . unwrap ( )
568+ . map ( |s| s. to_string ( ) )
569+ . collect ( ) ;
570+ let patterns = patterns:: get_patterns ( & patterns[ ..] ) ?;
571+ let options = CsplitOptions :: new ( & matches) ;
572+ if file_name == "-" {
573+ let stdin = io:: stdin ( ) ;
574+ Ok ( csplit ( & options, patterns, stdin. lock ( ) ) ?)
575+ } else {
576+ let file = File :: open ( file_name)
577+ . map_err_context ( || format ! ( "cannot access {}" , file_name. quote( ) ) ) ?;
578+ let file_metadata = file
579+ . metadata ( )
580+ . map_err_context ( || format ! ( "cannot access {}" , file_name. quote( ) ) ) ?;
581+ if !file_metadata. is_file ( ) {
582+ return Err ( CsplitError :: NotRegularFile ( file_name. to_string ( ) ) . into ( ) ) ;
583+ }
584+ Ok ( csplit ( & options, patterns, BufReader :: new ( file) ) ?)
585+ }
586+ }
587+
588+ pub fn uu_app ( ) -> Command {
589+ Command :: new ( uucore:: util_name ( ) )
590+ . version ( crate_version ! ( ) )
591+ . about ( ABOUT )
592+ . override_usage ( format_usage ( USAGE ) )
593+ . infer_long_args ( true )
594+ . arg (
595+ Arg :: new ( options:: SUFFIX_FORMAT )
596+ . short ( 'b' )
597+ . long ( options:: SUFFIX_FORMAT )
598+ . value_name ( "FORMAT" )
599+ . help ( "use sprintf FORMAT instead of %02d" ) ,
600+ )
601+ . arg (
602+ Arg :: new ( options:: PREFIX )
603+ . short ( 'f' )
604+ . long ( options:: PREFIX )
605+ . value_name ( "PREFIX" )
606+ . help ( "use PREFIX instead of 'xx'" ) ,
607+ )
608+ . arg (
609+ Arg :: new ( options:: KEEP_FILES )
610+ . short ( 'k' )
611+ . long ( options:: KEEP_FILES )
612+ . help ( "do not remove output files on errors" )
613+ . action ( ArgAction :: SetTrue ) ,
614+ )
615+ . arg (
616+ Arg :: new ( options:: SUPPRESS_MATCHED )
617+ . long ( options:: SUPPRESS_MATCHED )
618+ . help ( "suppress the lines matching PATTERN" )
619+ . action ( ArgAction :: SetTrue ) ,
620+ )
621+ . arg (
622+ Arg :: new ( options:: DIGITS )
623+ . short ( 'n' )
624+ . long ( options:: DIGITS )
625+ . value_name ( "DIGITS" )
626+ . help ( "use specified number of digits instead of 2" ) ,
627+ )
628+ . arg (
629+ Arg :: new ( options:: QUIET )
630+ . short ( 's' )
631+ . long ( options:: QUIET )
632+ . visible_alias ( "silent" )
633+ . help ( "do not print counts of output file sizes" )
634+ . action ( ArgAction :: SetTrue ) ,
635+ )
636+ . arg (
637+ Arg :: new ( options:: ELIDE_EMPTY_FILES )
638+ . short ( 'z' )
639+ . long ( options:: ELIDE_EMPTY_FILES )
640+ . help ( "remove empty output files" )
641+ . action ( ArgAction :: SetTrue ) ,
642+ )
643+ . arg (
644+ Arg :: new ( options:: FILE )
645+ . hide ( true )
646+ . required ( true )
647+ . value_hint ( clap:: ValueHint :: FilePath ) ,
648+ )
649+ . arg (
650+ Arg :: new ( options:: PATTERN )
651+ . hide ( true )
652+ . action ( clap:: ArgAction :: Append )
653+ . required ( true ) ,
654+ )
655+ . after_help ( AFTER_HELP )
656+ }
657+
555658#[ cfg( test) ]
556659mod tests {
557660 use super :: * ;
@@ -714,106 +817,3 @@ mod tests {
714817 assert ! ( input_splitter. next( ) . is_none( ) ) ;
715818 }
716819}
717-
718- #[ uucore:: main]
719- pub fn uumain ( args : impl uucore:: Args ) -> UResult < ( ) > {
720- let args = args. collect_ignore ( ) ;
721-
722- let matches = uu_app ( ) . try_get_matches_from ( args) ?;
723-
724- // get the file to split
725- let file_name = matches. get_one :: < String > ( options:: FILE ) . unwrap ( ) ;
726-
727- // get the patterns to split on
728- let patterns: Vec < String > = matches
729- . get_many :: < String > ( options:: PATTERN )
730- . unwrap ( )
731- . map ( |s| s. to_string ( ) )
732- . collect ( ) ;
733- let patterns = patterns:: get_patterns ( & patterns[ ..] ) ?;
734- let options = CsplitOptions :: new ( & matches) ;
735- if file_name == "-" {
736- let stdin = io:: stdin ( ) ;
737- Ok ( csplit ( & options, patterns, stdin. lock ( ) ) ?)
738- } else {
739- let file = File :: open ( file_name)
740- . map_err_context ( || format ! ( "cannot access {}" , file_name. quote( ) ) ) ?;
741- let file_metadata = file
742- . metadata ( )
743- . map_err_context ( || format ! ( "cannot access {}" , file_name. quote( ) ) ) ?;
744- if !file_metadata. is_file ( ) {
745- return Err ( CsplitError :: NotRegularFile ( file_name. to_string ( ) ) . into ( ) ) ;
746- }
747- Ok ( csplit ( & options, patterns, BufReader :: new ( file) ) ?)
748- }
749- }
750-
751- pub fn uu_app ( ) -> Command {
752- Command :: new ( uucore:: util_name ( ) )
753- . version ( crate_version ! ( ) )
754- . about ( ABOUT )
755- . override_usage ( format_usage ( USAGE ) )
756- . infer_long_args ( true )
757- . arg (
758- Arg :: new ( options:: SUFFIX_FORMAT )
759- . short ( 'b' )
760- . long ( options:: SUFFIX_FORMAT )
761- . value_name ( "FORMAT" )
762- . help ( "use sprintf FORMAT instead of %02d" ) ,
763- )
764- . arg (
765- Arg :: new ( options:: PREFIX )
766- . short ( 'f' )
767- . long ( options:: PREFIX )
768- . value_name ( "PREFIX" )
769- . help ( "use PREFIX instead of 'xx'" ) ,
770- )
771- . arg (
772- Arg :: new ( options:: KEEP_FILES )
773- . short ( 'k' )
774- . long ( options:: KEEP_FILES )
775- . help ( "do not remove output files on errors" )
776- . action ( ArgAction :: SetTrue ) ,
777- )
778- . arg (
779- Arg :: new ( options:: SUPPRESS_MATCHED )
780- . long ( options:: SUPPRESS_MATCHED )
781- . help ( "suppress the lines matching PATTERN" )
782- . action ( ArgAction :: SetTrue ) ,
783- )
784- . arg (
785- Arg :: new ( options:: DIGITS )
786- . short ( 'n' )
787- . long ( options:: DIGITS )
788- . value_name ( "DIGITS" )
789- . help ( "use specified number of digits instead of 2" ) ,
790- )
791- . arg (
792- Arg :: new ( options:: QUIET )
793- . short ( 's' )
794- . long ( options:: QUIET )
795- . visible_alias ( "silent" )
796- . help ( "do not print counts of output file sizes" )
797- . action ( ArgAction :: SetTrue ) ,
798- )
799- . arg (
800- Arg :: new ( options:: ELIDE_EMPTY_FILES )
801- . short ( 'z' )
802- . long ( options:: ELIDE_EMPTY_FILES )
803- . help ( "remove empty output files" )
804- . action ( ArgAction :: SetTrue ) ,
805- )
806- . arg (
807- Arg :: new ( options:: FILE )
808- . hide ( true )
809- . required ( true )
810- . value_hint ( clap:: ValueHint :: FilePath ) ,
811- )
812- . arg (
813- Arg :: new ( options:: PATTERN )
814- . hide ( true )
815- . action ( clap:: ArgAction :: Append )
816- . required ( true ) ,
817- )
818- . after_help ( AFTER_HELP )
819- }
0 commit comments