@@ -12,25 +12,32 @@ use crate::{
12
12
use self :: verbose:: Verbose ;
13
13
14
14
use super :: {
15
- ast:: { Authenticate , RunAs , Tag } ,
15
+ ast:: { Authenticate , Def , RunAs , Tag } ,
16
16
tokens:: Command ,
17
+ VecOrd ,
17
18
} ;
18
19
19
20
mod verbose;
20
21
21
22
pub struct Entry < ' a > {
22
23
run_as : Option < & ' a RunAs > ,
23
24
cmd_specs : Vec < ( Tag , Qualified < & ' a Meta < Command > > ) > ,
25
+ cmd_alias : & ' a VecOrd < Def < Command > > ,
24
26
}
25
27
26
28
impl < ' a > Entry < ' a > {
27
29
pub ( super ) fn new (
28
30
run_as : Option < & ' a RunAs > ,
29
31
cmd_specs : Vec < ( Tag , Qualified < & ' a Meta < Command > > ) > ,
32
+ cmd_alias : & ' a VecOrd < Def < Command > > ,
30
33
) -> Self {
31
34
debug_assert ! ( !cmd_specs. is_empty( ) ) ;
32
35
33
- Self { run_as, cmd_specs }
36
+ Self {
37
+ run_as,
38
+ cmd_specs,
39
+ cmd_alias,
40
+ }
34
41
}
35
42
36
43
pub fn verbose ( self ) -> impl fmt:: Display + ' a {
@@ -56,7 +63,11 @@ fn root_runas() -> RunAs {
56
63
57
64
impl fmt:: Display for Entry < ' _ > {
58
65
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
59
- let Self { run_as, cmd_specs } = self ;
66
+ let Self {
67
+ run_as,
68
+ cmd_specs,
69
+ cmd_alias,
70
+ } = self ;
60
71
61
72
let root_runas = root_runas ( ) ;
62
73
let run_as = run_as. unwrap_or ( & root_runas) ;
@@ -79,7 +90,7 @@ impl fmt::Display for Entry<'_> {
79
90
80
91
write_tag ( f, tag, last_tag) ?;
81
92
last_tag = Some ( tag) ;
82
- write_spec ( f, spec) ?;
93
+ write_spec ( f, spec, cmd_alias , true ) ?;
83
94
}
84
95
85
96
Ok ( ( ) )
@@ -208,17 +219,28 @@ fn write_tag(f: &mut fmt::Formatter, tag: &Tag, last_tag: Option<&Tag>) -> fmt::
208
219
Ok ( ( ) )
209
220
}
210
221
211
- fn write_spec ( f : & mut fmt:: Formatter , spec : & Qualified < & Meta < Command > > ) -> fmt:: Result {
222
+ fn write_spec (
223
+ f : & mut fmt:: Formatter ,
224
+ spec : & Qualified < & Meta < Command > > ,
225
+ alias_list : & VecOrd < Def < Command > > ,
226
+ mut sign : bool ,
227
+ ) -> fmt:: Result {
212
228
let meta = match spec {
213
229
Qualified :: Allow ( meta) => meta,
214
230
Qualified :: Forbid ( meta) => {
215
- f . write_str ( "!" ) ? ;
231
+ sign = !sign ;
216
232
meta
217
233
}
218
234
} ;
219
235
236
+ match meta {
237
+ Meta :: All | Meta :: Only ( _) if !sign => f. write_str ( "!" ) ?,
238
+ _ => { }
239
+ }
240
+
220
241
match meta {
221
242
Meta :: All => f. write_str ( "ALL" ) ?,
243
+
222
244
Meta :: Only ( ( cmd, args) ) => {
223
245
write ! ( f, "{cmd}" ) ?;
224
246
if let Some ( args) = args {
@@ -227,7 +249,22 @@ fn write_spec(f: &mut fmt::Formatter, spec: &Qualified<&Meta<Command>>) -> fmt::
227
249
}
228
250
}
229
251
}
230
- Meta :: Alias ( alias) => f. write_str ( alias) ?,
252
+ Meta :: Alias ( alias) => {
253
+ // this will terminate, since AliasTable has been checked by sanitize_alias_table
254
+ if let Some ( Def ( _, spec_list) ) = super :: elems ( alias_list) . find ( |Def ( id, _) | id == alias)
255
+ {
256
+ let mut is_first_iteration = true ;
257
+ for spec in spec_list {
258
+ if !is_first_iteration {
259
+ f. write_str ( ", " ) ?;
260
+ }
261
+ write_spec ( f, & spec. as_ref ( ) , alias_list, sign) ?;
262
+ is_first_iteration = false ;
263
+ }
264
+ } else {
265
+ f. write_str ( "???" ) ?
266
+ }
267
+ }
231
268
}
232
269
233
270
Ok ( ( ) )
0 commit comments