-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Comamnd func handle workspace instead of config directly
- Loading branch information
Showing
9 changed files
with
109 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
use crate::config::Config; | ||
use crate::{app, versioning::up_major}; | ||
use crate::versioning::up_major; | ||
use crate::workspace::{make_context, Workspace}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
|
||
#[derive(Args)] | ||
pub(crate) struct Arguments {} | ||
|
||
pub(crate) fn execute(_args: &Arguments, config: &Config) -> Result<()> { | ||
let new_version = up_major(&config.current_version); | ||
|
||
app::update(&config, &new_version) | ||
pub(crate) fn execute(_args: &Arguments, workspace: &Workspace) -> Result<()> { | ||
let current_version = &workspace.config.current_version; | ||
let new_version = up_major(¤t_version); | ||
let context = make_context(¤t_version, &new_version); | ||
workspace.update_files(&context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
use crate::config::Config; | ||
use crate::{app, versioning::up_minor}; | ||
use crate::versioning::up_minor; | ||
use crate::workspace::{make_context, Workspace}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
|
||
#[derive(Args)] | ||
pub(crate) struct Arguments {} | ||
|
||
pub(crate) fn execute(_args: &Arguments, config: &Config) -> Result<()> { | ||
let new_version = up_minor(&config.current_version); | ||
|
||
app::update(&config, &new_version) | ||
pub(crate) fn execute(_args: &Arguments, workspace: &Workspace) -> Result<()> { | ||
let current_version = &workspace.config.current_version; | ||
let new_version = up_minor(¤t_version); | ||
let context = make_context(¤t_version, &new_version); | ||
workspace.update_files(&context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
use crate::config::Config; | ||
use crate::{app, versioning::up_patch}; | ||
use crate::versioning::up_patch; | ||
use crate::workspace::{make_context, Workspace}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
|
||
#[derive(Args)] | ||
pub(crate) struct Arguments {} | ||
|
||
pub(crate) fn execute(_args: &Arguments, config: &Config) -> Result<()> { | ||
let new_version = up_patch(&config.current_version); | ||
|
||
app::update(&config, &new_version) | ||
pub(crate) fn execute(_args: &Arguments, workspace: &Workspace) -> Result<()> { | ||
let current_version = &workspace.config.current_version; | ||
let new_version = up_patch(¤t_version); | ||
let context = make_context(¤t_version, &new_version); | ||
workspace.update_files(&context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use anyhow::Result; | ||
use chrono::Local; | ||
use semver::Version; | ||
use std::path::PathBuf; | ||
use tera::Context; | ||
|
||
use crate::config::{resolve_config, Config, DEFAULT_FILENAME}; | ||
use crate::writer::Writer; | ||
|
||
/** | ||
* CLI workspace. | ||
* | ||
* .. note:: Under construction | ||
*/ | ||
#[derive(Debug)] | ||
pub struct Workspace { | ||
pub config: Config, | ||
} | ||
|
||
impl Workspace { | ||
pub fn try_new(root: PathBuf) -> Result<Self> { | ||
let resolved = resolve_config(&root); | ||
if resolved.is_err() { | ||
return Err(resolved.unwrap_err()); | ||
} | ||
Ok(Self { | ||
config: resolved.unwrap(), | ||
}) | ||
} | ||
|
||
#[allow(dead_code)] | ||
fn init_writer(&self, ctx: &Context) -> Writer { | ||
let mut writer = Writer::new(ctx); | ||
writer.add_target( | ||
&PathBuf::from(DEFAULT_FILENAME), | ||
&("current_version = \"{{current_version}}\"".to_string()), | ||
&("current_version = \"{{new_version}}\"".to_string()), | ||
); | ||
for f in &self.config.files { | ||
writer.add_target(&f.path, &f.search, &f.replace); | ||
} | ||
writer | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn update_files(&self, ctx: &Context) -> Result<()> { | ||
let writer = self.init_writer(ctx); | ||
match writer.update_all() { | ||
Ok(_) => { | ||
println!("Updated!"); | ||
Ok(()) | ||
} | ||
Err(err) => Err(err), | ||
} | ||
} | ||
} | ||
|
||
pub fn make_context(current_version: &Version, new_version: &Version) -> Context { | ||
let mut ctx = Context::new(); | ||
ctx.insert("current_version", current_version); | ||
ctx.insert("new_version", new_version); | ||
ctx.insert("now", &Local::now().to_rfc3339()); | ||
return ctx; | ||
} |