mirror of
https://github.com/pimalaya/himalaya.git
synced 2024-12-09 21:18:39 +03:00
add example and bin
This commit is contained in:
@@ -78,6 +78,14 @@ tracing = "0.1"
|
||||
url = "2.2"
|
||||
uuid = { version = "0.8", features = ["v4"] }
|
||||
|
||||
[[example]]
|
||||
name = "keyring"
|
||||
required-features = ["imap", "keyring"]
|
||||
|
||||
[[bin]]
|
||||
name = "keyring"
|
||||
required-features = ["imap", "keyring"]
|
||||
|
||||
[patch.crates-io]
|
||||
# IMAP
|
||||
imap-next = { git = "https://github.com/duesee/imap-next" }
|
||||
|
||||
79
examples/keyring.rs
Normal file
79
examples/keyring.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use std::{collections::HashMap, env};
|
||||
|
||||
use email::{
|
||||
account::config::passwd::PasswdConfig,
|
||||
imap::config::{ImapAuthConfig, ImapConfig},
|
||||
};
|
||||
use himalaya::{
|
||||
account::{
|
||||
arg::name::AccountNameArg, command::configure::AccountConfigureCommand,
|
||||
config::TomlAccountConfig,
|
||||
},
|
||||
config::Config,
|
||||
output::OutputFmt,
|
||||
printer::StdoutPrinter,
|
||||
};
|
||||
use pimalaya_tui::tracing::Tracing;
|
||||
use secret::{keyring::KeyringEntry, Secret};
|
||||
use tracing::info;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env::set_var("RUST_LOG", "debug");
|
||||
Tracing::install().unwrap();
|
||||
|
||||
secret::keyring::set_global_service_name("himalaya-cli");
|
||||
|
||||
info!("checking keyring-lib");
|
||||
|
||||
let entry = KeyringEntry::try_new("key").unwrap();
|
||||
entry.set_secret("val").await.unwrap();
|
||||
assert_eq!("val", entry.get_secret().await.unwrap());
|
||||
|
||||
info!("checking secret-lib");
|
||||
|
||||
let mut secret = Secret::new_keyring_entry(entry);
|
||||
assert_eq!(secret.get().await.unwrap(), "val");
|
||||
|
||||
secret.set("val2").await.unwrap();
|
||||
assert_eq!(secret.get().await.unwrap(), "val2");
|
||||
|
||||
info!("checking email-lib");
|
||||
|
||||
let config = PasswdConfig(secret);
|
||||
config.reset().await.unwrap();
|
||||
config.configure(|| Ok(String::from("val3"))).await.unwrap();
|
||||
assert_eq!(config.get().await.unwrap(), "val3");
|
||||
|
||||
info!("checking himalaya");
|
||||
|
||||
let mut printer = StdoutPrinter::new(OutputFmt::Plain);
|
||||
let cmd = AccountConfigureCommand {
|
||||
account: AccountNameArg {
|
||||
name: String::from("account"),
|
||||
},
|
||||
reset: true,
|
||||
};
|
||||
|
||||
cmd.execute(
|
||||
&mut printer,
|
||||
&Config {
|
||||
accounts: HashMap::from_iter([(
|
||||
String::from("account"),
|
||||
TomlAccountConfig {
|
||||
imap: Some(ImapConfig {
|
||||
auth: ImapAuthConfig::Passwd(config.clone()),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let secret = config.get().await.unwrap();
|
||||
println!("secret: {secret}");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
mod check_up;
|
||||
mod configure;
|
||||
mod list;
|
||||
pub mod check_up;
|
||||
pub mod configure;
|
||||
pub mod list;
|
||||
|
||||
use clap::Subcommand;
|
||||
use color_eyre::Result;
|
||||
|
||||
79
src/bin/keyring.rs
Normal file
79
src/bin/keyring.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use std::{collections::HashMap, env};
|
||||
|
||||
use email::{
|
||||
account::config::passwd::PasswdConfig,
|
||||
imap::config::{ImapAuthConfig, ImapConfig},
|
||||
};
|
||||
use himalaya::{
|
||||
account::{
|
||||
arg::name::AccountNameArg, command::configure::AccountConfigureCommand,
|
||||
config::TomlAccountConfig,
|
||||
},
|
||||
config::Config,
|
||||
output::OutputFmt,
|
||||
printer::StdoutPrinter,
|
||||
};
|
||||
use pimalaya_tui::tracing::Tracing;
|
||||
use secret::{keyring::KeyringEntry, Secret};
|
||||
use tracing::info;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env::set_var("RUST_LOG", "debug");
|
||||
Tracing::install().unwrap();
|
||||
|
||||
secret::keyring::set_global_service_name("himalaya-cli");
|
||||
|
||||
info!("checking keyring-lib");
|
||||
|
||||
let entry = KeyringEntry::try_new("key").unwrap();
|
||||
entry.set_secret("val").await.unwrap();
|
||||
assert_eq!("val", entry.get_secret().await.unwrap());
|
||||
|
||||
info!("checking secret-lib");
|
||||
|
||||
let mut secret = Secret::new_keyring_entry(entry);
|
||||
assert_eq!(secret.get().await.unwrap(), "val");
|
||||
|
||||
secret.set("val2").await.unwrap();
|
||||
assert_eq!(secret.get().await.unwrap(), "val2");
|
||||
|
||||
info!("checking email-lib");
|
||||
|
||||
let config = PasswdConfig(secret);
|
||||
config.reset().await.unwrap();
|
||||
config.configure(|| Ok(String::from("val3"))).await.unwrap();
|
||||
assert_eq!(config.get().await.unwrap(), "val3");
|
||||
|
||||
info!("checking himalaya");
|
||||
|
||||
let mut printer = StdoutPrinter::new(OutputFmt::Plain);
|
||||
let cmd = AccountConfigureCommand {
|
||||
account: AccountNameArg {
|
||||
name: String::from("account"),
|
||||
},
|
||||
reset: true,
|
||||
};
|
||||
|
||||
cmd.execute(
|
||||
&mut printer,
|
||||
&Config {
|
||||
accounts: HashMap::from_iter([(
|
||||
String::from("account"),
|
||||
TomlAccountConfig {
|
||||
imap: Some(ImapConfig {
|
||||
auth: ImapAuthConfig::Passwd(config.clone()),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let secret = config.get().await.unwrap();
|
||||
println!("secret: {secret}");
|
||||
}
|
||||
Reference in New Issue
Block a user