Add base app
This commit is contained in:
48
src/main.rs
Normal file
48
src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
fn main() -> eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
||||
let args = std::env::args();
|
||||
|
||||
let args = args.collect::<Vec<String>>();
|
||||
let args = args.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
|
||||
|
||||
let cmd = clap::Command::new("git-toolkit").allow_external_subcommands(true);
|
||||
|
||||
let matches = cmd.get_matches_from(args.clone().as_slice());
|
||||
match matches.subcommand() {
|
||||
Some((_, args)) => {
|
||||
let raw = args
|
||||
.get_many::<std::ffi::OsString>("")
|
||||
.ok_or(eyre::anyhow!("please pass some args to search"))?
|
||||
.map(|s| s.as_os_str())
|
||||
.map(|s| s.to_string_lossy().to_string())
|
||||
.collect::<Vec<String>>();
|
||||
let raw = raw.iter().map(|s| s.as_str()).collect::<Vec<&str>>();
|
||||
|
||||
prepend_git_shell(raw.as_slice())?
|
||||
}
|
||||
None => prepend_git_shell(args.as_slice())?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn prepend_git_shell(args: &[&str]) -> eyre::Result<()> {
|
||||
let mut shell_args = vec!["git"];
|
||||
shell_args.extend_from_slice(args);
|
||||
|
||||
shell(&shell_args)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn shell(args: &[&str]) -> eyre::Result<()> {
|
||||
let _ = std::process::Command::new(args[0])
|
||||
.args(&args[1..])
|
||||
.stdin(std::process::Stdio::inherit())
|
||||
.stdout(std::process::Stdio::inherit())
|
||||
.stderr(std::process::Stdio::inherit())
|
||||
.output()?;
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user