diff --git a/src/lib.rs b/src/lib.rs index b1c5b6c..01de6e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,14 +30,14 @@ use kxio::kxprintln as p; #[derive(Parser, Debug)] #[clap(version = clap::crate_version!(), author = clap::crate_authors!(), about = clap::crate_description!())] -struct Commands { +pub struct Commands { #[clap(long, action = clap::ArgAction::SetTrue)] - log: bool, + pub log: bool, #[clap(subcommand)] - command: Command, + pub command: Command, } #[derive(Parser, Debug)] -enum Command { +pub enum Command { /// Initialize the configuration #[command(about = "Initialize configuration")] Init, @@ -95,8 +95,7 @@ impl FullCtx { } #[cfg_attr(test, mutants::skip)] -pub async fn run(ctx: &Ctx) -> color_eyre::Result<()> { - let commands = Commands::parse(); +pub async fn run(ctx: &Ctx, commands: &Commands) -> color_eyre::Result<()> { if commands.log { tracing::subscriber::set_global_default( tracing_subscriber::FmtSubscriber::builder() diff --git a/src/main.rs b/src/main.rs index 6a7ddc4..7bb1e26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,12 @@ // +use clap::Parser; use color_eyre::Result; -use trello_to_deck::{run, Ctx}; +use trello_to_deck::{run, Commands, Ctx}; #[tokio::main] #[cfg_attr(test, mutants::skip)] async fn main() -> Result<()> { color_eyre::install()?; - run(&Ctx::from(std::env::current_dir()?)).await + run(&Ctx::from(std::env::current_dir()?), &Commands::parse()).await } diff --git a/src/nextcloud/card.rs b/src/nextcloud/card.rs index 92115f0..6931cf6 100644 --- a/src/nextcloud/card.rs +++ b/src/nextcloud/card.rs @@ -9,7 +9,7 @@ use crate::{ }; #[derive(Parser, Debug)] -pub(crate) enum NextcloudCardCommand { +pub enum NextcloudCardCommand { List { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/nextcloud/deck.rs b/src/nextcloud/deck.rs index 2fc87fe..0a1e817 100644 --- a/src/nextcloud/deck.rs +++ b/src/nextcloud/deck.rs @@ -5,7 +5,7 @@ use crate::execute::Execute; use crate::{p, FullCtx}; #[derive(Parser, Debug)] -pub(crate) enum NextcloudDeckCommand { +pub enum NextcloudDeckCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/nextcloud/mod.rs b/src/nextcloud/mod.rs index d4a191e..b5016ea 100644 --- a/src/nextcloud/mod.rs +++ b/src/nextcloud/mod.rs @@ -29,7 +29,7 @@ pub(crate) struct DeckClient<'ctx> { } #[derive(Parser, Debug)] -pub(crate) enum NextcloudCommand { +pub enum NextcloudCommand { #[clap(subcommand)] Deck(NextcloudDeckCommand), #[clap(subcommand)] diff --git a/src/nextcloud/stack.rs b/src/nextcloud/stack.rs index 1446fe9..1a85f6d 100644 --- a/src/nextcloud/stack.rs +++ b/src/nextcloud/stack.rs @@ -5,7 +5,7 @@ use crate::execute::Execute; use crate::{p, FullCtx}; #[derive(Parser, Debug)] -pub(crate) enum NextcloudStackCommand { +pub enum NextcloudStackCommand { List { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/tests/init.rs b/src/tests/init.rs index ac1ff98..04c87b7 100644 --- a/src/tests/init.rs +++ b/src/tests/init.rs @@ -1,15 +1,21 @@ +// use super::*; +use crate::{Command, Commands}; use test_log::test; -#[test] -fn when_file_does_not_exist_should_create() { +#[test(tokio::test)] +async fn when_file_does_not_exist_should_create() { //given let fs = given::a_filesystem(); let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer()); + let commands = Commands { + log: false, + command: Command::Init, + }; //when - let_assert!(Ok(_) = run(&ctx)); + let_assert!(Ok(_) = crate::run(&ctx, &commands).await); //then let path = ctx.fs.base().join(f!("{NAME}.toml")); @@ -18,17 +24,21 @@ fn when_file_does_not_exist_should_create() { assert_eq!(contents, include_str!("../default-config.toml")); } -#[test] -fn when_file_exists_should_err() { +#[test(tokio::test)] +async fn when_file_exists_should_err() { //given let fs = given::a_filesystem(); let path = fs.base().join(f!("{NAME}.toml")); let file = fs.file(&path); file.write("").expect("create file"); - let ctx = given::a_context(fs.as_real(), given::a_network().into(), given::a_printer()); + let commands = Commands { + log: false, + command: Command::Init, + }; + //when - let_assert!(Err(err) = run(&ctx)); + let_assert!(Err(err) = crate::run(&ctx, &commands).await); //then assert!(err diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 7723736..81ae75d 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -6,9 +6,7 @@ use std::collections::HashMap; use assert2::let_assert; use pretty_assertions::assert_eq as assert_peq; -use crate::{ - config::AppConfig, f, init::run, nextcloud::NextcloudConfig, s, trello::TrelloConfig, Ctx, NAME, -}; +use crate::{config::AppConfig, f, nextcloud::NextcloudConfig, s, trello::TrelloConfig, Ctx, NAME}; mod api_result; mod config; diff --git a/src/trello/attachment.rs b/src/trello/attachment.rs index 893b4c7..bc09c69 100644 --- a/src/trello/attachment.rs +++ b/src/trello/attachment.rs @@ -9,7 +9,7 @@ use crate::{execute::Execute, p, FullCtx}; use super::model::{TrelloAttachmentId, TrelloCardId}; #[derive(Parser, Debug)] -pub(crate) enum TrelloAttachmentCommand { +pub enum TrelloAttachmentCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/trello/board.rs b/src/trello/board.rs index 65a8d03..22af4de 100644 --- a/src/trello/board.rs +++ b/src/trello/board.rs @@ -7,7 +7,7 @@ use crate::{p, FullCtx}; use super::model::TrelloBoardId; #[derive(Parser, Debug)] -pub(crate) enum TrelloBoardCommand { +pub enum TrelloBoardCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/trello/card.rs b/src/trello/card.rs index 51bb597..bb8fd86 100644 --- a/src/trello/card.rs +++ b/src/trello/card.rs @@ -7,7 +7,7 @@ use crate::{execute::Execute, p, FullCtx}; use super::model::TrelloCardId; #[derive(Parser, Debug)] -pub(crate) enum TrelloCardCommand { +pub enum TrelloCardCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/trello/member.rs b/src/trello/member.rs index 5b780f1..3f6bfb5 100644 --- a/src/trello/member.rs +++ b/src/trello/member.rs @@ -5,7 +5,7 @@ use crate::execute::Execute; use crate::{p, FullCtx}; #[derive(Parser, Debug)] -pub(crate) enum TrelloMemberCommand { +pub enum TrelloMemberCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, diff --git a/src/trello/mod.rs b/src/trello/mod.rs index 6db58b0..bcd5e36 100644 --- a/src/trello/mod.rs +++ b/src/trello/mod.rs @@ -29,7 +29,7 @@ pub(crate) mod stack; mod tests; #[derive(Parser, Debug)] -pub(crate) enum TrelloCommand { +pub enum TrelloCommand { #[clap(subcommand)] Member(TrelloMemberCommand), diff --git a/src/trello/stack.rs b/src/trello/stack.rs index 22e9119..650bf3b 100644 --- a/src/trello/stack.rs +++ b/src/trello/stack.rs @@ -7,7 +7,7 @@ use crate::{execute::Execute, p, FullCtx}; use super::model::TrelloListId; #[derive(Parser, Debug)] -pub(crate) enum TrelloStackCommand { +pub enum TrelloStackCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool,