提交 958baf90 编写于 作者: H hustccc

add some unfinished code

上级 94506583
......@@ -14,6 +14,7 @@ use simple_logger::SimpleLogger;
pub struct Git<'a> {
exe: Command,
args: Vec<&'a str>,
work_dir: Option<&'a str>,
}
......@@ -24,10 +25,12 @@ impl<'a> XSCommand<'a, GitErr> for Git<'a> {
Self {
exe: git,
args,
work_dir: None,
}
}
fn set_args(&mut self, args: Vec<&'a str>) -> Result<(), GitErr> {
// TODO: check the rationality of args
self.args = args;
Ok(())
}
......@@ -42,10 +45,13 @@ impl<'a> XSCommand<'a, GitErr> for Git<'a> {
args
}
fn set_workdir(&mut self, work_dir: &'a str) -> Result<(), GitErr> {
// TODO: check the rationality of workdir
self.work_dir = Some(work_dir);
Ok(())
}
fn excute(&mut self, stdout: Option<&str>, stderr: Option<&str>) -> Result<i32, GitErr> {
// Init the logger
// let logger = SimpleLogger::new();
// logger.init().unwrap();
for arg in &self.args {
self.exe.arg(arg);
}
......@@ -60,6 +66,9 @@ impl<'a> XSCommand<'a, GitErr> for Git<'a> {
let err_out = unsafe { Stdio::from_raw_fd(stderr_fd) };
self.exe.stderr(err_out);
}
if let Some(dir) = self.work_dir {
self.exe.current_dir(dir);
}
let res = self.exe.status();
match res {
Ok(exit_status) => {
......
//! `xscommand` crate is for abstraction of command used in XiangShan development
//! like `sh`, `git` and `emu` which is a simulator in the development of XiangShan
//!
//! The project use this crate should init the [logger](https://github.com/rust-lang/log) in the main.rs, like this:
//! ```no_run
//! extern crate simple_logger;
//! use simple_logger::SimpleLogger;
//!
//! fn main() {
//! let logger = SimpleLogger::new();
//! logger.init().unwrap();
//! ...
//! }
//! ```
pub mod git;
use std::fmt::Debug;
......@@ -15,6 +25,8 @@ pub trait XSCommand<'a, T: XSCommandErr + Debug> {
fn set_args(&mut self, args: Vec<&'a str>) -> Result<(), T>;
/// Get arguments
fn get_args(&self) -> Vec<&str>;
/// Set the working dir for the XSCommand
fn set_workdir(&mut self, work_dir: &'a str) -> Result<(), T>;
/// Excute the command
/// Return exit code
fn excute(&mut self, stdout: Option<&str>, stderr: Option<&str>) -> Result<i32, T>;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册