summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/main.rs b/src/main.rs
index 307c1f9..9fd7963 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,7 +18,7 @@ fn main() {
Some(("random", sub_matches)) => {
let random_command = sub_matches.subcommand().unwrap();
match random_command {
- ("henchman", _) => {
+ ("henchman", henchman_matches) => {
let class_name = random_tables.roll_table("henchman_class").to_string();
let race_name = random_tables.roll_table("henchman_race").to_string();
// HACK: Need a proper way to do lookups, shouldn't rely on
@@ -43,22 +43,50 @@ fn main() {
);
npc.roll_henchman_ability_scores();
let ability_scores = npc.ability_scores.unwrap();
- println!(
- "{} {} {}. STR {}, INT {}, WIS {}, CON {}, DEX {}, CHA {}",
- npc.alignment.unwrap(),
- npc.race.unwrap().name,
- npc.class.unwrap().name,
- ability_scores.get_score(AbilityScore::Strength).unwrap(),
- ability_scores
- .get_score(AbilityScore::Intelligence)
- .unwrap(),
- ability_scores.get_score(AbilityScore::Wisdom).unwrap(),
- ability_scores
- .get_score(AbilityScore::Constitution)
- .unwrap(),
- ability_scores.get_score(AbilityScore::Dexterity).unwrap(),
- ability_scores.get_score(AbilityScore::Charisma).unwrap()
- );
+
+ let output_csv = henchman_matches.get_flag("csv");
+
+ // TODO: DRY. Can't store template in a variable since println! needs the
+ // string literal at compile time.
+ if output_csv {
+ println!(
+ "{},{},{},{},{},{},{},{},{}",
+ npc.alignment
+ .unwrap()
+ .split_whitespace()
+ .map(|word| word.chars().next().unwrap())
+ .collect::<String>(),
+ npc.race.unwrap().name,
+ npc.class.unwrap().name,
+ ability_scores.get_score(AbilityScore::Strength).unwrap(),
+ ability_scores
+ .get_score(AbilityScore::Intelligence)
+ .unwrap(),
+ ability_scores.get_score(AbilityScore::Wisdom).unwrap(),
+ ability_scores
+ .get_score(AbilityScore::Constitution)
+ .unwrap(),
+ ability_scores.get_score(AbilityScore::Dexterity).unwrap(),
+ ability_scores.get_score(AbilityScore::Charisma).unwrap()
+ );
+ } else {
+ println!(
+ "{} {} {}. STR {}, INT {}, WIS {}, CON {}, DEX {}, CHA {}",
+ npc.alignment.unwrap(),
+ npc.race.unwrap().name,
+ npc.class.unwrap().name,
+ ability_scores.get_score(AbilityScore::Strength).unwrap(),
+ ability_scores
+ .get_score(AbilityScore::Intelligence)
+ .unwrap(),
+ ability_scores.get_score(AbilityScore::Wisdom).unwrap(),
+ ability_scores
+ .get_score(AbilityScore::Constitution)
+ .unwrap(),
+ ability_scores.get_score(AbilityScore::Dexterity).unwrap(),
+ ability_scores.get_score(AbilityScore::Charisma).unwrap()
+ );
+ };
}
("magic", _) => {
let magic = random_tables.roll_table("ua_magic");