Skip to content

Commit

Permalink
Merge pull request #16 from ChristophWurst/release/030
Browse files Browse the repository at this point in the history
Version bump
  • Loading branch information
ChristophWurst authored Nov 22, 2017
2 parents 816e94b + 54dd61c commit a5e345b
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "krankerl"
version = "0.2.0"
version = "0.3.0"
authors = ["Christoph Wurst <[email protected]>"]
description = "A CLI helper to manage Nextcloud apps"

Expand Down
38 changes: 30 additions & 8 deletions src/config/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::Path;

use toml;

use super::{ConfigFileReader, ConfigReader};
use super::super::error;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -105,15 +106,16 @@ exclude = [
Ok(())
}

fn load_config(path: &Path) -> Result<String, error::Error> {
fn load_config<R>(path: &Path, reader: &R) -> Result<String, error::Error>
where
R: ConfigReader,
{
let mut path_buf = path.to_path_buf();
path_buf.push("krankerl.toml");

let mut file = File::open(path_buf)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let as_string = reader.read(&path_buf)?;

Ok(contents)
Ok(as_string)
}

fn parse_config(config: String) -> Result<ParsedAppConfig, error::Error> {
Expand All @@ -126,7 +128,8 @@ fn parse_config(config: String) -> Result<ParsedAppConfig, error::Error> {
}

pub fn get_config(path: &Path) -> Result<AppConfig, error::Error> {
let config_str = load_config(path)?;
let reader = ConfigFileReader::new();
let config_str = load_config(path, &reader)?;
parse_config(config_str).map(|config| config.into())
}

Expand All @@ -140,6 +143,24 @@ mod tests {

use super::*;

struct StaticReader {}

impl ConfigReader for StaticReader {
fn read(&self, path: &Path) -> Result<String, error::Error> {
Ok(path.to_str().unwrap().to_owned())
}
}

#[test]
fn test_load_config() {
let reader = StaticReader {};
let path = Path::new("my/app");

let conf = load_config(&path, &reader).unwrap();

assert_eq!("my/app/krankerl.toml".to_owned(), conf);
}

fn prepare_fs_test(id: &'static str) -> (PathBuf, TempDir) {
let mut src = PathBuf::from("./tests/apps");
src.push(id);
Expand Down Expand Up @@ -182,10 +203,11 @@ mod tests {
}

#[test]
fn test_load_config() {
fn test_load_real_config() {
let (app_path, tmp) = prepare_fs_test("app3");
let reader = ConfigFileReader::new();

load_config(&app_path).unwrap();
load_config(&app_path, &reader).unwrap();

tmp.close().unwrap();
}
Expand Down
3 changes: 3 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pub mod app;
pub mod krankerl;
mod reader;

pub use self::reader::{ConfigFileReader, ConfigReader};
27 changes: 27 additions & 0 deletions src/config/reader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::fs::File;
use std::io::Read;
use std::path::Path;

use error;

pub trait ConfigReader {
fn read(&self, path: &Path) -> Result<String, error::Error>;
}

pub struct ConfigFileReader {}

impl ConfigFileReader {
pub fn new() -> Self {
ConfigFileReader {}
}
}

impl ConfigReader for ConfigFileReader {
fn read(&self, path: &Path) -> Result<String, error::Error> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

Ok(contents)
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extern crate futures;
extern crate futures_cpupool;
extern crate globset;
extern crate hex;

extern crate nextcloud_appinfo;
extern crate nextcloud_appsignature;
extern crate nextcloud_appstore;
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use krankerl::packaging::package_app;
use tokio_core::reactor::Core;

const USAGE: &'static str = "
Krankerl. A CLI tool for the Nextcloud app store.
Krankerl. A CLI helper to manage Nextcloud apps.
Usage:
krankerl enable
Expand Down Expand Up @@ -149,6 +149,6 @@ fn main() {
println!("an error occured: {}", e);
});
} else if args.flag_version {
println!("v0.2.0");
println!(env!("CARGO_PKG_VERSION"));
}
}

0 comments on commit a5e345b

Please sign in to comment.