mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-20 07:01:12 +00:00
add completion subcommands (#99)
* add completion subcommands * improve error mgmt, add entry to readme Co-authored-by: Clément DOUIN <soywod@users.noreply.github.com>
This commit is contained in:
parent
8a617c314e
commit
9287846aed
27
README.md
27
README.md
|
@ -25,6 +25,7 @@ Minimalist CLI email client, written in Rust.
|
||||||
* [Move a message](#move-a-message)
|
* [Move a message](#move-a-message)
|
||||||
* [Delete a message](#delete-a-message)
|
* [Delete a message](#delete-a-message)
|
||||||
* [Listen to new messages](#listen-to-new-messages)
|
* [Listen to new messages](#listen-to-new-messages)
|
||||||
|
* [Completions](#completions)
|
||||||
* [Interfaces](#interfaces)
|
* [Interfaces](#interfaces)
|
||||||
* [GUI](#gui)
|
* [GUI](#gui)
|
||||||
* [TUI](#tui)
|
* [TUI](#tui)
|
||||||
|
@ -237,6 +238,32 @@ systemctl --user enable himalaya.service
|
||||||
systemctl --user start himalaya.service
|
systemctl --user start himalaya.service
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Completions
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# For bash shells
|
||||||
|
himalaya bash-completions
|
||||||
|
|
||||||
|
# For zsh shells
|
||||||
|
himalaya zsh-completions
|
||||||
|
|
||||||
|
# For fish shells
|
||||||
|
himalaya fish-completions
|
||||||
|
```
|
||||||
|
|
||||||
|
Those commands print the generated scripts to the stdout. You will have
|
||||||
|
to manually save and source them. For example:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
himalaya bash-completions > himalaya-completions.bash
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# ~/.bashrc
|
||||||
|
|
||||||
|
source himalaya-completions.bash
|
||||||
|
```
|
||||||
|
|
||||||
## Interfaces
|
## Interfaces
|
||||||
|
|
||||||
### GUI
|
### GUI
|
||||||
|
|
34
src/completion/cli.rs
Normal file
34
src/completion/cli.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use clap::{self, App, ArgMatches, SubCommand};
|
||||||
|
use error_chain::error_chain;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
error_chain! {}
|
||||||
|
|
||||||
|
pub fn completion_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
|
vec![
|
||||||
|
SubCommand::with_name("bash-completions").about("Generates bash completions script"),
|
||||||
|
SubCommand::with_name("zsh-completions").about("Generates zsh completions script"),
|
||||||
|
SubCommand::with_name("fish-completions").about("Generates fish completions script"),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn completion_matches(mut app: App, matches: &ArgMatches) -> Result<bool> {
|
||||||
|
use clap::Shell::*;
|
||||||
|
|
||||||
|
if matches.is_present("bash-completions") {
|
||||||
|
app.gen_completions_to("himalaya", Bash, &mut io::stdout());
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches.is_present("zsh-completions") {
|
||||||
|
app.gen_completions_to("himalaya", Zsh, &mut io::stdout());
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches.is_present("fish-completions") {
|
||||||
|
app.gen_completions_to("himalaya", Fish, &mut io::stdout());
|
||||||
|
return Ok(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(false)
|
||||||
|
}
|
21
src/main.rs
21
src/main.rs
|
@ -27,13 +27,17 @@ mod mbox {
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
pub(crate) mod model;
|
pub(crate) mod model;
|
||||||
}
|
}
|
||||||
|
mod completion {
|
||||||
|
pub(crate) mod cli;
|
||||||
|
}
|
||||||
|
|
||||||
use clap;
|
use clap::{self, App};
|
||||||
use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
use log::{debug, error};
|
use log::{debug, error};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
completion::cli::{completion_matches, completion_subcmds},
|
||||||
config::cli::account_arg,
|
config::cli::account_arg,
|
||||||
flag::cli::{flag_matches, flag_subcmds},
|
flag::cli::{flag_matches, flag_subcmds},
|
||||||
imap::cli::{imap_matches, imap_subcmds},
|
imap::cli::{imap_matches, imap_subcmds},
|
||||||
|
@ -52,12 +56,13 @@ error_chain! {
|
||||||
ImapCli(crate::imap::cli::Error, crate::imap::cli::ErrorKind);
|
ImapCli(crate::imap::cli::Error, crate::imap::cli::ErrorKind);
|
||||||
MboxCli(crate::mbox::cli::Error, crate::mbox::cli::ErrorKind);
|
MboxCli(crate::mbox::cli::Error, crate::mbox::cli::ErrorKind);
|
||||||
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
||||||
|
CompletionCli(crate::completion::cli::Error, crate::completion::cli::ErrorKind);
|
||||||
OutputLog(crate::output::log::Error, crate::output::log::ErrorKind);
|
OutputLog(crate::output::log::Error, crate::output::log::ErrorKind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run() -> Result<()> {
|
fn build_cli() -> App<'static, 'static> {
|
||||||
let matches = clap::App::new(env!("CARGO_PKG_NAME"))
|
clap::App::new(env!("CARGO_PKG_NAME"))
|
||||||
.version(env!("CARGO_PKG_VERSION"))
|
.version(env!("CARGO_PKG_VERSION"))
|
||||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||||
.author(env!("CARGO_PKG_AUTHORS"))
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||||||
|
@ -68,7 +73,11 @@ fn run() -> Result<()> {
|
||||||
.subcommands(imap_subcmds())
|
.subcommands(imap_subcmds())
|
||||||
.subcommands(mbox_subcmds())
|
.subcommands(mbox_subcmds())
|
||||||
.subcommands(msg_subcmds())
|
.subcommands(msg_subcmds())
|
||||||
.get_matches();
|
.subcommands(completion_subcmds())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run() -> Result<()> {
|
||||||
|
let matches = build_cli().get_matches();
|
||||||
|
|
||||||
let output_fmt: OutputFmt = matches.value_of("output").unwrap().into();
|
let output_fmt: OutputFmt = matches.value_of("output").unwrap().into();
|
||||||
let log_level: LogLevel = matches.value_of("log").unwrap().into();
|
let log_level: LogLevel = matches.value_of("log").unwrap().into();
|
||||||
|
@ -91,6 +100,10 @@ fn run() -> Result<()> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if completion_matches(build_cli(), &matches)? {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
msg_matches(&matches)?;
|
msg_matches(&matches)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue