()
| 109 | "; |
| 110 | |
| 111 | fn parse_args() -> Result<(CliArgs, RunMode, Vec<String>), lexopt::Error> { |
| 112 | let mut args = CliArgs::default(); |
| 113 | let mut parser = lexopt::Parser::from_env(); |
| 114 | fn argv(argv0: String, mut parser: lexopt::Parser) -> Result<Vec<String>, lexopt::Error> { |
| 115 | std::iter::once(Ok(argv0)) |
| 116 | .chain(parser.raw_args()?.map(|arg| arg.string())) |
| 117 | .collect() |
| 118 | } |
| 119 | while let Some(arg) = parser.next()? { |
| 120 | match arg { |
| 121 | Short('b') => args.bytes_warning += 1, |
| 122 | Short('B') => args.dont_write_bytecode = true, |
| 123 | Short('c') => { |
| 124 | let cmd = parser.value()?.string()?; |
| 125 | return Ok((args, RunMode::Command(cmd), argv("-c".to_owned(), parser)?)); |
| 126 | } |
| 127 | Short('d') => args.debug += 1, |
| 128 | Short('E') => args.ignore_environment = true, |
| 129 | Short('h' | '?') | Long("help") => help(parser), |
| 130 | Short('i') => args.inspect = true, |
| 131 | Short('I') => args.isolate = true, |
| 132 | Short('m') => { |
| 133 | let module = parser.value()?.string()?; |
| 134 | let argv = argv("PLACEHOLDER".to_owned(), parser)?; |
| 135 | return Ok((args, RunMode::Module(module), argv)); |
| 136 | } |
| 137 | Short('O') => args.optimize += 1, |
| 138 | Short('P') => args.safe_path = true, |
| 139 | Short('q') => args.quiet = true, |
| 140 | Short('R') => args.random_hash_seed = true, |
| 141 | Short('S') => args.no_site = true, |
| 142 | Short('s') => args.no_user_site = true, |
| 143 | Short('u') => args.unbuffered = true, |
| 144 | Short('v') => args.verbose += 1, |
| 145 | Short('V') | Long("version") => version(), |
| 146 | Short('W') => args.warning_control.push(parser.value()?.string()?), |
| 147 | // TODO: Short('x') => |
| 148 | Short('X') => args.implementation_option.push(parser.value()?.string()?), |
| 149 | |
| 150 | Long("check-hash-based-pycs") => { |
| 151 | args.check_hash_based_pycs = parser.value()?.parse()? |
| 152 | } |
| 153 | |
| 154 | // TODO: make these more specific |
| 155 | Long("help-env") => help(parser), |
| 156 | Long("help-xoptions") => help(parser), |
| 157 | Long("help-all") => help(parser), |
| 158 | |
| 159 | #[cfg(feature = "flame-it")] |
| 160 | Long("profile-output") => args.profile_output = Some(parser.value()?), |
| 161 | #[cfg(feature = "flame-it")] |
| 162 | Long("profile-format") => args.profile_format = Some(parser.value()?.string()?), |
| 163 | |
| 164 | Long("install-pip") => { |
| 165 | let (mode, argv) = if let Some(val) = parser.optional_value() { |
| 166 | (val.parse()?, vec![val.string()?]) |
| 167 | } else if let Ok(argv0) = parser.value() { |
| 168 | let mode = argv0.parse()?; |
no test coverage detected