mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
improve arg comments, rename arg Match to Command
This commit is contained in:
+12
-10
@@ -1,24 +1,26 @@
|
||||
//! Module related to completion arguments.
|
||||
//! Module related to completion CLI.
|
||||
//!
|
||||
//! This module provides subcommands and an argument matcher related to completion.
|
||||
//! This module provides subcommands and a command matcher related to completion.
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{self, App, Arg, ArgMatches, Shell, SubCommand};
|
||||
use log::debug;
|
||||
|
||||
/// Enumeration of all possible matches.
|
||||
pub enum Match<'a> {
|
||||
type OptionShell<'a> = Option<&'a str>;
|
||||
|
||||
/// Completion commands.
|
||||
pub enum Command<'a> {
|
||||
/// Generate completion script for the given shell slice.
|
||||
Generate(&'a str),
|
||||
Generate(OptionShell<'a>),
|
||||
}
|
||||
|
||||
/// Completion arg matcher.
|
||||
pub fn matches<'a>(m: &'a ArgMatches) -> Result<Option<Match<'a>>> {
|
||||
/// Completion command matcher.
|
||||
pub fn matches<'a>(m: &'a ArgMatches) -> Result<Option<Command<'a>>> {
|
||||
if let Some(m) = m.subcommand_matches("completion") {
|
||||
debug!("completion command matched");
|
||||
let shell = m.value_of("shell").unwrap();
|
||||
debug!("shell: {}", shell);
|
||||
return Ok(Some(Match::Generate(shell)));
|
||||
let shell = m.value_of("shell");
|
||||
debug!("shell: `{:?}`", shell);
|
||||
return Ok(Some(Command::Generate(shell)));
|
||||
};
|
||||
|
||||
Ok(None)
|
||||
|
||||
@@ -7,8 +7,8 @@ use clap::{App, Shell};
|
||||
use std::{io, str::FromStr};
|
||||
|
||||
/// Generate completion script from the given [`clap::App`] for the given shell slice.
|
||||
pub fn generate<'a>(shell: &'a str, mut app: App<'a, 'a>) -> Result<()> {
|
||||
let shell = Shell::from_str(shell)
|
||||
pub fn generate<'a>(shell: Option<&'a str>, mut app: App<'a, 'a>) -> Result<()> {
|
||||
let shell = Shell::from_str(shell.unwrap_or_default())
|
||||
.map_err(|err| anyhow!(err))
|
||||
.context("cannot parse shell")?;
|
||||
app.gen_completions_to("himalaya", shell, &mut io::stdout());
|
||||
|
||||
Reference in New Issue
Block a user