Formatting convention corrections, some cleanup.
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::Gamemode;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Character {
|
pub struct Character {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub standing: Standing
|
pub standing: Standing,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Character {
|
impl Character {
|
||||||
@@ -47,7 +47,7 @@ pub struct Standing {
|
|||||||
pub society: i8,
|
pub society: i8,
|
||||||
pub court: i8,
|
pub court: i8,
|
||||||
pub friends: Vec<&'static People>,
|
pub friends: Vec<&'static People>,
|
||||||
pub enemies: Vec<&'static People>
|
pub enemies: Vec<&'static People>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Standing {
|
impl Standing {
|
||||||
@@ -90,7 +90,7 @@ pub enum People {
|
|||||||
SarahGood(Option<Character>),
|
SarahGood(Option<Character>),
|
||||||
SusannaWalcott(Option<Character>),
|
SusannaWalcott(Option<Character>),
|
||||||
ThomasPutnam(Option<Character>),
|
ThomasPutnam(Option<Character>),
|
||||||
Tituba(Option<Character>)
|
Tituba(Option<Character>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl People {
|
impl People {
|
||||||
@@ -109,7 +109,7 @@ impl People {
|
|||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::ElizabethProctor(None),
|
&People::ElizabethProctor(None),
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::ReverendJohnHale(None)
|
&People::ReverendJohnHale(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -122,12 +122,12 @@ impl People {
|
|||||||
&People::BettyParris(None),
|
&People::BettyParris(None),
|
||||||
&People::ThomasPutnam(None),
|
&People::ThomasPutnam(None),
|
||||||
&People::ReverendParris(None),
|
&People::ReverendParris(None),
|
||||||
&People::MercyLewis(None)
|
&People::MercyLewis(None),
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::ElizabethProctor(None),
|
&People::ElizabethProctor(None),
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::RebeccaNurse(None)
|
&People::RebeccaNurse(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -138,11 +138,11 @@ impl People {
|
|||||||
court: 10,
|
court: 10,
|
||||||
friends: vec![
|
friends: vec![
|
||||||
&People::AbigailWilliams(None),
|
&People::AbigailWilliams(None),
|
||||||
&People::ReverendParris(None)
|
&People::ReverendParris(None),
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::ElizabethProctor(None)
|
&People::ElizabethProctor(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -156,7 +156,7 @@ impl People {
|
|||||||
&People::JudgeHathorne(None),
|
&People::JudgeHathorne(None),
|
||||||
&People::ReverendParris(None),
|
&People::ReverendParris(None),
|
||||||
&People::EzekielCheever(None),
|
&People::EzekielCheever(None),
|
||||||
&People::MarshalHerrick(None)
|
&People::MarshalHerrick(None),
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::ElizabethProctor(None),
|
&People::ElizabethProctor(None),
|
||||||
@@ -164,7 +164,7 @@ impl People {
|
|||||||
&People::ReverendJohnHale(None),
|
&People::ReverendJohnHale(None),
|
||||||
&People::FrancisNurse(None),
|
&People::FrancisNurse(None),
|
||||||
&People::GilesCorey(None),
|
&People::GilesCorey(None),
|
||||||
&People::MarthaCorey(None)
|
&People::MarthaCorey(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -178,12 +178,12 @@ impl People {
|
|||||||
&People::GilesCorey(None),
|
&People::GilesCorey(None),
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::RebeccaNurse(None),
|
&People::RebeccaNurse(None),
|
||||||
&People::ReverendJohnHale(None)
|
&People::ReverendJohnHale(None),
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::AbigailWilliams(None),
|
&People::AbigailWilliams(None),
|
||||||
&People::DeputyGovernorDanforth(None),
|
&People::DeputyGovernorDanforth(None),
|
||||||
&People::EzekielCheever(None)
|
&People::EzekielCheever(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -197,14 +197,14 @@ impl People {
|
|||||||
&People::DeputyGovernorDanforth(None),
|
&People::DeputyGovernorDanforth(None),
|
||||||
&People::ReverendParris(None),
|
&People::ReverendParris(None),
|
||||||
&People::ReverendJohnHale(None),
|
&People::ReverendJohnHale(None),
|
||||||
&People::JudgeHathorne(None)
|
&People::JudgeHathorne(None),
|
||||||
|
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::ElizabethProctor(None),
|
&People::ElizabethProctor(None),
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::FrancisNurse(None),
|
&People::FrancisNurse(None),
|
||||||
&People::GilesCorey(None)
|
&People::GilesCorey(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -223,7 +223,7 @@ impl People {
|
|||||||
&People::AbigailWilliams(None),
|
&People::AbigailWilliams(None),
|
||||||
&People::ReverendJohnHale(None),
|
&People::ReverendJohnHale(None),
|
||||||
&People::JudgeHathorne(None),
|
&People::JudgeHathorne(None),
|
||||||
&People::ThomasPutnam(None)
|
&People::ThomasPutnam(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -237,7 +237,7 @@ impl People {
|
|||||||
&People::FrancisNurse(None),
|
&People::FrancisNurse(None),
|
||||||
&People::JohnProctor(None),
|
&People::JohnProctor(None),
|
||||||
&People::MarthaCorey(None),
|
&People::MarthaCorey(None),
|
||||||
&People::GilesCorey(None)
|
&People::GilesCorey(None),
|
||||||
],
|
],
|
||||||
enemies: vec![
|
enemies: vec![
|
||||||
&People::ThomasPutnam(None),
|
&People::ThomasPutnam(None),
|
||||||
@@ -246,7 +246,7 @@ impl People {
|
|||||||
&People::JudgeHathorne(None),
|
&People::JudgeHathorne(None),
|
||||||
&People::EzekielCheever(None),
|
&People::EzekielCheever(None),
|
||||||
&People::MarshalHerrick(None),
|
&People::MarshalHerrick(None),
|
||||||
&People::AbigailWilliams(None)
|
&People::AbigailWilliams(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -264,7 +264,7 @@ impl People {
|
|||||||
&People::EzekielCheever(None),
|
&People::EzekielCheever(None),
|
||||||
&People::JudgeHathorne(None),
|
&People::JudgeHathorne(None),
|
||||||
&People::ReverendJohnHale(None),
|
&People::ReverendJohnHale(None),
|
||||||
&People::MarshalHerrick(None)
|
&People::MarshalHerrick(None),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
@@ -296,7 +296,7 @@ impl Distribution<People> for Standard {
|
|||||||
19 => People::SusannaWalcott(None),
|
19 => People::SusannaWalcott(None),
|
||||||
20 => People::ThomasPutnam(None),
|
20 => People::ThomasPutnam(None),
|
||||||
21 => People::Tituba(None),
|
21 => People::Tituba(None),
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,5 +305,5 @@ impl Distribution<People> for Standard {
|
|||||||
pub enum SurvivalStatus {
|
pub enum SurvivalStatus {
|
||||||
PlayerMassacred,
|
PlayerMassacred,
|
||||||
PlayerLived,
|
PlayerLived,
|
||||||
PlayerDied
|
PlayerDied,
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,22 @@ use std::i8;
|
|||||||
|
|
||||||
use rand::{
|
use rand::{
|
||||||
distributions::{Distribution, Standard},
|
distributions::{Distribution, Standard},
|
||||||
rngs::ThreadRng
|
rngs::ThreadRng,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::characters::{
|
use crate::characters::{
|
||||||
Character,
|
Character,
|
||||||
People,
|
People,
|
||||||
SurvivalStatus
|
SurvivalStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_event() -> Events {
|
|
||||||
Events::Trial(Trial)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub trait EventHandle {
|
pub trait EventHandle {
|
||||||
fn handle<'main>(
|
fn handle<'a>(
|
||||||
self: &Self,
|
self: &Self,
|
||||||
rng: &'main ThreadRng,
|
rng: &'a ThreadRng,
|
||||||
player: &'main mut Character,
|
player: &'a mut Character,
|
||||||
characters: &'main mut Vec<People>
|
characters: &'a mut Vec<People>,
|
||||||
) -> EventReturn {
|
) -> EventReturn {
|
||||||
EventReturn::None
|
EventReturn::None
|
||||||
}
|
}
|
||||||
@@ -31,13 +27,13 @@ pub trait EventHandle {
|
|||||||
pub struct Trial;
|
pub struct Trial;
|
||||||
|
|
||||||
impl EventHandle for Trial {
|
impl EventHandle for Trial {
|
||||||
fn handle<'main>(
|
fn handle<'a>(
|
||||||
self: &Self,
|
self: &Self,
|
||||||
rng: &'main ThreadRng,
|
rng: &'a ThreadRng,
|
||||||
player: &'main mut Character,
|
player: &'a mut Character,
|
||||||
characters: &'main mut Vec<People>
|
characters: &'a mut Vec<People>,
|
||||||
) -> EventReturn {
|
) -> EventReturn {
|
||||||
let mut player_status = SurvivalStatus::PlayerDied;
|
let mut player_status: SurvivalStatus = SurvivalStatus::PlayerDied;
|
||||||
|
|
||||||
println!("You have been summoned before the court.\n");
|
println!("You have been summoned before the court.\n");
|
||||||
|
|
||||||
@@ -53,11 +49,11 @@ impl EventHandle for Trial {
|
|||||||
pub struct WildAccusation;
|
pub struct WildAccusation;
|
||||||
|
|
||||||
impl EventHandle for WildAccusation {
|
impl EventHandle for WildAccusation {
|
||||||
fn handle<'main>(
|
fn handle<'a>(
|
||||||
self: &Self,
|
self: &Self,
|
||||||
rng: &'main ThreadRng,
|
rng: &'a ThreadRng,
|
||||||
player: &'main mut Character,
|
player: &'a mut Character,
|
||||||
characters: &'main mut Vec<People>
|
characters: &'a mut Vec<People>,
|
||||||
) -> EventReturn {
|
) -> EventReturn {
|
||||||
EventReturn::None
|
EventReturn::None
|
||||||
}
|
}
|
||||||
@@ -65,15 +61,15 @@ impl EventHandle for WildAccusation {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Events {
|
pub enum Events {
|
||||||
Trial(Trial)
|
Trial(Trial),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Distribution<Events> for Standard {
|
impl Distribution<Events> for Standard {
|
||||||
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Events {
|
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Events {
|
||||||
match rng.gen_range(0..=0) {
|
match rng.gen_range(0..=0) {
|
||||||
0 => Events::Trial(Trial),
|
0 => Events::Trial(Trial),
|
||||||
1 => Events::Trial(Trial),
|
1 => todo!(),
|
||||||
_ => unreachable!()
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,5 +77,5 @@ impl Distribution<Events> for Standard {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum EventReturn {
|
pub enum EventReturn {
|
||||||
Survival(SurvivalStatus),
|
Survival(SurvivalStatus),
|
||||||
None
|
None,
|
||||||
}
|
}
|
||||||
109
src/main.rs
109
src/main.rs
@@ -5,76 +5,85 @@ mod utils;
|
|||||||
use characters::{
|
use characters::{
|
||||||
Character,
|
Character,
|
||||||
People,
|
People,
|
||||||
SurvivalStatus
|
SurvivalStatus,
|
||||||
};
|
};
|
||||||
|
|
||||||
use events::{
|
use events::{
|
||||||
get_event, EventHandle, EventReturn, Events, Trial
|
EventHandle,
|
||||||
|
EventReturn,
|
||||||
|
Events,
|
||||||
|
Trial,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rand::{
|
use rand::{
|
||||||
random,
|
random,
|
||||||
thread_rng
|
thread_rng,
|
||||||
|
rngs::ThreadRng
|
||||||
};
|
};
|
||||||
|
|
||||||
use utils::{
|
use utils::{
|
||||||
fmt_args,
|
fmt_args,
|
||||||
ArgType,
|
ArgType,
|
||||||
FlagType
|
FlagType,
|
||||||
};
|
};
|
||||||
|
|
||||||
//Number of game rounds.
|
//Number of game rounds.
|
||||||
const ROUNDS: u8 = 15;
|
const ROUNDS: u8 = 15;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cmd_args = dbg!(fmt_args());
|
let cmd_args: Vec<ArgType> = fmt_args();
|
||||||
let mut characters = People::build_characters();
|
let mut characters: Vec<People> = People::build_characters();
|
||||||
let mut rng = thread_rng();
|
let rng: ThreadRng = thread_rng();
|
||||||
|
|
||||||
// Set player default values based on gamemode.
|
// Set player default values based on gamemode.
|
||||||
let mut player: Character = dbg!(Character::build_player(Gamemode::get(&cmd_args)));
|
let mut player: Character = Character::build_player(Gamemode::get(&cmd_args));
|
||||||
let mut end_status = SurvivalStatus::PlayerLived;
|
let mut end_status: SurvivalStatus = SurvivalStatus::PlayerLived;
|
||||||
|
|
||||||
// Game loop.
|
// Game loop.
|
||||||
for r in 0..=ROUNDS {
|
for r in 0..=ROUNDS {
|
||||||
let random_event: Events = random();
|
end_status = run_event(
|
||||||
|
&rng,
|
||||||
|
&mut player,
|
||||||
|
&mut characters,
|
||||||
|
random(),
|
||||||
|
);
|
||||||
|
|
||||||
match random_event {
|
if matches!(end_status, SurvivalStatus::PlayerLived) { break }
|
||||||
Events::Trial(trial) => match trial.handle(&rng, &mut player, &mut characters) {
|
|
||||||
EventReturn::Survival(state) => match state {
|
|
||||||
SurvivalStatus::PlayerLived => (),
|
|
||||||
_ => {end_status = state}
|
|
||||||
}
|
|
||||||
_ => unreachable!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match end_status {
|
|
||||||
SurvivalStatus::PlayerLived => (),
|
|
||||||
_ => break
|
|
||||||
}
|
|
||||||
|
|
||||||
// If player's standing is too low, bring to court.
|
|
||||||
if player.standing.clone().calculate() <= 0 {
|
|
||||||
match Trial.handle(&rng, &mut player, &mut characters) {
|
|
||||||
EventReturn::Survival(state) => match state {
|
|
||||||
SurvivalStatus::PlayerLived => (),
|
|
||||||
_ => {end_status = state}
|
|
||||||
},
|
|
||||||
_ => unreachable!()
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if r == ROUNDS {
|
|
||||||
end_status = SurvivalStatus::PlayerLived
|
|
||||||
};
|
|
||||||
|
|
||||||
if characters.len() == 0 {
|
if characters.len() == 0 {
|
||||||
end_status = SurvivalStatus::PlayerMassacred
|
end_status = SurvivalStatus::PlayerMassacred
|
||||||
|
} else if r == ROUNDS {
|
||||||
|
end_status = SurvivalStatus::PlayerLived
|
||||||
|
} else if player.standing.clone().calculate() <= 0 {
|
||||||
|
//Standing too low, bring to court.
|
||||||
|
end_status = run_event(
|
||||||
|
&rng,
|
||||||
|
&mut player,
|
||||||
|
&mut characters,
|
||||||
|
Events::Trial(Trial),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match end_status {
|
match end_status {
|
||||||
SurvivalStatus::PlayerDied => println!("You died. And for what?"),
|
SurvivalStatus::PlayerDied => println!("You died. And for what?"),
|
||||||
SurvivalStatus::PlayerLived => println!("You survived, but at what cost? How many died to save you?"),
|
SurvivalStatus::PlayerLived => println!("You survived, but at what cost? How many died to save you?"),
|
||||||
SurvivalStatus::PlayerMassacred => println!("You killed everyone. I ask, at what end will you yield. Care you not for the life of others?")
|
SurvivalStatus::PlayerMassacred => println!("You killed everyone. I ask, at what end will you yield. Care you not for the life of others?"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_event<'main>(
|
||||||
|
rng: &ThreadRng ,
|
||||||
|
player: &mut Character,
|
||||||
|
characters: &mut Vec<People>,
|
||||||
|
event: Events,
|
||||||
|
) -> SurvivalStatus {
|
||||||
|
match event {
|
||||||
|
Events::Trial(trial) => match trial.handle(rng, player, characters) {
|
||||||
|
EventReturn::Survival(state) => state,
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,34 +96,34 @@ pub enum Gamemode {
|
|||||||
//Hard
|
//Hard
|
||||||
JohnProctor,
|
JohnProctor,
|
||||||
//Just dead.
|
//Just dead.
|
||||||
GoodyOsborne
|
GoodyOsborne,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Gamemode {
|
impl Gamemode {
|
||||||
fn get(cmd_args: &Vec<ArgType>) -> Gamemode {
|
fn get(cmd_args: &Vec<ArgType>) -> Gamemode {
|
||||||
if cmd_args.len() != 1 {
|
if cmd_args.len() != 1 {
|
||||||
match &cmd_args[1] {
|
match &cmd_args[1] {
|
||||||
ArgType::Command(c) => match c.as_str() {
|
ArgType::Command(command) => match command.as_str() {
|
||||||
"abigail" => Gamemode::Abigail,
|
"abigail" => Gamemode::Abigail,
|
||||||
"john_proctor" => Gamemode::JohnProctor,
|
"john_proctor" => Gamemode::JohnProctor,
|
||||||
"goody_osborne" => Gamemode::GoodyOsborne,
|
"goody_osborne" => Gamemode::GoodyOsborne,
|
||||||
_ => Gamemode::MaryWarren
|
_ => Gamemode::MaryWarren,
|
||||||
},
|
},
|
||||||
ArgType::Flag(f) => match f {
|
ArgType::Flag(flag) => match flag {
|
||||||
FlagType::Long(l) => match l.as_str() {
|
FlagType::Long(flag_long) => match flag_long.as_str() {
|
||||||
"abigail" => Gamemode::Abigail,
|
"abigail" => Gamemode::Abigail,
|
||||||
"john-proctor" => Gamemode::JohnProctor,
|
"john-proctor" => Gamemode::JohnProctor,
|
||||||
"goody-osborne" => Gamemode::GoodyOsborne,
|
"goody-osborne" => Gamemode::GoodyOsborne,
|
||||||
_ => Gamemode::MaryWarren
|
_ => Gamemode::MaryWarren,
|
||||||
},
|
},
|
||||||
FlagType::Short(s) => match s.as_str() {
|
FlagType::Short(flag_short) => match flag_short.as_str() {
|
||||||
"a" => Gamemode::Abigail,
|
"a" => Gamemode::Abigail,
|
||||||
"j" => Gamemode::JohnProctor,
|
"j" => Gamemode::JohnProctor,
|
||||||
"o" => Gamemode::GoodyOsborne,
|
"o" => Gamemode::GoodyOsborne,
|
||||||
_ => Gamemode::MaryWarren
|
_ => Gamemode::MaryWarren,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
_ => Gamemode::MaryWarren
|
_ => Gamemode::MaryWarren,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Gamemode::MaryWarren
|
Gamemode::MaryWarren
|
||||||
|
|||||||
40
src/utils.rs
40
src/utils.rs
@@ -1,42 +1,38 @@
|
|||||||
use std::env::args;
|
use std::{
|
||||||
use std::io;
|
env::args,
|
||||||
|
io,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const DASH:char = 45 as u8 as char;
|
const DASH: char = 45 as u8 as char;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum ArgType {
|
pub enum ArgType {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
Binary(String),
|
Binary(String),
|
||||||
Command(String),
|
Command(String),
|
||||||
Flag(FlagType)
|
Flag(FlagType),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum FlagType {
|
pub enum FlagType {
|
||||||
//Currently only handles single flags. eg. "-S", "-y"
|
//Currently only handles single flags. eg. "-S", "-y"
|
||||||
Short(String),
|
Short(String),
|
||||||
Long(String)
|
Long(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fmt_args() -> Vec<ArgType> {
|
pub fn fmt_args() -> Vec<ArgType> {
|
||||||
let mut args_vec:Vec<ArgType> = Vec::new();
|
let mut args_vec:Vec<ArgType> = Vec::new();
|
||||||
|
|
||||||
for x in args() {
|
for obj in args() { match try_flag(obj.clone()) {
|
||||||
match try_flag(x.clone()) {
|
None => args_vec.push(ArgType::Command(obj)),
|
||||||
None => args_vec.push(ArgType::Command(x)),
|
Some(flag) => args_vec.push(ArgType::Flag(flag)),
|
||||||
Some(f) => args_vec.push(ArgType::Flag(f))
|
}}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
args_vec[0] = {
|
args_vec[0] = ArgType::Binary(match args_vec[0].clone() {
|
||||||
ArgType::Binary({
|
ArgType::Command(command) => command,
|
||||||
match args_vec[0].clone() {
|
err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err)
|
||||||
ArgType::Command(c) => c,
|
});
|
||||||
err => panic!("Expected ArgType::Command at args_vec[0], found {:?}", err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
args_vec
|
args_vec
|
||||||
}
|
}
|
||||||
@@ -59,15 +55,13 @@ fn break_flag_short(mut arg: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn break_flag_long(mut arg: String) -> String {
|
fn break_flag_long(mut arg: String) -> String {
|
||||||
for _ in 1..=2 {
|
for _ in 1..=2 { arg.remove(0); };
|
||||||
arg.remove(0);
|
|
||||||
};
|
|
||||||
|
|
||||||
arg
|
arg
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn input() -> String {
|
pub fn input() -> String {
|
||||||
let mut input_buffer = String::new();
|
let mut input_buffer: String = String::new();
|
||||||
|
|
||||||
io::stdin()
|
io::stdin()
|
||||||
.read_line( &mut input_buffer)
|
.read_line( &mut input_buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user