File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ use seahorse:: { App , Context , Flag , FlagType } ;
2
+ use std:: { env, fs} ;
3
+
4
+ fn main ( ) {
5
+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
6
+ let app = App :: new ( "cp" )
7
+ . description ( "Copy a file" )
8
+ . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
9
+ . version ( env ! ( "CARGO_PKG_VERSION" ) )
10
+ . usage ( "cp file1 file2" )
11
+ . action ( |c| match cp ( c) {
12
+ Ok ( ( ) ) => std:: process:: exit ( 0 ) ,
13
+ Err ( e) => println ! ( "Could not copy file: {:?}" , e) ,
14
+ } )
15
+ . flag (
16
+ Flag :: new ( "verbose" , FlagType :: Bool )
17
+ . description ( "Becomes more verbose" )
18
+ . alias ( "v" ) ,
19
+ ) ;
20
+ app. run ( args) ;
21
+ }
22
+
23
+ fn cp ( c : & Context ) -> std:: io:: Result < ( ) > {
24
+ fs:: copy ( & c. args [ 0 ] , & c. args [ 1 ] ) ?;
25
+ if c. bool_flag ( "verbose" ) {
26
+ println ! ( "Copying file {:?} to {:?}" , & c. args[ 0 ] , & c. args[ 1 ] ) ;
27
+ }
28
+ Ok ( ( ) )
29
+ }
Original file line number Diff line number Diff line change
1
+ use seahorse:: { App , Context , Flag , FlagType } ;
2
+ use std:: { env, fs} ;
3
+
4
+ fn main ( ) {
5
+ let args: Vec < String > = env:: args ( ) . collect ( ) ;
6
+ let app = App :: new ( "mv" )
7
+ . description ( "Move a file" )
8
+ . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
9
+ . version ( env ! ( "CARGO_PKG_VERSION" ) )
10
+ . usage ( "mv file1 file2" )
11
+ . action ( |c| match mv ( c) {
12
+ Ok ( ( ) ) => std:: process:: exit ( 0 ) ,
13
+ Err ( e) => println ! ( "Could not move file: {:?}" , e) ,
14
+ } )
15
+ . flag (
16
+ Flag :: new ( "verbose" , FlagType :: Bool )
17
+ . description ( "Becomes more verbose" )
18
+ . alias ( "v" ) ,
19
+ ) ;
20
+ app. run ( args) ;
21
+ }
22
+
23
+ fn mv ( c : & Context ) -> std:: io:: Result < ( ) > {
24
+ fs:: rename ( & c. args [ 0 ] , & c. args [ 1 ] ) ?;
25
+ if c. bool_flag ( "verbose" ) {
26
+ println ! ( "Moving file {:?} to {:?}" , & c. args[ 0 ] , & c. args[ 1 ] ) ;
27
+ }
28
+ Ok ( ( ) )
29
+ }
You can’t perform that action at this time.
0 commit comments