Skip to content

Commit

Permalink
feat: Add loggings
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Apr 6, 2024
1 parent a31e14e commit 2755025
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Configuration manager.

use anyhow::{anyhow, Result};
use log::info;
use semver::Version;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
Expand Down Expand Up @@ -68,6 +69,7 @@ pub fn resolve_config(root: &PathBuf) -> Result<(ConfigDocument, Config)> {
Ok((ConfigDocument::AgeToml(doc), config.unwrap()))
};
if _age_toml.is_ok() {
info!("Found valid .age.toml");
return _age_toml;
}
let _cargo_toml = '_cargo_toml: {
Expand All @@ -83,6 +85,7 @@ pub fn resolve_config(root: &PathBuf) -> Result<(ConfigDocument, Config)> {
Ok((ConfigDocument::CargoToml(doc), config.unwrap()))
};
if _cargo_toml.is_ok() {
info!("Found valid Cargo.toml");
return _cargo_toml;
}
let _pyproject_toml = '_pyproject_toml: {
Expand All @@ -98,7 +101,12 @@ pub fn resolve_config(root: &PathBuf) -> Result<(ConfigDocument, Config)> {
Ok((ConfigDocument::PyprojectToml(doc), config.unwrap()))
};
if _pyproject_toml.is_ok() {
info!("Found valid pyproject.toml");
return _pyproject_toml;
}
info!(
"There is not valid configuration in {}",
root.display().to_string()
);
Err(anyhow!("Valid configuration file is not exists."))
}
10 changes: 10 additions & 0 deletions src/workspace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, Result};
use chrono::{DateTime, Local};
use log::debug;
use semver::Version;
use std::path::PathBuf;

Expand All @@ -20,6 +21,7 @@ pub struct Workspace {

impl Workspace {
pub fn try_new(root: PathBuf) -> Result<Self> {
debug!("Trying init workspace on : {}", root.display().to_string());
let resolved = resolve_config(&root);
if resolved.is_err() {
return Err(resolved.unwrap_err());
Expand Down Expand Up @@ -59,16 +61,19 @@ impl Workspace {
}

pub fn update_files(&mut self, ctx: &Context) -> Result<()> {
debug!("Updating configuration file.");
match self.doc.update_version(&ctx.new_version) {
Ok(_) => {}
Err(err) => {
return Err(err);
}
}

debug!("Updating target files.");
let writer = self.init_writer(ctx);
match writer.update_all() {
Ok(_) => {
debug!("All updatings are completed.");
println!("Updated!");
Ok(())
}
Expand Down Expand Up @@ -104,5 +109,10 @@ impl Context {

// TODO:: This is only to keep implementation of commands
pub fn make_context(current_version: &Version, new_version: &Version) -> Context {
debug!(
"Current version of workspace is {}",
current_version.to_string()
);
debug!("New version of workspace is {}", new_version.to_string());
Context::new(current_version, new_version)
}

0 comments on commit 2755025

Please sign in to comment.