-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move more features to monotrail-utils
- Loading branch information
Showing
13 changed files
with
137 additions
and
96 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/// python has idiosyncratic cli options that are hard to replicate with clap, so we roll our own. | ||
/// Takes args without the first-is-current-program (i.e. python) convention. | ||
/// | ||
/// `usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...` | ||
/// | ||
/// Returns the script, if any | ||
pub fn naive_python_arg_parser<T: AsRef<str>>(args: &[T]) -> Result<Option<String>, String> { | ||
// These are hand collected from `python --help` | ||
// See also https://docs.python.org/3/using/cmdline.html#command-line | ||
let no_value_opts = [ | ||
"-b", "-B", "-d", "-E", "-h", "-i", "-I", "-O", "-OO", "-q", "-s", "-S", "-u", "-v", "-V", | ||
"-x", "-?", | ||
]; | ||
let value_opts = ["--check-hash-based-pycs", "-W", "-X"]; | ||
let mut arg_iter = args.iter(); | ||
loop { | ||
if let Some(arg) = arg_iter.next() { | ||
if no_value_opts.contains(&arg.as_ref()) { | ||
continue; | ||
} else if value_opts.contains(&arg.as_ref()) { | ||
// consume the value belonging to the options | ||
let value = arg_iter.next(); | ||
if value.is_none() { | ||
return Err(format!("Missing argument for {}", arg.as_ref())); | ||
} | ||
continue; | ||
} else if arg.as_ref() == "-c" || arg.as_ref() == "-m" { | ||
let value = arg_iter.next(); | ||
if value.is_none() { | ||
return Err(format!("Missing argument for {}", arg.as_ref())); | ||
} | ||
return Ok(None); | ||
} else { | ||
return Ok(Some(arg.as_ref().to_string())); | ||
} | ||
} else { | ||
// interactive python shell | ||
return Ok(None); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.