mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
extract output cli+utils
This commit is contained in:
parent
e2ba18cda8
commit
f2158e71d2
11
src/app.rs
11
src/app.rs
|
@ -7,6 +7,7 @@ use crate::{
|
||||||
imap::cli::{imap_matches, imap_subcmds},
|
imap::cli::{imap_matches, imap_subcmds},
|
||||||
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
||||||
msg::cli::{msg_matches, msg_subcmds},
|
msg::cli::{msg_matches, msg_subcmds},
|
||||||
|
output::cli::output_args,
|
||||||
};
|
};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
|
@ -26,15 +27,7 @@ impl<'a> App<'a> {
|
||||||
.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"))
|
||||||
.arg(
|
.args(&output_args())
|
||||||
Arg::with_name("output")
|
|
||||||
.long("output")
|
|
||||||
.short("o")
|
|
||||||
.help("Defines the output format")
|
|
||||||
.value_name("STRING")
|
|
||||||
.possible_values(&["plain", "json"])
|
|
||||||
.default_value("plain"),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("account")
|
Arg::with_name("account")
|
||||||
.long("account")
|
.long("account")
|
||||||
|
|
|
@ -4,7 +4,7 @@ use serde::Deserialize;
|
||||||
use std::{collections::HashMap, env, fs::File, io::Read, path::PathBuf};
|
use std::{collections::HashMap, env, fs::File, io::Read, path::PathBuf};
|
||||||
use toml;
|
use toml;
|
||||||
|
|
||||||
use crate::output::run_cmd;
|
use crate::output::utils::run_cmd;
|
||||||
|
|
||||||
error_chain! {}
|
error_chain! {}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn imap_matches(matches: &ArgMatches) -> Result<bool> {
|
||||||
let mut imap_conn = ImapConnector::new(&account)?;
|
let mut imap_conn = ImapConnector::new(&account)?;
|
||||||
let mbox = matches.value_of("mailbox").unwrap();
|
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.idle(&config, &mbox)?;
|
||||||
imap_conn.logout();
|
imap_conn.logout();
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
mod app;
|
mod app;
|
||||||
mod config;
|
mod config;
|
||||||
mod input;
|
mod input;
|
||||||
mod output;
|
|
||||||
mod smtp;
|
mod smtp;
|
||||||
mod table;
|
mod table;
|
||||||
|
mod output {
|
||||||
|
pub(crate) mod cli;
|
||||||
|
pub(crate) mod utils;
|
||||||
|
}
|
||||||
mod imap {
|
mod imap {
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
pub(crate) mod model;
|
pub(crate) mod model;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
||||||
use error_chain::error_chain;
|
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! {
|
error_chain! {
|
||||||
links {
|
links {
|
||||||
Config(crate::config::Error, crate::config::ErrorKind);
|
Config(crate::config::Error, crate::config::ErrorKind);
|
||||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||||
MsgCli(crate::msg::cli::Error, crate::msg::cli::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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
imap::model::ImapConnector,
|
imap::model::ImapConnector,
|
||||||
input,
|
input,
|
||||||
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
||||||
output::print,
|
output::utils::print,
|
||||||
smtp,
|
smtp,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ error_chain! {
|
||||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||||
Input(crate::input::Error, crate::input::ErrorKind);
|
Input(crate::input::Error, crate::input::ErrorKind);
|
||||||
MsgModel(crate::msg::model::Error, crate::msg::model::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);
|
Smtp(crate::smtp::Error, crate::smtp::ErrorKind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
src/output/cli.rs
Normal file
11
src/output/cli.rs
Normal file
|
@ -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")]
|
||||||
|
}
|
Loading…
Reference in a new issue