Skip to content

Commit

Permalink
feat(config): Change .cobalt.yml to _cobalt.yml
Browse files Browse the repository at this point in the history
Why?
- Better aligns with other `_` prefixed files in cobalt
- The file is meant for humans
- This is what Jekyll does

Fixes cobalt-org#348
  • Loading branch information
epage committed Jan 4, 2018
1 parent 4f8ec19 commit c4ee83b
Show file tree
Hide file tree
Showing 20 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/bin/cobalt/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn get_config_args() -> Vec<clap::Arg<'static, 'static>> {
.short("c")
.long("config")
.value_name("FILE")
.help("Config file to use [default: .cobalt.yml]")
.help("Config file to use [default: _cobalt.yml]")
.takes_value(true),
clap::Arg::with_name("destination")
.short("d")
Expand Down
7 changes: 7 additions & 0 deletions src/bin/cobalt/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;
use std::ffi;
use std::fs;
use std::path;

use clap;
Expand Down Expand Up @@ -49,6 +50,12 @@ fn migrate_config(config_path: Option<&str>) -> Result<()> {
};
let config: cobalt::ConfigBuilder = config.into();
let content = config.to_string();

fs::remove_file(&config_path)?;

let mut config_path = config_path;
config_path.set_file_name("_cobalt.yml");
let config_path = config_path;
cobalt_model::files::write_document_file(content, config_path)?;

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions src/cobalt_model/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ impl ConfigBuilder {
}

fn from_cwd_internal(cwd: path::PathBuf) -> Result<ConfigBuilder> {
let file_path = files::find_project_file(&cwd, ".cobalt.yml");
let file_path = files::find_project_file(&cwd, "_cobalt.yml");
let config = file_path
.map(|p| {
info!("Using config file {:?}", &p);
Self::from_file(&p).chain_err(|| format!("Error reading config file {:?}", p))
})
.unwrap_or_else(|| {
warn!("No .cobalt.yml file found in current directory, using default config.");
warn!("No _cobalt.yml file found in current directory, using default config.");
let config = ConfigBuilder {
root: cwd,
..Default::default()
Expand Down Expand Up @@ -383,7 +383,7 @@ impl Default for Config {

#[test]
fn test_from_file_ok() {
let result = ConfigBuilder::from_file("tests/fixtures/config/.cobalt.yml").unwrap();
let result = ConfigBuilder::from_file("tests/fixtures/config/_cobalt.yml").unwrap();
assert_eq!(result.root,
path::Path::new("tests/fixtures/config").to_path_buf());
}
Expand Down Expand Up @@ -435,7 +435,7 @@ fn test_build_default() {

#[test]
fn test_build_dest() {
let result = ConfigBuilder::from_file("tests/fixtures/config/.cobalt.yml").unwrap();
let result = ConfigBuilder::from_file("tests/fixtures/config/_cobalt.yml").unwrap();
let result = result.build().unwrap();
assert_eq!(result.source,
path::Path::new("tests/fixtures/config").to_path_buf());
Expand All @@ -445,7 +445,7 @@ fn test_build_dest() {

#[test]
fn test_build_abs_dest() {
let mut result = ConfigBuilder::from_file("tests/fixtures/config/.cobalt.yml").unwrap();
let mut result = ConfigBuilder::from_file("tests/fixtures/config/_cobalt.yml").unwrap();
result.abs_dest = Some("hello/world".to_owned());
let result = result.build().unwrap();
assert_eq!(result.source,
Expand Down
10 changes: 5 additions & 5 deletions src/cobalt_model/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,22 +515,22 @@ mod tests {

#[test]
fn find_project_file_same_dir() {
let actual = find_project_file("tests/fixtures/config", ".cobalt.yml").unwrap();
let expected = path::Path::new("tests/fixtures/config/.cobalt.yml");
let actual = find_project_file("tests/fixtures/config", "_cobalt.yml").unwrap();
let expected = path::Path::new("tests/fixtures/config/_cobalt.yml");
assert_eq!(actual, expected);
}

#[test]
fn find_project_file_parent_dir() {
let actual = find_project_file("tests/fixtures/config/child", ".cobalt.yml").unwrap();
let expected = path::Path::new("tests/fixtures/config/.cobalt.yml");
let actual = find_project_file("tests/fixtures/config/child", "_cobalt.yml").unwrap();
let expected = path::Path::new("tests/fixtures/config/_cobalt.yml");
assert_eq!(actual, expected);
}

#[test]
fn find_project_file_doesnt_exist() {
let expected = path::Path::new("<NOT FOUND>");
let actual = find_project_file("tests/fixtures/", ".cobalt.yml")
let actual = find_project_file("tests/fixtures/", "_cobalt.yml")
.unwrap_or_else(|| expected.into());
assert_eq!(actual, expected);
}
Expand Down
2 changes: 1 addition & 1 deletion src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn create_new_project<P: AsRef<path::Path>>(dest: P) -> Result<()> {
pub fn create_new_project_for_path(dest: &path::Path) -> Result<()> {
fs::create_dir_all(dest)?;

create_file(&dest.join(".cobalt.yml"), COBALT_YML)?;
create_file(&dest.join("_cobalt.yml"), COBALT_YML)?;
create_file(&dest.join("index.md"), INDEX_MD)?;

fs::create_dir_all(&dest.join("_layouts"))?;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c4ee83b

Please sign in to comment.