refactor: move config list

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2023-08-01 17:01:00 +02:00
parent e51454088e
commit ae9073bf0b
8 changed files with 93 additions and 58 deletions

View File

@@ -1,23 +1,18 @@
use std::{
env::current_dir,
io::Read,
ops::Deref,
path::{Path, PathBuf},
rc::Rc,
sync::{Arc, Mutex},
};
use ::semver::Version;
use anyhow::Context;
use clap::{Parser, Subcommand};
use cuddle_please_frontend::{gatheres::ConfigArgs, PleaseConfig, PleaseConfigBuilder};
use cuddle_please_misc::{
changelog_parser, get_most_significant_version, ChangeLogBuilder, ConsoleUi,
DynRemoteGitClient, DynUi, GiteaClient, GlobalArgs, LocalGitClient, NextVersion,
RemoteGitEngine, StdinFn, VcsClient,
get_most_significant_version, ConsoleUi, DynRemoteGitClient, DynUi, GiteaClient, GlobalArgs,
LocalGitClient, NextVersion, RemoteGitEngine, StdinFn, VcsClient,
};
use crate::release_command::ReleaseCommand;
use crate::{config_command::ConfigCommandHandler, release_command::ReleaseCommand};
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
@@ -94,17 +89,15 @@ impl Command {
match &self.commands {
Some(Commands::Release {}) => {
tracing::debug!("running command: release");
ReleaseCommand::new(config, git_client, gitea_client)
.execute(self.global.dry_run)?;
}
Some(Commands::Config { command }) => match command {
ConfigCommand::List { .. } => {
tracing::debug!("running command: config list");
self.ui.write_str_ln("cuddle-config");
}
},
Some(Commands::Config { command }) => {
ConfigCommandHandler::new(self.ui, config).execute(command)?;
}
Some(Commands::Gitea { command }) => {
let git_url = url::Url::parse(config.get_api_url())?;
@@ -116,7 +109,7 @@ impl Command {
url.push_str(format!(":{port}").as_str());
}
let client = GiteaClient::new(&url, self.global.token.as_ref().map(|t| t.as_str()));
let client = GiteaClient::new(&url, self.global.token.as_deref());
match command {
GiteaCommand::Connect {} => {
client.connect(config.get_owner(), config.get_repository())?;
@@ -227,7 +220,7 @@ impl Command {
cuddle_please_misc::RemoteEngine::Local => Box::new(LocalGitClient::new()),
cuddle_please_misc::RemoteEngine::Gitea => Box::new(GiteaClient::new(
&self.config.api_url.clone().expect("api_url to be set"),
self.global.token.as_ref().map(|t| t.as_str()),
self.global.token.as_deref(),
)),
}
}

View File

@@ -0,0 +1,27 @@
use cuddle_please_frontend::PleaseConfig;
use cuddle_please_misc::DynUi;
use crate::command::ConfigCommand;
pub struct ConfigCommandHandler {
ui: DynUi,
config: PleaseConfig,
}
impl ConfigCommandHandler {
pub fn new(ui: DynUi, config: PleaseConfig) -> Self {
Self { ui, config }
}
pub fn execute(&self, command: &ConfigCommand) -> anyhow::Result<()> {
match command {
ConfigCommand::List {} => {
tracing::debug!("running command: config list");
self.ui.write_str_ln("cuddle-config");
self.ui.write_str(&format!("{}", self.config));
}
}
Ok(())
}
}

View File

@@ -1,4 +1,5 @@
mod command;
mod config_command;
mod release_command;
pub use command::Command as PleaseCommand;

View File

@@ -1,19 +1,11 @@
use cuddle_please_frontend::PleaseConfig;
use std::{
io::Read,
ops::Deref,
path::{Path, PathBuf},
sync::{Arc, Mutex},
};
use ::semver::Version;
use anyhow::Context;
use clap::{Parser, Subcommand};
use cuddle_please_frontend::{gatheres::ConfigArgs, PleaseConfigBuilder};
use cuddle_please_misc::{
changelog_parser, get_most_significant_version, ChangeLogBuilder, ConsoleUi,
DynRemoteGitClient, DynUi, GiteaClient, GlobalArgs, NextVersion, StdinFn, VcsClient,
changelog_parser, get_most_significant_version, ChangeLogBuilder, DynRemoteGitClient,
NextVersion, VcsClient,
};
pub struct ReleaseCommand {