refactor: move config list
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
e51454088e
commit
ae9073bf0b
@ -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(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
27
crates/cuddle-please-commands/src/config_command.rs
Normal file
27
crates/cuddle-please-commands/src/config_command.rs
Normal 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(())
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
mod command;
|
||||
mod config_command;
|
||||
mod release_command;
|
||||
|
||||
pub use command::Command as PleaseCommand;
|
||||
|
@ -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 {
|
||||
|
@ -1,4 +1,7 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
pub mod gatheres;
|
||||
mod stage0_config;
|
||||
@ -42,6 +45,18 @@ impl PleaseConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PleaseConfig {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(f, "PleaseConfig")?;
|
||||
writeln!(f, " owner: {}", self.get_owner())?;
|
||||
writeln!(f, " repository: {}", self.get_repository())?;
|
||||
writeln!(f, " branch: {}", self.get_branch())?;
|
||||
writeln!(f, " api_url: {}", self.get_api_url())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct PleaseConfigBuilder {
|
||||
stdin: Option<stage0_config::PleaseConfigBuilder>,
|
||||
|
@ -9,57 +9,57 @@ impl LocalGitClient {
|
||||
}
|
||||
|
||||
impl RemoteGitEngine for LocalGitClient {
|
||||
fn connect(&self, owner: &str, repo: &str) -> anyhow::Result<()> {
|
||||
fn connect(&self, _owner: &str, _repo: &str) -> anyhow::Result<()> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_tags(&self, owner: &str, repo: &str) -> anyhow::Result<Vec<crate::gitea_client::Tag>> {
|
||||
fn get_tags(&self, _owner: &str, _repo: &str) -> anyhow::Result<Vec<crate::gitea_client::Tag>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_commits_since(
|
||||
&self,
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
since_sha: Option<&str>,
|
||||
branch: &str,
|
||||
_owner: &str,
|
||||
_repo: &str,
|
||||
_since_sha: Option<&str>,
|
||||
_branch: &str,
|
||||
) -> anyhow::Result<Vec<crate::gitea_client::Commit>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_pull_request(&self, owner: &str, repo: &str) -> anyhow::Result<Option<usize>> {
|
||||
fn get_pull_request(&self, _owner: &str, _repo: &str) -> anyhow::Result<Option<usize>> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn create_pull_request(
|
||||
&self,
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
version: &str,
|
||||
body: &str,
|
||||
base: &str,
|
||||
_owner: &str,
|
||||
_repo: &str,
|
||||
_version: &str,
|
||||
_body: &str,
|
||||
_base: &str,
|
||||
) -> anyhow::Result<usize> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn update_pull_request(
|
||||
&self,
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
version: &str,
|
||||
body: &str,
|
||||
index: usize,
|
||||
_owner: &str,
|
||||
_repo: &str,
|
||||
_version: &str,
|
||||
_body: &str,
|
||||
_index: usize,
|
||||
) -> anyhow::Result<usize> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn create_release(
|
||||
&self,
|
||||
owner: &str,
|
||||
repo: &str,
|
||||
version: &str,
|
||||
body: &str,
|
||||
prerelease: bool,
|
||||
_owner: &str,
|
||||
_repo: &str,
|
||||
_version: &str,
|
||||
_body: &str,
|
||||
_prerelease: bool,
|
||||
) -> anyhow::Result<crate::gitea_client::Release> {
|
||||
todo!()
|
||||
}
|
||||
|
@ -108,8 +108,8 @@ impl From<&BufferUi> for DynUi {
|
||||
pub fn assert_output(ui: &BufferUi, expected_stdout: &str, expected_stderr: &str) {
|
||||
let (stdout, stderr) = ui.get_output();
|
||||
|
||||
assert_eq!(expected_stdout, &stdout);
|
||||
assert_eq!(expected_stderr, &stderr);
|
||||
pretty_assertions::assert_eq!(expected_stdout, &stdout);
|
||||
pretty_assertions::assert_eq!(expected_stderr, &stderr);
|
||||
}
|
||||
|
||||
pub fn get_test_data_path(item: &str) -> PathBuf {
|
||||
|
@ -16,6 +16,14 @@ fn get_base_args<'a>() -> Vec<&'a str> {
|
||||
]
|
||||
}
|
||||
|
||||
const EXPECTED_OUTPUT: &'static str = r#"cuddle-config
|
||||
PleaseConfig
|
||||
owner: kjuulh
|
||||
repository: cuddle-please
|
||||
branch: main
|
||||
api_url: https://some-example.gitea-instance
|
||||
"#;
|
||||
|
||||
#[test]
|
||||
#[traced_test]
|
||||
fn test_config_from_current_dir() {
|
||||
@ -27,7 +35,7 @@ fn test_config_from_current_dir() {
|
||||
.execute(Some(¤t_dir))
|
||||
.unwrap();
|
||||
|
||||
assert_output(ui, "cuddle-config\n", "");
|
||||
assert_output(ui, EXPECTED_OUTPUT, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -43,7 +51,7 @@ fn test_config_from_source_dir() {
|
||||
.execute(None)
|
||||
.unwrap();
|
||||
|
||||
assert_output(ui, "cuddle-config\n", "");
|
||||
assert_output(ui, EXPECTED_OUTPUT, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -57,14 +65,13 @@ project:
|
||||
repository: cuddle-please
|
||||
branch: main
|
||||
settings:
|
||||
api_url: https://some-example.gitea-instance
|
||||
"#;
|
||||
api_url: https://some-example.gitea-instance"#;
|
||||
|
||||
args.push("--config-stdin");
|
||||
PleaseCommand::new_from_args_with_stdin(Some(ui), args, || Ok(config.into()))
|
||||
.execute(None)
|
||||
.unwrap();
|
||||
assert_output(ui, "cuddle-config\n", "");
|
||||
assert_output(ui, EXPECTED_OUTPUT, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user