Various cleanup and CLI improvements

This commit is contained in:
Daniel Flanagan 2024-04-17 13:28:16 -05:00
parent 7dfcb2ad95
commit 9b65a2b3d0
6 changed files with 62 additions and 11 deletions

View file

@ -26,15 +26,22 @@ pub struct Cli {
#[derive(Subcommand)]
pub enum Commands {
/// Lists tasks with options for syncing
/// List local tasks with options for syncing
#[clap(visible_alias = "ls")]
List(list::Args),
/// Sync local tasks with GitLab and Jira
Sync(sync::Args),
/// Purge all local data
Purge(PurgeArgs),
/// Performs various cleanup operations on local data
Cleanup(CleanupArgs),
/// Run the interactive terminal user interface (TUI)
#[command(subcommand)]
Ui(ui::Command),
#[clap(visible_alias = "tui")]
Ui(ui::Args),
/// Interact with the configured Jira endpoint
#[command(subcommand)]
@ -45,11 +52,39 @@ pub enum Commands {
Gitlab(gitlab::Command),
}
mod ui {
use clap::Subcommand;
#[derive(Args)]
pub struct PurgeArgs {}
impl PurgeArgs {
pub async fn run(&self) -> Result<()> {
let tasks = crate::tasks::Tasks::try_new()?;
tasks.purge_all()?;
println!("Local data purged!");
Ok(())
}
}
#[derive(Subcommand)]
pub enum Command {}
#[derive(Args)]
pub struct CleanupArgs {}
impl CleanupArgs {
pub async fn run(&self) -> Result<()> {
let tasks = crate::tasks::Tasks::try_new()?;
tasks.cleanup_all()?;
println!("Local data cleaned up!");
Ok(())
}
}
mod ui {
use crate::cli::prelude::*;
#[derive(Parser)]
pub struct Args {}
impl Args {
pub async fn run(&self) -> Result<()> {
crate::tui::run().await
}
}
}
mod list {

View file

View file

@ -19,7 +19,8 @@ use cli::{Cli, Commands};
async fn main() -> Result<()> {
let cli = Cli::new();
// this guard causes logs to be flushed when dropped
// this guard causes logs to be flushed when dropped (which is at the end of
// this function which would be the end of our program)
// https://docs.rs/tracing-appender/latest/tracing_appender/non_blocking/struct.WorkerGuard.html
let _log_guard = observe::setup_logging(cli.logs_directory, cli.tracing_env_filter)?;
@ -27,8 +28,10 @@ async fn main() -> Result<()> {
trace!("Starting...");
info!("Starting...");
let result = match cli.command {
Commands::Ui(args) => args.run().await,
Commands::Purge(args) => args.run().await,
Commands::Cleanup(args) => args.run().await,
Commands::Sync(args) => args.sync().await,
Commands::Ui(_args) => tui::run().await,
Commands::List(args) => args.list().await,
Commands::Jira(jira) => jira.exec().await,
Commands::Gitlab(gitlab) => gitlab.exec().await,

View file

@ -68,8 +68,18 @@ impl Display for Task {
status,
tags,
} = self;
let tags_text = tags
.iter()
.map(String::as_str)
.collect::<Vec<&str>>()
.join(", ");
let mr_text = if merge_requests.len() > 0 {
format!(" {} MRs", merge_requests.len())
} else {
"".into()
};
f.write_fmt(format_args!(
"{jira_key} {status:>10} {jira_priority} {description}",
"{jira_key} {status:>10} {jira_priority} {description} [{tags_text}]{mr_text}",
))
}
}

View file

@ -68,6 +68,7 @@ impl Tasks {
Ok(result)
}
#[allow(dead_code)]
pub fn get(&self, key: &str) -> Result<Option<Task>> {
let ivec = self.db.open_tree("tasks")?.get(key)?;
match ivec {
@ -206,7 +207,7 @@ impl Tasks {
self.db
.open_tree("task:meta")?
.insert(b"last_sync_date", serde_json::to_vec(&now)?);
.insert(b"last_sync_date", serde_json::to_vec(&now)?)?;
Ok(())
}

View file

@ -13,6 +13,8 @@ use ratatui::{
};
use std::io::stdout;
pub struct State {}
pub async fn run() -> Result<()> {
let t = Tasks::try_new()?;