Add repositories to the configuration file

This commit is contained in:
Thom Dickson 2021-12-16 19:48:47 -05:00
parent 17fd14d65e
commit 5cbea0c7fd
Signed by: boots
GPG Key ID: 40BE2AF8EBF8D2BB
2 changed files with 16 additions and 5 deletions

View File

@ -1,13 +1,20 @@
use std::error::Error;
use serde::{Deserialize, Serialize};
use std::env;
use std::error::Error;
use std::fs;
use std::path::Path;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
/// The internal representation of the configuration file.
pub struct Config {
pub source_dir: String,
repositories: Vec<Repository>,
}
#[derive(Debug, Serialize, Deserialize)]
struct Repository {
name: String,
url: String,
}
impl Config {
@ -17,6 +24,7 @@ impl Config {
pub fn new() -> Config {
Config {
source_dir: format!("{}/sources", env::var("HOME").unwrap()),
repositories: vec![],
}
}
@ -34,9 +42,9 @@ impl Config {
} else {
let config: String = toml::to_string(&self)?;
// Get the path to the config file
let path = match Path::new(filename).parent() {
let path = match Path::new(filename).parent() {
Some(x) => x,
_ => Path::new(filename)
_ => Path::new(filename),
};
// Make sure the path exists
fs::create_dir_all(path).unwrap();

View File

@ -6,7 +6,10 @@ fn main() {
let args = env::args();
let state = State::new(args);
let mut config = Config::new();
config.read_config(&state.config).unwrap();
if let Err(e) = config.read_config(&state.config) {
eprintln!("Configuration Error: {}", e);
std::process::exit(1);
}
if let Err(e) = shepherd::run(state, config) {
eprintln!("{}", e);
}