Add repositories to the configuration file
This commit is contained in:
parent
17fd14d65e
commit
5cbea0c7fd
|
@ -1,13 +1,20 @@
|
||||||
use std::error::Error;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::error::Error;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
/// The internal representation of the configuration file.
|
/// The internal representation of the configuration file.
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub source_dir: String,
|
pub source_dir: String,
|
||||||
|
repositories: Vec<Repository>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
struct Repository {
|
||||||
|
name: String,
|
||||||
|
url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
@ -17,6 +24,7 @@ impl Config {
|
||||||
pub fn new() -> Config {
|
pub fn new() -> Config {
|
||||||
Config {
|
Config {
|
||||||
source_dir: format!("{}/sources", env::var("HOME").unwrap()),
|
source_dir: format!("{}/sources", env::var("HOME").unwrap()),
|
||||||
|
repositories: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +44,7 @@ impl Config {
|
||||||
// Get the path to the config file
|
// Get the path to the config file
|
||||||
let path = match Path::new(filename).parent() {
|
let path = match Path::new(filename).parent() {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
_ => Path::new(filename)
|
_ => Path::new(filename),
|
||||||
};
|
};
|
||||||
// Make sure the path exists
|
// Make sure the path exists
|
||||||
fs::create_dir_all(path).unwrap();
|
fs::create_dir_all(path).unwrap();
|
||||||
|
|
|
@ -6,7 +6,10 @@ fn main() {
|
||||||
let args = env::args();
|
let args = env::args();
|
||||||
let state = State::new(args);
|
let state = State::new(args);
|
||||||
let mut config = Config::new();
|
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) {
|
if let Err(e) = shepherd::run(state, config) {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue