convert: Allow --seats to override input file
This commit is contained in:
parent
88ab06d633
commit
61e4eefca3
|
@ -74,7 +74,7 @@ pub fn main(mut cmd_opts: SubcmdOptions) -> Result<(), i32> {
|
|||
}
|
||||
|
||||
// Read input file
|
||||
let election: Election<Rational>;
|
||||
let mut election: Election<Rational>;
|
||||
|
||||
match cmd_opts.r#in.as_deref().unwrap() {
|
||||
"blt" => {
|
||||
|
@ -89,20 +89,24 @@ pub fn main(mut cmd_opts: SubcmdOptions) -> Result<(), i32> {
|
|||
}
|
||||
}
|
||||
"csp" => {
|
||||
match cmd_opts.seats {
|
||||
Some(seats) => {
|
||||
let file = File::open(cmd_opts.infile).expect("IO Error");
|
||||
election = parser::csp::parse_reader(file, seats);
|
||||
}
|
||||
None => {
|
||||
println!("Error: --seats must be specified with CSP input");
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
let file = File::open(cmd_opts.infile).expect("IO Error");
|
||||
election = parser::csp::parse_reader(file);
|
||||
}
|
||||
_ => unreachable!()
|
||||
};
|
||||
|
||||
match cmd_opts.seats {
|
||||
Some(seats) => {
|
||||
election.seats = seats;
|
||||
}
|
||||
None => {
|
||||
if election.seats == 0 {
|
||||
println!("Error: --seats must be specified with CSP input");
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write output file
|
||||
let output = File::create(cmd_opts.outfile).expect("IO Error");
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ use std::collections::HashMap;
|
|||
use std::io::Read;
|
||||
|
||||
/// Parse the given CSP file
|
||||
pub fn parse_reader<R: Read, N: Number>(reader: R, seats: usize) -> Election<N> {
|
||||
pub fn parse_reader<R: Read, N: Number>(reader: R) -> Election<N> {
|
||||
// Read CSV file
|
||||
let mut reader = ReaderBuilder::new()
|
||||
.has_headers(true)
|
||||
|
@ -93,7 +93,7 @@ pub fn parse_reader<R: Read, N: Number>(reader: R, seats: usize) -> Election<N>
|
|||
|
||||
return Election {
|
||||
name: String::new(),
|
||||
seats: seats,
|
||||
seats: 0,
|
||||
candidates: candidates,
|
||||
withdrawn_candidates: Vec::new(),
|
||||
ballots: ballots,
|
||||
|
|
Loading…
Reference in New Issue