nushell/crates/nu-command/src/experimental/git.rs

55 lines
1.5 KiB
Rust
Raw Normal View History

2021-09-29 20:25:05 +02:00
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{Signature, Value};
pub struct Git;
impl Command for Git {
fn name(&self) -> &str {
"git"
}
fn usage(&self) -> &str {
"Run a block"
}
fn signature(&self) -> nu_protocol::Signature {
Signature::build("git")
}
fn run(
&self,
_context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
use std::process::Command as ProcessCommand;
use std::process::Stdio;
let proc = ProcessCommand::new("git").stdout(Stdio::piped()).spawn();
match proc {
Ok(child) => {
match child.wait_with_output() {
Ok(val) => {
let result = val.stdout;
2021-10-20 07:58:25 +02:00
Ok(Value::String {
val: String::from_utf8_lossy(&result).to_string(),
span: call.head,
})
2021-09-29 20:25:05 +02:00
}
Err(_err) => {
2021-10-12 19:44:23 +02:00
// FIXME: Move this to an external signature and add better error handling
2021-09-29 20:25:05 +02:00
Ok(Value::nothing())
}
}
}
Err(_err) => {
2021-10-12 19:44:23 +02:00
// FIXME: Move this to an external signature and add better error handling
2021-09-29 20:25:05 +02:00
Ok(Value::nothing())
}
}
}
}