This commit is contained in:
JT
2021-10-25 17:01:02 +13:00
parent ab9d6b206d
commit b6d269e90a
63 changed files with 1075 additions and 1013 deletions

View File

@@ -1,7 +1,8 @@
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{Signature, Value};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, Value};
#[derive(Clone)]
pub struct Git;
impl Command for Git {
@@ -21,8 +22,8 @@ impl Command for Git {
&self,
_context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
use std::process::Command as ProcessCommand;
use std::process::Stdio;
@@ -37,17 +38,18 @@ impl Command for Git {
Ok(Value::String {
val: String::from_utf8_lossy(&result).to_string(),
span: call.head,
})
}
.into_pipeline_data())
}
Err(_err) => {
// FIXME: Move this to an external signature and add better error handling
Ok(Value::nothing())
Ok(PipelineData::new())
}
}
}
Err(_err) => {
// FIXME: Move this to an external signature and add better error handling
Ok(Value::nothing())
Ok(PipelineData::new())
}
}
}

View File

@@ -1,8 +1,9 @@
use nu_engine::eval_expression;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{Signature, SyntaxShape, Value};
use nu_protocol::{IntoPipelineData, PipelineData, Signature, SyntaxShape, Value};
#[derive(Clone)]
pub struct GitCheckout;
impl Command for GitCheckout {
@@ -26,8 +27,8 @@ impl Command for GitCheckout {
&self,
context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
use std::process::Command as ProcessCommand;
use std::process::Stdio;
@@ -52,17 +53,18 @@ impl Command for GitCheckout {
Ok(Value::String {
val: String::from_utf8_lossy(&result).to_string(),
span: call.head,
})
}
.into_pipeline_data())
}
Err(_err) => {
// FIXME: Move this to an external signature and add better error handling
Ok(Value::nothing())
Ok(PipelineData::new())
}
}
}
Err(_err) => {
// FIXME: Move this to an external signature and add better error handling
Ok(Value::nothing())
Ok(PipelineData::new())
}
}
}

View File

@@ -5,8 +5,11 @@ use std::process::Stdio;
use nu_protocol::ast::Call;
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::IntoPipelineData;
use nu_protocol::PipelineData;
use nu_protocol::{Signature, Value};
#[derive(Clone)]
pub struct ListGitBranches;
//NOTE: this is not a real implementation :D. It's just a simple one to test with until we port the real one.
@@ -27,8 +30,8 @@ impl Command for ListGitBranches {
&self,
_context: &EvaluationContext,
call: &Call,
_input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
_input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let list_branches = ProcessCommand::new("git")
.arg("branch")
.stdout(Stdio::piped())
@@ -55,15 +58,12 @@ impl Command for ListGitBranches {
})
.collect();
Ok(Value::List {
vals: lines,
span: call.head,
})
Ok(lines.into_iter().into_pipeline_data())
} else {
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
} else {
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
}
}