2020-10-26 13:55:05 +01:00
|
|
|
// Dancing Droids
|
2020-10-26 15:29:14 +01:00
|
|
|
// Copyright (C) 2020 Martin HART, Volodymyr PATUTA, Stephane Elias BENABDESLAM
|
2020-10-26 13:55:05 +01:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-10-20 12:48:28 +02:00
|
|
|
use clap::{App, Arg};
|
2020-10-13 10:31:50 +02:00
|
|
|
use std::fs;
|
|
|
|
use std::io;
|
|
|
|
|
2020-10-17 18:16:40 +02:00
|
|
|
/// Retrieve the content of a file and return it as a string.
|
2020-10-13 10:19:34 +02:00
|
|
|
fn open_file(filename: &str) -> io::Result<String> {
|
|
|
|
let content = fs::read_to_string(filename)?;
|
|
|
|
Ok(content)
|
|
|
|
}
|
|
|
|
|
2020-10-19 12:50:48 +02:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2020-10-20 13:42:32 +02:00
|
|
|
// We handle CLI flags here.
|
2020-10-20 12:48:28 +02:00
|
|
|
let matches = App::new("DancingDroids")
|
|
|
|
.version("0.1.0")
|
|
|
|
.about("When droids dance togethers")
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("file")
|
|
|
|
.short("f")
|
|
|
|
.long("file")
|
|
|
|
.takes_value(true)
|
|
|
|
.help("Configuration file"),
|
|
|
|
)
|
|
|
|
.get_matches();
|
|
|
|
|
2020-10-20 13:17:50 +02:00
|
|
|
let raw_conf = open_file(matches.value_of("file").unwrap_or("two_robots.txt"))?;
|
2020-10-20 14:06:10 +02:00
|
|
|
|
2020-10-19 12:50:48 +02:00
|
|
|
Ok(())
|
2020-10-11 15:14:20 +02:00
|
|
|
}
|
2020-10-13 12:07:47 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2020-10-13 12:15:04 +02:00
|
|
|
#[test]
|
|
|
|
fn test_open_file() {
|
|
|
|
assert!(open_file("two_robots.txt").is_ok());
|
|
|
|
assert!(open_file("test_unexisting_file.extension").is_err());
|
|
|
|
}
|
2020-10-13 12:07:47 +02:00
|
|
|
}
|