mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 05:07:55 +08:00
extract output cli+utils
This commit is contained in:
+2
-9
@@ -7,6 +7,7 @@ use crate::{
|
||||
imap::cli::{imap_matches, imap_subcmds},
|
||||
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
||||
msg::cli::{msg_matches, msg_subcmds},
|
||||
output::cli::output_args,
|
||||
};
|
||||
|
||||
error_chain! {
|
||||
@@ -26,15 +27,7 @@ impl<'a> App<'a> {
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||
.author(env!("CARGO_PKG_AUTHORS"))
|
||||
.arg(
|
||||
Arg::with_name("output")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.help("Defines the output format")
|
||||
.value_name("STRING")
|
||||
.possible_values(&["plain", "json"])
|
||||
.default_value("plain"),
|
||||
)
|
||||
.args(&output_args())
|
||||
.arg(
|
||||
Arg::with_name("account")
|
||||
.long("account")
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ use serde::Deserialize;
|
||||
use std::{collections::HashMap, env, fs::File, io::Read, path::PathBuf};
|
||||
use toml;
|
||||
|
||||
use crate::output::run_cmd;
|
||||
use crate::output::utils::run_cmd;
|
||||
|
||||
error_chain! {}
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ pub fn imap_matches(matches: &ArgMatches) -> Result<bool> {
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
let mbox = matches.value_of("mailbox").unwrap();
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("idle") {
|
||||
if let Some(_) = matches.subcommand_matches("idle") {
|
||||
imap_conn.idle(&config, &mbox)?;
|
||||
imap_conn.logout();
|
||||
return Ok(true);
|
||||
|
||||
+4
-1
@@ -1,9 +1,12 @@
|
||||
mod app;
|
||||
mod config;
|
||||
mod input;
|
||||
mod output;
|
||||
mod smtp;
|
||||
mod table;
|
||||
mod output {
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod utils;
|
||||
}
|
||||
mod imap {
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod model;
|
||||
|
||||
+2
-2
@@ -1,14 +1,14 @@
|
||||
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
||||
use error_chain::error_chain;
|
||||
|
||||
use crate::{config::Config, imap::model::ImapConnector, output::print};
|
||||
use crate::{config::Config, imap::model::ImapConnector, output::utils::print};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
Config(crate::config::Error, crate::config::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
||||
Output(crate::output::Error, crate::output::ErrorKind);
|
||||
OutputUtils(crate::output::utils::Error, crate::output::utils::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ use crate::{
|
||||
imap::model::ImapConnector,
|
||||
input,
|
||||
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
||||
output::print,
|
||||
output::utils::print,
|
||||
smtp,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ error_chain! {
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
Input(crate::input::Error, crate::input::ErrorKind);
|
||||
MsgModel(crate::msg::model::Error, crate::msg::model::ErrorKind);
|
||||
Output(crate::output::Error, crate::output::ErrorKind);
|
||||
OutputUtils(crate::output::utils::Error, crate::output::utils::ErrorKind);
|
||||
Smtp(crate::smtp::Error, crate::smtp::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use clap::Arg;
|
||||
|
||||
pub fn output_args<'a>() -> Vec<Arg<'a, 'a>> {
|
||||
vec![Arg::with_name("output")
|
||||
.long("output")
|
||||
.short("o")
|
||||
.help("Defines the output format")
|
||||
.value_name("STRING")
|
||||
.possible_values(&["plain", "json"])
|
||||
.default_value("plain")]
|
||||
}
|
||||
Reference in New Issue
Block a user