refactor: move config building out of main execution loop
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
c7793f7422
commit
39db4b8d1c
@ -83,22 +83,7 @@ impl Command {
|
||||
}
|
||||
|
||||
pub fn execute(self, current_dir: Option<&Path>) -> anyhow::Result<()> {
|
||||
// 0. Get config
|
||||
let mut builder = &mut PleaseConfigBuilder::new();
|
||||
|
||||
if self.global.config_stdin {
|
||||
if let Some(stdin_fn) = self.stdin.clone() {
|
||||
let output = (stdin_fn.lock().unwrap().deref())();
|
||||
builder = builder.with_stdin(output?);
|
||||
}
|
||||
}
|
||||
// 1. Parse the current directory
|
||||
let current_dir = get_current_path(current_dir, self.config.source.clone())?;
|
||||
let config = builder
|
||||
.with_config_file(¤t_dir)
|
||||
.with_execution_env(std::env::vars())
|
||||
.with_cli(self.config.clone())
|
||||
.build()?;
|
||||
let config = self.build_config(current_dir)?;
|
||||
|
||||
match &self.commands {
|
||||
Some(Commands::Release {}) => {
|
||||
@ -317,6 +302,26 @@ impl Command {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_config(
|
||||
&self,
|
||||
current_dir: Option<&Path>,
|
||||
) -> Result<cuddle_please_frontend::PleaseConfig, anyhow::Error> {
|
||||
let mut builder = &mut PleaseConfigBuilder::new();
|
||||
if self.global.config_stdin {
|
||||
if let Some(stdin_fn) = self.stdin.clone() {
|
||||
let output = (stdin_fn.lock().unwrap().deref())();
|
||||
builder = builder.with_stdin(output?);
|
||||
}
|
||||
}
|
||||
let current_dir = get_current_path(current_dir, self.config.source.clone())?;
|
||||
let config = builder
|
||||
.with_config_file(¤t_dir)
|
||||
.with_execution_env(std::env::vars())
|
||||
.with_cli(self.config.clone())
|
||||
.build()?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn get_git(&self, current_dir: &Path) -> anyhow::Result<VcsClient> {
|
||||
VcsClient::new_git(current_dir)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user