Compare commits
No commits in common. "a3b2f3da7411691154321ea1ec64df3ac4813457" and "ad5e96782a0c1c08d6fc3ec45db0b51630cd88cd" have entirely different histories.
a3b2f3da74
...
ad5e96782a
4 changed files with 9 additions and 55 deletions
|
@ -18,45 +18,6 @@ pub trait Command {
|
||||||
fn spawn(&self) -> ExitCode;
|
fn spawn(&self) -> ExitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CommandSequence {
|
|
||||||
command: Option<Box<dyn Command>>,
|
|
||||||
next_command: Option<Box<dyn Command>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandSequence {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
command: None,
|
|
||||||
next_command: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
pub fn add(&self, command: &dyn Command) {
|
|
||||||
if self.command.is_none() {
|
|
||||||
let my_box = Box::new(command.to_owned());
|
|
||||||
self.command = Some(my_box);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Command for CommandSequence {
|
|
||||||
fn spawn(&self) -> ExitCode {
|
|
||||||
let mut exit_code = ExitCode::new(0);
|
|
||||||
|
|
||||||
if self.command.is_some() {
|
|
||||||
exit_code = self.command.as_ref().unwrap().spawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.next_command.is_some() {
|
|
||||||
exit_code = self.next_command.as_ref().unwrap().spawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
exit_code
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UnixProgram {
|
pub struct UnixProgram {
|
||||||
argv: Vec<String>,
|
argv: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::command::{Command, ExitCode};
|
use crate::command::{Command, ExitCode, UnixProgram};
|
||||||
use crate::interface::{get_user_input, print_prompt};
|
use crate::interface::{get_user_input, print_prompt};
|
||||||
use crate::parser::parse_command_line;
|
|
||||||
|
|
||||||
fn exit(code: &ExitCode) {
|
fn exit(code: &ExitCode) {
|
||||||
let code = i32::from(code.get());
|
let code = i32::from(code.get());
|
||||||
|
@ -18,9 +17,15 @@ pub fn run() {
|
||||||
|
|
||||||
if user_input.is_some() {
|
if user_input.is_some() {
|
||||||
let user_input = user_input.unwrap();
|
let user_input = user_input.unwrap();
|
||||||
let command_sequence = parse_command_line(user_input);
|
|
||||||
|
|
||||||
current_exit_code = command_sequence.spawn();
|
let argv: Vec<String> = user_input
|
||||||
|
.split_whitespace()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
if !argv.is_empty() {
|
||||||
|
current_exit_code = UnixProgram::new().argv(argv).spawn();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
println!();
|
println!();
|
||||||
exit(¤t_exit_code);
|
exit(¤t_exit_code);
|
||||||
|
|
|
@ -2,7 +2,6 @@ mod command;
|
||||||
mod control;
|
mod control;
|
||||||
mod error;
|
mod error;
|
||||||
mod interface;
|
mod interface;
|
||||||
mod parser;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
control::run();
|
control::run();
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
use crate::command::{CommandSequence, UnixProgram};
|
|
||||||
|
|
||||||
pub fn parse_command_line(line: String) -> CommandSequence {
|
|
||||||
let /*mut*/ command_sequence = CommandSequence::new();
|
|
||||||
|
|
||||||
let argv = line.split_whitespace().map(|s| s.to_string()).collect();
|
|
||||||
let _command = UnixProgram::new().argv(argv);
|
|
||||||
// command_sequence.add(command);
|
|
||||||
|
|
||||||
command_sequence
|
|
||||||
}
|
|
Loading…
Reference in a new issue