mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 17:57:19 +02:00
feat: Update cli interface
This commit is contained in:
parent
d8176e01df
commit
8342ce05af
8 changed files with 137 additions and 13 deletions
24
src/cli.rs
24
src/cli.rs
|
@ -8,12 +8,34 @@ pub fn generate_cli_app() -> App<'static> {
|
|||
.version(APP_VERSION)
|
||||
.author("Dheepak Krishnamurthy <@kdheepak>")
|
||||
.about("A taskwarrior terminal user interface")
|
||||
.arg(
|
||||
Arg::new("data")
|
||||
.short('d')
|
||||
.long("data")
|
||||
.value_name("FOLDER")
|
||||
.help("Sets the data folder for taskwarrior-tui")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("config")
|
||||
.short('c')
|
||||
.long("config")
|
||||
.value_name("FOLDER")
|
||||
.help("Sets the config folder for taskwarrior-tui")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("taskdata")
|
||||
.long("taskdata")
|
||||
.value_name("FOLDER")
|
||||
.help("Sets the .task folder using the TASKDATA environment variable for taskwarrior")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("taskrc")
|
||||
.long("taskrc")
|
||||
.value_name("FILE")
|
||||
.help("Sets a custom config file")
|
||||
.help("Sets the .taskrc file using the TASKRC environment variable for taskwarrior")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
|
|
79
src/main.rs
79
src/main.rs
|
@ -41,6 +41,8 @@ use crossterm::{
|
|||
use futures::stream::{FuturesUnordered, StreamExt};
|
||||
use tui::{backend::CrosstermBackend, Terminal};
|
||||
|
||||
use path_clean::PathClean;
|
||||
|
||||
use app::{Mode, TaskwarriorTui};
|
||||
|
||||
use crate::action::Action;
|
||||
|
@ -101,26 +103,91 @@ pub fn initialize_logging() {
|
|||
log4rs::init_config(config).expect("Failed to initialize logging.");
|
||||
}
|
||||
|
||||
pub fn absolute_path(path: impl AsRef<Path>) -> io::Result<PathBuf> {
|
||||
let path = path.as_ref();
|
||||
|
||||
let absolute_path = if path.is_absolute() {
|
||||
path.to_path_buf()
|
||||
} else {
|
||||
env::current_dir()?.join(path)
|
||||
}
|
||||
.clean();
|
||||
|
||||
Ok(absolute_path)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
better_panic::install();
|
||||
|
||||
initialize_logging();
|
||||
|
||||
let matches = cli::generate_cli_app().get_matches();
|
||||
|
||||
debug!("getting matches from clap...");
|
||||
let config = matches.value_of("config").unwrap_or("~/.taskrc");
|
||||
let config = matches.value_of("config");
|
||||
let data = matches.value_of("data");
|
||||
let taskrc = matches.value_of("taskrc");
|
||||
let taskdata = matches.value_of("taskdata");
|
||||
let report = matches.value_of("report").unwrap_or("next");
|
||||
|
||||
if let Some(e) = config {
|
||||
if env::var("TASKWARRIOR_TUI_CONFIG").is_err() {
|
||||
// if environment variable is not set, this env::var returns an error
|
||||
env::set_var(
|
||||
"TASKWARRIOR_TUI_CONFIG",
|
||||
absolute_path(PathBuf::from(e)).expect("Unable to get path for config"),
|
||||
)
|
||||
} else {
|
||||
warn!("TASKWARRIOR_TUI_CONFIG environment variable cannot be set.")
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(e) = data {
|
||||
if env::var("TASKWARRIOR_TUI_DATA").is_err() {
|
||||
// if environment variable is not set, this env::var returns an error
|
||||
env::set_var(
|
||||
"TASKWARRIOR_TUI_DATA",
|
||||
absolute_path(PathBuf::from(e)).expect("Unable to get path for data"),
|
||||
)
|
||||
} else {
|
||||
warn!("TASKWARRIOR_TUI_DATA environment variable cannot be set.")
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(e) = taskrc {
|
||||
if env::var("TASKRC").is_err() {
|
||||
// if environment variable is not set, this env::var returns an error
|
||||
env::set_var(
|
||||
"TASKRC",
|
||||
absolute_path(PathBuf::from(e)).expect("Unable to get path for taskrc"),
|
||||
)
|
||||
} else {
|
||||
warn!("TASKRC environment variable cannot be set.")
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(e) = taskdata {
|
||||
if env::var("TASKDATA").is_err() {
|
||||
// if environment variable is not set, this env::var returns an error
|
||||
env::set_var(
|
||||
"TASKDATA",
|
||||
absolute_path(PathBuf::from(e)).expect("Unable to get path for taskdata"),
|
||||
)
|
||||
} else {
|
||||
warn!("TASKDATA environment variable cannot be set.")
|
||||
}
|
||||
}
|
||||
|
||||
initialize_logging();
|
||||
|
||||
debug!("getting matches from clap...");
|
||||
debug!("report = {:?}", &report);
|
||||
debug!("config = {:?}", &config);
|
||||
let r = task::block_on(tui_main(config, report));
|
||||
let r = task::block_on(tui_main(report));
|
||||
if let Err(err) = r {
|
||||
eprintln!("\x1b[0;31m[taskwarrior-tui error]\x1b[0m: {}\n\nIf you need additional help, please report as a github issue on https://github.com/kdheepak/taskwarrior-tui", err);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async fn tui_main(_config: &str, report: &str) -> Result<()> {
|
||||
async fn tui_main(report: &str) -> Result<()> {
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
destruct_terminal();
|
||||
better_panic::Settings::auto().create_panic_handler()(panic_info);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue