refactor: pass parsed Commands from main
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m30s
Test / build (map[name:stable]) (push) Successful in 2m2s
Release Please / Release-plz (push) Failing after 18s

This commit is contained in:
Paul Campbell 2024-12-15 20:07:34 +00:00
parent 6fe7be191f
commit 9e414d8947
14 changed files with 36 additions and 28 deletions

View file

@ -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()

View file

@ -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
}

View file

@ -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,

View file

@ -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,

View file

@ -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)]

View file

@ -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,

View file

@ -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

View file

@ -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;

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -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,

View file

@ -29,7 +29,7 @@ pub(crate) mod stack;
mod tests;
#[derive(Parser, Debug)]
pub(crate) enum TrelloCommand {
pub enum TrelloCommand {
#[clap(subcommand)]
Member(TrelloMemberCommand),

View file

@ -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,