File tree Expand file tree Collapse file tree 4 files changed +57
-14
lines changed Expand file tree Collapse file tree 4 files changed +57
-14
lines changed Original file line number Diff line number Diff line change 3
3
4
4
use crate :: ShellCore ;
5
5
6
- fn unset_var ( core : & mut ShellCore , name : & str ) -> i32 {
6
+ fn unset_all ( core : & mut ShellCore , name : & str ) -> i32 {
7
7
core. data . unset ( name) ;
8
8
0
9
9
}
10
10
11
+ fn unset_var ( core : & mut ShellCore , name : & str ) -> i32 {
12
+ core. data . unset_var ( name) ;
13
+ 0
14
+ }
15
+
16
+ fn unset_function ( core : & mut ShellCore , name : & str ) -> i32 {
17
+ core. data . unset_function ( name) ;
18
+ 0
19
+ }
20
+
11
21
pub fn unset ( core : & mut ShellCore , args : & mut Vec < String > ) -> i32 {
12
22
match args[ 1 ] . as_ref ( ) {
13
- "-f" => 0 ,
14
- "-v" => 0 ,
15
- name => unset_var ( core, name) ,
23
+ "-f" => {
24
+ if args. len ( ) > 2 {
25
+ return unset_function ( core, & args[ 2 ] ) ;
26
+ }
27
+ } ,
28
+ "-v" => {
29
+ if args. len ( ) > 2 {
30
+ return unset_var ( core, & args[ 2 ] ) ;
31
+ }
32
+ } ,
33
+ name => return unset_all ( core, name) ,
16
34
}
35
+ 0
17
36
}
Original file line number Diff line number Diff line change @@ -157,12 +157,6 @@ impl Data {
157
157
self . set_layer_param ( key, val, 0 ) ;
158
158
}
159
159
160
- pub fn unset ( & mut self , key : & str ) {
161
- for layer in & mut self . parameters {
162
- layer. remove ( key) ;
163
- }
164
- }
165
-
166
160
pub fn set_local_param ( & mut self , key : & str , val : & str ) {
167
161
let layer = self . parameters . len ( ) ;
168
162
self . set_layer_param ( key, val, layer-1 ) ;
@@ -241,4 +235,19 @@ impl Data {
241
235
prev_head = head;
242
236
}
243
237
}
238
+
239
+ pub fn unset_var ( & mut self , key : & str ) {
240
+ for layer in & mut self . parameters {
241
+ layer. remove ( key) ;
242
+ }
243
+ }
244
+
245
+ pub fn unset_function ( & mut self , key : & str ) {
246
+ self . functions . remove ( key) ;
247
+ }
248
+
249
+ pub fn unset ( & mut self , key : & str ) {
250
+ self . unset_var ( key) ;
251
+ self . unset_function ( key) ;
252
+ }
244
253
}
Original file line number Diff line number Diff line change @@ -91,19 +91,19 @@ impl SimpleCommand {
91
91
92
92
match unistd:: execvp ( & cargs[ 0 ] , & cargs) {
93
93
Err ( Errno :: E2BIG ) => {
94
- println ! ( "sush: {}: Arg list too long" , & self . args[ 0 ] ) ;
94
+ eprintln ! ( "sush: {}: Arg list too long" , & self . args[ 0 ] ) ;
95
95
process:: exit ( 126 )
96
96
} ,
97
97
Err ( Errno :: EACCES ) => {
98
- println ! ( "sush: {}: Permission denied" , & self . args[ 0 ] ) ;
98
+ eprintln ! ( "sush: {}: Permission denied" , & self . args[ 0 ] ) ;
99
99
process:: exit ( 126 )
100
100
} ,
101
101
Err ( Errno :: ENOENT ) => {
102
- println ! ( "{}: command not found" , & self . args[ 0 ] ) ;
102
+ eprintln ! ( "{}: command not found" , & self . args[ 0 ] ) ;
103
103
process:: exit ( 127 )
104
104
} ,
105
105
Err ( err) => {
106
- println ! ( "Failed to execute. {:?}" , err) ;
106
+ eprintln ! ( "Failed to execute. {:?}" , err) ;
107
107
process:: exit ( 127 )
108
108
}
109
109
_ => panic ! ( "SUSH INTERNAL ERROR (never come here)" )
Original file line number Diff line number Diff line change @@ -90,6 +90,21 @@ res=$($com <<< 'eval "(" echo abc ")" "|" rev')
90
90
res=$( $com <<< ' A=aaa ; unset A ; echo $A' )
91
91
[ " $res " = " " ] || err $LINENO
92
92
93
+ res=$( $com <<< ' A=aaa ; unset -f A ; echo $A' )
94
+ [ " $res " = " aaa" ] || err $LINENO
95
+
96
+ res=$( $com <<< ' A=aaa ; unset -v A ; echo $A' )
97
+ [ " $res " = " " ] || err $LINENO
98
+
99
+ res=$( $com <<< ' A () { echo aaa ; } ; unset -v A ; A' )
100
+ [ " $res " = " aaa" ] || err $LINENO
101
+
102
+ res=$( $com <<< ' A () { echo aaa ; } ; unset -f A ; A' )
103
+ [ " $res " = " " ] || err $LINENO
104
+
105
+ res=$( $com <<< ' A () { echo aaa ; } ; unset A ; A' )
106
+ [ " $res " = " " ] || err $LINENO
107
+
93
108
# ## COMPOUND COMMAND TEST ###
94
109
95
110
res=$( $com <<< ' (echo hoge; echo fuge)' )
You can’t perform that action at this time.
0 commit comments