diff --git a/Cargo.lock b/Cargo.lock index dda324f..465f396 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,15 +26,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" version = "1.0.40" @@ -326,21 +317,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "clap" -version = "2.33.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim 0.8.0", - "textwrap 0.11.0", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "3.0.0-beta.2" @@ -355,7 +331,7 @@ dependencies = [ "os_str_bytes", "strsim 0.10.0", "termcolor", - "textwrap 0.12.1", + "textwrap", "unicode-width", "vec_map", ] @@ -379,7 +355,7 @@ version = "3.0.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adf420f8b687b628d2915ccfd43a660c437a170432e3fbcb66944e8717a0d68f" dependencies = [ - "clap 3.0.0-beta.2", + "clap", ] [[package]] @@ -1425,12 +1401,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.9.3" @@ -1490,8 +1460,7 @@ dependencies = [ "better-panic", "cassowary", "chrono", - "clap 2.33.3", - "clap 3.0.0-beta.2", + "clap", "clap_generate", "crossterm", "dirs", @@ -1533,15 +1502,6 @@ dependencies = [ "libc", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "textwrap" version = "0.12.1" diff --git a/Cargo.toml b/Cargo.toml index 1e323ba..10b3474 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ async-std = { version = "1", features = ["attributes", "unstable"] } better-panic = "0.2.0" cassowary = "0.3.0" chrono = "0.4" -clap = "2.33" +clap = "3.0.0-beta.2" crossterm = { version = "0.17", optional = true, default-features = false, features = ["event-stream"] } dirs = "2.0.2" futures = "0.3" diff --git a/build.rs b/build.rs index 2459a91..7a6c555 100644 --- a/build.rs +++ b/build.rs @@ -1,33 +1,10 @@ #![allow(dead_code)] -use clap::{App, Arg}; use clap_generate::{generate_to, generators::*}; -const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); -const APP_NAME: &str = env!("CARGO_PKG_NAME"); +include!("src/cli.rs"); fn main() { - let mut app = App::new(APP_NAME) - .version(APP_VERSION) - .author("Dheepak Krishnamurthy <@kdheepak>") - .about("A taskwarrior terminal user interface") - .arg( - Arg::new("config") - .short('c') - .long("config") - .value_name("FILE") - .about("Sets a custom config file") - .takes_value(true), - ) - .arg( - Arg::new("report") - .short('r') - .long("report") - .value_name("STRING") - .about("Sets default report") - .takes_value(true), - ); - - app.set_bin_name(APP_NAME); + let mut app = generate_cli_app(); let name = app.get_name().to_string(); let outdir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("completions/"); dbg!(&outdir); diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..8a0eef7 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,30 @@ +use clap::{App, Arg}; + +const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); +const APP_NAME: &str = env!("CARGO_PKG_NAME"); + +pub fn generate_cli_app() -> App<'static> { + let mut app = App::new(APP_NAME) + .version(APP_VERSION) + .author("Dheepak Krishnamurthy <@kdheepak>") + .about("A taskwarrior terminal user interface") + .arg( + Arg::new("config") + .short('c') + .long("config") + .value_name("FILE") + .about("Sets a custom config file") + .takes_value(true), + ) + .arg( + Arg::new("report") + .short('r') + .long("report") + .value_name("STRING") + .about("Sets default report") + .takes_value(true), + ); + + app.set_bin_name(APP_NAME); + app +} diff --git a/src/main.rs b/src/main.rs index e1c7057..ab6095a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ mod app; mod calendar; +mod cli; mod completion; mod config; mod context; @@ -16,7 +17,6 @@ mod task_report; use crate::event::{Event, EventConfig, Events, Key}; use anyhow::Result; -use clap::{App, Arg}; use std::env; use std::error::Error; use std::io::{self, Write}; @@ -38,9 +38,6 @@ use tui::{backend::CrosstermBackend, Terminal}; use app::{AppMode, TaskwarriorTuiApp}; -const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); -const APP_NAME: &str = env!("CARGO_PKG_NAME"); - pub fn setup_terminal() -> Terminal> { enable_raw_mode().unwrap(); let mut stdout = io::stdout(); @@ -58,27 +55,7 @@ pub fn destruct_terminal() { fn main() { better_panic::install(); - let matches = App::new(APP_NAME) - .version(APP_VERSION) - .author("Dheepak Krishnamurthy <@kdheepak>") - .about("A taskwarrior terminal user interface") - .arg( - Arg::with_name("config") - .short("c") - .long("config") - .value_name("FILE") - .help("Sets a custom config file") - .takes_value(true), - ) - .arg( - Arg::with_name("report") - .short("r") - .long("report") - .value_name("STRING") - .help("Sets default report") - .takes_value(true), - ) - .get_matches(); + let matches = cli::generate_cli_app().get_matches(); let config = matches.value_of("config").unwrap_or("~/.taskrc"); let report = matches.value_of("report").unwrap_or("next");