mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
fix args typos
This commit is contained in:
parent
329af51534
commit
abb9f4172b
|
@ -23,7 +23,7 @@ const ARG_RAW: &str = "raw";
|
||||||
const ARG_REPLY_ALL: &str = "reply-all";
|
const ARG_REPLY_ALL: &str = "reply-all";
|
||||||
const CMD_ATTACHMENTS: &str = "attachments";
|
const CMD_ATTACHMENTS: &str = "attachments";
|
||||||
const CMD_COPY: &str = "copy";
|
const CMD_COPY: &str = "copy";
|
||||||
const CMD_DELETE: &str = "delete";
|
const CMD_DEL: &str = "delete";
|
||||||
const CMD_FORWARD: &str = "forward";
|
const CMD_FORWARD: &str = "forward";
|
||||||
const CMD_LIST: &str = "list";
|
const CMD_LIST: &str = "list";
|
||||||
const CMD_MOVE: &str = "move";
|
const CMD_MOVE: &str = "move";
|
||||||
|
@ -56,7 +56,7 @@ pub(crate) type Ids<'a> = &'a str;
|
||||||
pub enum Cmd<'a> {
|
pub enum Cmd<'a> {
|
||||||
Attachments(Id<'a>),
|
Attachments(Id<'a>),
|
||||||
Copy(Id<'a>, Folder<'a>),
|
Copy(Id<'a>, Folder<'a>),
|
||||||
Delete(Id<'a>),
|
Delete(Ids<'a>),
|
||||||
Forward(Id<'a>, Attachments<'a>, Encrypt),
|
Forward(Id<'a>, Attachments<'a>, Encrypt),
|
||||||
List(table::args::MaxTableWidth, Option<PageSize>, Page),
|
List(table::args::MaxTableWidth, Option<PageSize>, Page),
|
||||||
Move(Id<'a>, Folder<'a>),
|
Move(Id<'a>, Folder<'a>),
|
||||||
|
@ -91,10 +91,10 @@ pub fn matches<'a>(m: &'a ArgMatches) -> Result<Option<Cmd<'a>>> {
|
||||||
let id = parse_id_arg(m);
|
let id = parse_id_arg(m);
|
||||||
let folder = folder::args::parse_target_arg(m);
|
let folder = folder::args::parse_target_arg(m);
|
||||||
Cmd::Copy(id, folder)
|
Cmd::Copy(id, folder)
|
||||||
} else if let Some(m) = m.subcommand_matches(CMD_DELETE) {
|
} else if let Some(m) = m.subcommand_matches(CMD_DEL) {
|
||||||
debug!("delete command matched");
|
debug!("delete command matched");
|
||||||
let id = parse_id_arg(m);
|
let ids = parse_ids_arg(m);
|
||||||
Cmd::Delete(id)
|
Cmd::Delete(ids)
|
||||||
} else if let Some(m) = m.subcommand_matches(CMD_FORWARD) {
|
} else if let Some(m) = m.subcommand_matches(CMD_FORWARD) {
|
||||||
debug!("forward command matched");
|
debug!("forward command matched");
|
||||||
let id = parse_id_arg(m);
|
let id = parse_id_arg(m);
|
||||||
|
@ -185,13 +185,13 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
.arg(table::args::max_width()),
|
.arg(table::args::max_width()),
|
||||||
SubCommand::with_name(CMD_SEARCH)
|
SubCommand::with_name(CMD_SEARCH)
|
||||||
.aliases(&["s", "query", "q"])
|
.aliases(&["s", "query", "q"])
|
||||||
.about("Lists emails matching the given IMAP query")
|
.about("Lists emails matching the given query")
|
||||||
.arg(page_size_arg())
|
.arg(page_size_arg())
|
||||||
.arg(page_arg())
|
.arg(page_arg())
|
||||||
.arg(table::args::max_width())
|
.arg(table::args::max_width())
|
||||||
.arg(query_arg()),
|
.arg(query_arg()),
|
||||||
SubCommand::with_name(CMD_SORT)
|
SubCommand::with_name(CMD_SORT)
|
||||||
.about("Sorts emails by the given criteria and matching the given IMAP query")
|
.about("Sorts emails by the given criteria and matching the given query")
|
||||||
.arg(page_size_arg())
|
.arg(page_size_arg())
|
||||||
.arg(page_arg())
|
.arg(page_arg())
|
||||||
.arg(table::args::max_width())
|
.arg(table::args::max_width())
|
||||||
|
@ -199,6 +199,7 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
.arg(query_arg()),
|
.arg(query_arg()),
|
||||||
SubCommand::with_name(CMD_WRITE)
|
SubCommand::with_name(CMD_WRITE)
|
||||||
.about("Writes a new email")
|
.about("Writes a new email")
|
||||||
|
.aliases(&["w", "new", "n"])
|
||||||
.args(&tpl::args::args())
|
.args(&tpl::args::args())
|
||||||
.arg(attachments_arg())
|
.arg(attachments_arg())
|
||||||
.arg(encrypt_flag()),
|
.arg(encrypt_flag()),
|
||||||
|
@ -237,10 +238,10 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
.about("Moves an email to the targeted folder")
|
.about("Moves an email to the targeted folder")
|
||||||
.arg(id_arg())
|
.arg(id_arg())
|
||||||
.arg(folder::args::target_arg()),
|
.arg(folder::args::target_arg()),
|
||||||
SubCommand::with_name(CMD_DELETE)
|
SubCommand::with_name(CMD_DEL)
|
||||||
.aliases(&["del", "d", "remove", "rm"])
|
.aliases(&["del", "d", "remove", "rm"])
|
||||||
.about("Deletes an email")
|
.about("Deletes an email")
|
||||||
.arg(id_arg()),
|
.arg(ids_arg()),
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
.concat()
|
.concat()
|
||||||
|
@ -249,7 +250,7 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
/// Represents the email id argument.
|
/// Represents the email id argument.
|
||||||
pub fn id_arg<'a>() -> Arg<'a, 'a> {
|
pub fn id_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name(ARG_ID)
|
Arg::with_name(ARG_ID)
|
||||||
.help("Specifies the targeted email")
|
.help("Specifies the target email")
|
||||||
.value_name("ID")
|
.value_name("ID")
|
||||||
.required(true)
|
.required(true)
|
||||||
}
|
}
|
||||||
|
@ -304,11 +305,11 @@ pub fn parse_criteria_arg<'a>(matches: &'a ArgMatches<'a>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the email ids argument.
|
/// Represents the email ids argument.
|
||||||
pub fn id_range_arg<'a>() -> Arg<'a, 'a> {
|
pub fn ids_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name(ARG_IDS)
|
Arg::with_name(ARG_IDS)
|
||||||
.help("Specifies targeted email(s)")
|
.help("Specifies the target email(s)")
|
||||||
.long_help("Specifies a range of targeted emails. The range follows the RFC3501 format.")
|
.long_help("Specifies a range of emails. The range follows the RFC3501 format.")
|
||||||
.value_name("RANGE")
|
.value_name("IDS")
|
||||||
.required(true)
|
.required(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,14 +352,14 @@ fn page_arg<'a>() -> Arg<'a, 'a> {
|
||||||
.short("p")
|
.short("p")
|
||||||
.long("page")
|
.long("page")
|
||||||
.value_name("INT")
|
.value_name("INT")
|
||||||
.default_value("0")
|
.default_value("1")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents the page argument parser.
|
/// Represents the page argument parser.
|
||||||
fn parse_page_arg<'a>(matches: &'a ArgMatches<'a>) -> usize {
|
fn parse_page_arg<'a>(matches: &'a ArgMatches<'a>) -> usize {
|
||||||
matches
|
matches
|
||||||
.value_of(ARG_PAGE)
|
.value_of(ARG_PAGE)
|
||||||
.unwrap_or("1")
|
.unwrap()
|
||||||
.parse()
|
.parse()
|
||||||
.ok()
|
.ok()
|
||||||
.map(|page| 1.max(page) - 1)
|
.map(|page| 1.max(page) - 1)
|
||||||
|
@ -453,8 +454,7 @@ pub fn parse_mime_type_arg<'a>(matches: &'a ArgMatches<'a>) -> &'a str {
|
||||||
/// Represents the email query argument.
|
/// Represents the email query argument.
|
||||||
pub fn query_arg<'a>() -> Arg<'a, 'a> {
|
pub fn query_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name(ARG_QUERY)
|
Arg::with_name(ARG_QUERY)
|
||||||
.help("IMAP query")
|
.long_help("The query system depends on the backend, see the wiki for more details")
|
||||||
.long_help("The IMAP query format follows the RFC3501. The query is case-insensitive.")
|
|
||||||
.value_name("QUERY")
|
.value_name("QUERY")
|
||||||
.multiple(true)
|
.multiple(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
|
|
|
@ -61,21 +61,21 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
SubCommand::with_name(CMD_ADD)
|
SubCommand::with_name(CMD_ADD)
|
||||||
.aliases(&["a"])
|
.aliases(&["a"])
|
||||||
.about("Adds email flags")
|
.about("Adds email flags")
|
||||||
.arg(email::args::id_range_arg())
|
.arg(email::args::ids_arg())
|
||||||
.arg(flags_arg()),
|
.arg(flags_arg()),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name(CMD_SET)
|
SubCommand::with_name(CMD_SET)
|
||||||
.aliases(&["s", "change", "c"])
|
.aliases(&["s", "change", "c"])
|
||||||
.about("Sets email flags")
|
.about("Sets email flags")
|
||||||
.arg(email::args::id_range_arg())
|
.arg(email::args::ids_arg())
|
||||||
.arg(flags_arg()),
|
.arg(flags_arg()),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name(CMD_DEL)
|
SubCommand::with_name(CMD_DEL)
|
||||||
.aliases(&["rem", "rm", "r", "delete", "del", "d"])
|
.aliases(&["rem", "rm", "r", "delete", "del", "d"])
|
||||||
.about("Removes email flags")
|
.about("Removes email flags")
|
||||||
.arg(email::args::id_range_arg())
|
.arg(email::args::ids_arg())
|
||||||
.arg(flags_arg()),
|
.arg(flags_arg()),
|
||||||
)]
|
)]
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub fn source_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name(ARG_SOURCE)
|
Arg::with_name(ARG_SOURCE)
|
||||||
.short("f")
|
.short("f")
|
||||||
.long("folder")
|
.long("folder")
|
||||||
.help("Specifies the folder source")
|
.help("Specifies the source folder")
|
||||||
.value_name("SOURCE")
|
.value_name("SOURCE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ pub fn parse_source_arg<'a>(matches: &'a ArgMatches<'a>) -> &'a str {
|
||||||
/// Represents the target folder argument.
|
/// Represents the target folder argument.
|
||||||
pub fn target_arg<'a>() -> Arg<'a, 'a> {
|
pub fn target_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name(ARG_TARGET)
|
Arg::with_name(ARG_TARGET)
|
||||||
.help("Specifies the folder target")
|
.help("Specifies the target folder")
|
||||||
.value_name("TARGET")
|
.value_name("TARGET")
|
||||||
.required(true)
|
.required(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,3 @@ impl fmt::Display for OutputFmt {
|
||||||
write!(f, "{}", fmt)
|
write!(f, "{}", fmt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defines a struct-wrapper to provide a JSON output.
|
|
||||||
#[derive(Debug, Clone, serde::Serialize)]
|
|
||||||
pub struct OutputJson<T: serde::Serialize> {
|
|
||||||
response: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: serde::Serialize> OutputJson<T> {
|
|
||||||
pub fn new(response: T) -> Self {
|
|
||||||
Self { response }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt::{self, Debug};
|
||||||
use termcolor::{ColorChoice, StandardStream};
|
use termcolor::{ColorChoice, StandardStream};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
output::{OutputFmt, OutputJson},
|
output::OutputFmt,
|
||||||
printer::{Print, PrintTable, PrintTableOpts, WriteColor},
|
printer::{Print, PrintTable, PrintTableOpts, WriteColor},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ impl Printer for StdoutPrinter {
|
||||||
fn print_struct<T: Debug + Print + serde::Serialize>(&mut self, data: T) -> Result<()> {
|
fn print_struct<T: Debug + Print + serde::Serialize>(&mut self, data: T) -> Result<()> {
|
||||||
match self.fmt {
|
match self.fmt {
|
||||||
OutputFmt::Plain => data.print(self.writer.as_mut()),
|
OutputFmt::Plain => data.print(self.writer.as_mut()),
|
||||||
OutputFmt::Json => serde_json::to_writer(self.writer.as_mut(), &OutputJson::new(data))
|
OutputFmt::Json => serde_json::to_writer(self.writer.as_mut(), &data)
|
||||||
.context("cannot write JSON to writer"),
|
.context("cannot write json to writer"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue