Return context
(&self, args: Vec<String>)
| 110 | |
| 111 | /// Return context |
| 112 | pub fn context(&self, args: Vec<String>) -> Context<'f> { |
| 113 | let mut ctx = Context { |
| 114 | flag: HashMap::new(), |
| 115 | args: args.clone(), |
| 116 | }; |
| 117 | |
| 118 | if args.len() <= 1 { |
| 119 | return ctx; |
| 120 | } |
| 121 | |
| 122 | let args = &args[1..]; |
| 123 | |
| 124 | let mut index = 0; |
| 125 | for v in args.iter() { |
| 126 | // 变量到倒数第二个就不需要遍历 |
| 127 | if index == args.len() - 1 { |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | for f in self.flags.iter() { |
| 132 | if v == f.0 { |
| 133 | ctx.flag.insert( |
| 134 | f.0.clone(), |
| 135 | Flag { |
| 136 | flag: f.1.flag, |
| 137 | usages: f.1.usages, |
| 138 | value: args[index + 1..][0].clone(), |
| 139 | }, |
| 140 | ); |
| 141 | } |
| 142 | } |
| 143 | index += 1; |
| 144 | } |
| 145 | ctx |
| 146 | } |
| 147 | } |