Skip to content

Commit

Permalink
refactor: rename config to plural
Browse files Browse the repository at this point in the history
BREAKING CHANGE: in `coco.yml`, the `repo` -> `repos`
  • Loading branch information
phodal committed Feb 24, 2021
1 parent 3f5440d commit 7295f02
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions _fixtures/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repo:
repos:
- url: https://github.com/coco-rs/coco.fixtures
- url: https://github.com/coco-rs/coco.fixtures2

message:
# should be a regexp
format: []
format: []
4 changes: 2 additions & 2 deletions coco.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repo:
repos:
- url: https://github.com/coco-rs/coco.fixtures
- url: https://github.com/coco-rs/coco.fixtures2
- url: .
- url: https://github.com/datum-lang/scie
- url: https://github.com/projectfluent/fluent-rs
language: [Rust, JavaScript]
languages: [Rust, JavaScript]

# todo: add commit
commit:
Expand Down
18 changes: 9 additions & 9 deletions core_model/src/coco_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use serde::{Deserialize, Serialize};
/// Coco Config from `coco.yml`
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct CocoConfig {
pub repo: Vec<RepoConfig>,
pub repos: Vec<RepoConfig>,
pub plugins: Vec<String>,
}

impl Default for CocoConfig {
fn default() -> Self {
CocoConfig {
repo: vec![],
repos: vec![],
plugins: vec![],
}
}
Expand All @@ -20,14 +20,14 @@ impl Default for CocoConfig {
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct RepoConfig {
pub url: String,
pub language: Option<Vec<String>>,
pub languages: Option<Vec<String>>,
}

impl Default for RepoConfig {
fn default() -> Self {
RepoConfig {
url: "".to_string(),
language: None,
languages: None,
}
}
}
Expand All @@ -36,7 +36,7 @@ impl RepoConfig {
pub fn new(url: &str) -> RepoConfig {
RepoConfig {
url: url.to_string(),
language: None,
languages: None,
}
}
}
Expand All @@ -48,16 +48,16 @@ mod test {
#[test]
fn should_parse_language() {
let data = r#"
repo:
repos:
- url: https://github.com/projectfluent/fluent-rs
language: [Rust, JavaScript]
languages: [Rust, JavaScript]
plugins:
- swagger
"#;
let config: CocoConfig = serde_yaml::from_str(&data).expect("parse config file error");
let repos = config.repo;
let languages = repos[0].language.as_ref().unwrap();
let repos = config.repos;
let languages = repos[0].languages.as_ref().unwrap();
assert_eq!(2, languages.len());
assert_eq!("Rust", languages[0]);
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/_fixtures/coco-fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
repo:
repos:
- url: https://github.com/coco-rs/coco.fixtures

# todo plugins
Expand Down
4 changes: 2 additions & 2 deletions plugins/coco_struct_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ mod tests {
let mut repos = vec![];
repos.push(RepoConfig {
url: format!("{}", ctags_fixtures_dir().display()),
language: None,
languages: None,
});
let config = CocoConfig {
repo: repos,
repos: repos,
plugins: vec![],
};

Expand Down
2 changes: 1 addition & 1 deletion plugins/coco_struct_analysis/src/struct_analysis_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ctags_opt::Opt;
use crate::ctags_parser::CtagsParser;

pub fn execute_struct_analysis(config: CocoConfig) {
for repo in config.repo {
for repo in config.repos {
let url_str = repo.url.as_str();

let origin_files = files_from_path(url_str);
Expand Down
2 changes: 1 addition & 1 deletion src/app/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Analyst {
impl From<&CocoConfig> for Analyst {
fn from(config: &CocoConfig) -> Self {
Self {
repos: config.repo.clone(),
repos: config.repos.clone(),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/bin/coco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fn create_config(config_file: &str) -> CocoConfig {
let current = env::current_dir().unwrap();
repo.push(RepoConfig {
url: current.into_os_string().to_str().unwrap().to_string(),
language: None,
languages: None,
});
CocoConfig {
repo: repo,
repos: repo,
plugins: vec![],
}
}
Expand All @@ -73,8 +73,8 @@ mod test {
let current = env::current_dir().unwrap();
let url = current.into_os_string().to_str().unwrap().to_string();

assert_eq!(config.repo.len(), 1);
assert_eq!(url, config.repo[0].url);
assert_eq!(config.repos.len(), 1);
assert_eq!(url, config.repos[0].url);
assert_eq!(config.plugins.len(), 0);
}
}

0 comments on commit 7295f02

Please sign in to comment.