Skip to content

Commit

Permalink
fix init and create
Browse files Browse the repository at this point in the history
  • Loading branch information
Brett committed Mar 17, 2019
1 parent 972a1b0 commit 4536602
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 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 = "hemtt"
version = "0.5.0"
version = "0.5.1"
authors = ["Brett <[email protected]>"]
edition = "2018"

Expand Down
8 changes: 5 additions & 3 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn default_include() -> Vec<PathBuf> {

impl Project {
pub fn save(&self) -> Result<(), Error> {
let file = path().unwrap_or_print();
let file = path(false).unwrap_or_print();
let mut out = File::create(file)?;
if toml_exists() {
out.write_fmt(format_args!("{}", toml::to_string(&self).unwrap()))?;
Expand Down Expand Up @@ -169,11 +169,13 @@ pub fn exists() -> bool {
toml_exists() || json_exists()
}

pub fn path() -> Result<&'static Path, Error> {
pub fn path(fail: bool) -> Result<&'static Path, Error> {
if exists() {
return Ok(Path::new(
if toml_exists() {"hemtt.toml"} else {"hemtt.json"}
));
} else if !fail {
return Ok(Path::new("hemtt.json"));
}
Err(error!("No HEMTT project file was found"))
}
Expand All @@ -187,7 +189,7 @@ pub fn toml_exists() -> bool {
}

pub fn get_project() -> Result<Project, Error> {
let file = path()?;
let file = path(true)?;
let mut f = File::open(file)?;
let mut contents = String::new();
f.read_to_string(&mut contents)?;
Expand Down

0 comments on commit 4536602

Please sign in to comment.