-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for shell completions (#65)
- Loading branch information
1 parent
f34bcc6
commit 34b748c
Showing
7 changed files
with
169 additions
and
118 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
[package] | ||
name = "fab" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["Shaishav Gandhi <[email protected]>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { git = "https://github.com/clap-rs/clap/" } | ||
clap = { version = "3.0.0-beta.1", git = "https://github.com/clap-rs/clap" } | ||
clap_generate = { version = "3.0.0-beta.1", git = "https://github.com/clap-rs/clap" } | ||
reqwest = {version = "0.10.4", features = ["blocking","json"] } | ||
serde_json = "1.0.48" | ||
serde = {version = "1.0.104", features = ["derive"] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use crate::preferences::Preferences; | ||
use clap::{App, Arg}; | ||
|
||
/// Builds the App with commands and defaults. | ||
pub fn build_cli(preferences: &Preferences) -> App { | ||
let version = "0.3.0"; | ||
|
||
let default_task_priority: &Vec<&str> = &preferences | ||
.default_task_priority | ||
.iter() | ||
.map(std::ops::Deref::deref) | ||
.collect(); | ||
|
||
let default_limit = preferences.default_limit.as_str(); | ||
let default_sort = preferences.default_sort.as_ref(); | ||
|
||
App::new("Fab") | ||
.author("Shaishav <[email protected]>") | ||
.version(version) | ||
.subcommand( | ||
App::new("diffs") | ||
.version(version) | ||
.author("Shaishav <[email protected]>") | ||
.about("Commands related to your differential revisions") | ||
.arg( | ||
Arg::with_name("needs-review") | ||
.short('n') | ||
.long("needs-review") | ||
.help("Show diffs that need your review"), | ||
), | ||
) | ||
.subcommand( | ||
App::new("tasks") | ||
.about("Commands related to maniphest tasks") | ||
.version(version) | ||
.author("Shaishav <[email protected]>") | ||
.arg( | ||
Arg::with_name("priority") | ||
.short('p') | ||
.long("priority") | ||
.possible_values(&[ | ||
"unbreak-now", | ||
"needs-triage", | ||
"high", | ||
"normal", | ||
"low", | ||
"wishlist", | ||
]) | ||
.help("Specify the priority of the task") | ||
.default_values(default_task_priority) | ||
.multiple(true), | ||
) | ||
.arg( | ||
Arg::with_name("limit") | ||
.short('l') | ||
.long("limit") | ||
.help("limit results by a value") | ||
// .default_value(preferences.get_default_limit().clone().as_str()) | ||
.default_value(&default_limit), | ||
) | ||
.arg( | ||
Arg::with_name("sort") | ||
.short('s') | ||
.long("sort") | ||
.help("Sort results") | ||
.possible_values(&["priority", "updated", "newest", "title"]) | ||
.default_value(default_sort), | ||
) | ||
.arg( | ||
Arg::with_name("status") | ||
.short('S') | ||
.long("status") | ||
.help("Filter tasks by status") | ||
.possible_values(&["open", "resolved", "wontfix", "invalid", "duplicate"]) | ||
.default_value("open"), | ||
), | ||
) | ||
.subcommand( | ||
App::new("summary") | ||
.about("Gives a snapshot of what is relevant to you in the moment") | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
.subcommand( | ||
App::new("configure") | ||
.about("Configure settings") | ||
.arg( | ||
Arg::with_name("reset") | ||
.short('r') | ||
.long("reset") | ||
.help("Reset preferences to their default value"), | ||
) | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
.subcommand( | ||
App::new("autocomplete") | ||
.about("Add autocomplete suggestions for vim") | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
.subcommand( | ||
App::new("generate-bash-completions") | ||
.about("Generate the bash completion files for fab") | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
#[macro_use] | ||
extern crate serde_json; | ||
|
||
use clap; | ||
use clap::{App, Arg}; | ||
use clap_generate::generate; | ||
use clap_generate::generators::{Bash, Elvish, Fish, PowerShell, Zsh}; | ||
use failure::Error; | ||
use std::io; | ||
mod auth; | ||
mod cli; | ||
mod diffs; | ||
mod preferences; | ||
mod structs; | ||
|
@@ -16,96 +18,10 @@ const WHO_AM_I: &str = "api/user.whoami"; | |
const NO_BORDER_PRESET: &str = " "; | ||
|
||
fn main() -> Result<(), Error> { | ||
let version = "0.2.0"; | ||
let preferences = preferences::get_preferences()?; | ||
|
||
let default_task_priority: &Vec<&str> = &preferences | ||
.default_task_priority | ||
.iter() | ||
.map(std::ops::Deref::deref) | ||
.collect(); | ||
|
||
let default_sort = &preferences.default_sort; | ||
|
||
let matches = App::new("Fab") | ||
.author("Shaishav <[email protected]>") | ||
.version(version) | ||
.subcommand( | ||
App::new("diffs") | ||
.version(version) | ||
.author("Shaishav <[email protected]>") | ||
.about("Commands related to your differential revisions") | ||
.arg( | ||
Arg::with_name("needs-review") | ||
.short('n') | ||
.long("needs-review") | ||
.help("Show diffs that need your review"), | ||
), | ||
) | ||
.subcommand( | ||
App::new("tasks") | ||
.about("Commands related to maniphest tasks") | ||
.version(version) | ||
.author("Shaishav <[email protected]>") | ||
.arg( | ||
Arg::with_name("priority") | ||
.short('p') | ||
.long("priority") | ||
.possible_values(&[ | ||
"unbreak-now", | ||
"needs-triage", | ||
"high", | ||
"normal", | ||
"low", | ||
"wishlist", | ||
]) | ||
.help("Specify the priority of the task") | ||
.default_values(default_task_priority) | ||
.multiple(true), | ||
) | ||
.arg( | ||
Arg::with_name("limit") | ||
.short('l') | ||
.long("limit") | ||
.help("limit results by a value") | ||
.default_value(&format!("{}", &preferences.default_limit)), | ||
) | ||
.arg( | ||
Arg::with_name("sort") | ||
.short('s') | ||
.long("sort") | ||
.help("Sort results") | ||
.possible_values(&["priority", "updated", "newest", "title"]) | ||
.default_value(default_sort), | ||
) | ||
.arg( | ||
Arg::with_name("status") | ||
.short('S') | ||
.long("status") | ||
.help("Filter tasks by status") | ||
.possible_values(&["open", "resolved", "wontfix", "invalid", "duplicate"]) | ||
.default_value("open"), | ||
), | ||
) | ||
.subcommand( | ||
App::new("summary") | ||
.about("Gives a snapshot of what is relevant to you in the moment") | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
.subcommand( | ||
App::new("configure") | ||
.about("Configure settings") | ||
.arg( | ||
Arg::with_name("reset") | ||
.short('r') | ||
.long("reset") | ||
.help("Reset preferences to their default value"), | ||
) | ||
.version(version) | ||
.author("Shaishav <[email protected]>"), | ||
) | ||
.get_matches(); | ||
let app = cli::build_cli(&preferences); | ||
let matches = &app.get_matches(); | ||
|
||
let config = auth::init()?; | ||
|
||
|
@@ -117,6 +33,16 @@ fn main() -> Result<(), Error> { | |
summary::process_summary(matches, &config, &preferences)?; | ||
} else if let Some(matches) = matches.subcommand_matches("configure") { | ||
preferences::process_configuration(matches)?; | ||
} else if let Some(_matches) = matches.subcommand_matches("generate-bash-completions") { | ||
generate::<Bash, _>(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); | ||
} else if let Some(_matches) = matches.subcommand_matches("generate-zsh-completions") { | ||
generate::<Zsh, _>(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); | ||
} else if let Some(_matches) = matches.subcommand_matches("generate-fish-completions") { | ||
generate::<Fish, _>(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); | ||
} else if let Some(_matches) = matches.subcommand_matches("generate-elvish-completions") { | ||
generate::<Elvish, _>(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); | ||
} else if let Some(_matches) = matches.subcommand_matches("generate-powershell-completions") { | ||
generate::<PowerShell, _>(&mut cli::build_cli(&preferences), "fab", &mut io::stdout()); | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.