formatting & lints, one fix for member-only groups

This commit is contained in:
2021-08-22 18:55:06 +02:00
parent 4c8fbb413d
commit 8822d8d11d
10 changed files with 528 additions and 323 deletions
+45 -49
View File
@@ -5,67 +5,62 @@ extern crate elefren;
extern crate log;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate smart_default;
// #[macro_use]
// extern crate smart_default;
#[macro_use]
extern crate thiserror;
use clap::Arg;
use elefren::{FediClient, Registration, Scopes, StatusBuilder};
use elefren::debug::NotificationDisplay;
use elefren::entities::account::Account;
use elefren::entities::event::Event;
use elefren::entities::notification::NotificationType;
use elefren::scopes;
use elefren::status_builder::Visibility;
use log::LevelFilter;
use tokio_stream::{Stream, StreamExt};
use crate::store::{NewGroupOptions, StoreOptions};
use crate::utils::acct_to_server;
mod store;
mod group_handle;
mod utils;
mod command;
mod error;
mod group_handle;
mod store;
mod utils;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let args = clap::App::new("groups")
.arg(Arg::with_name("verbose")
.short("v")
.multiple(true)
.help("increase logging, can be repeated"))
.arg(Arg::with_name("config")
.short("c")
.long("config")
.takes_value(true)
.help("set custom storage file, defaults to groups.json"))
.arg(Arg::with_name("auth")
.short("a")
.long("auth")
.takes_value(true)
.value_name("HANDLE")
.help("authenticate to a new server (always using https)"))
.arg(Arg::with_name("reauth")
.short("A")
.long("reauth")
.takes_value(true)
.value_name("HANDLE")
.help("authenticate to a new server (always using https)"))
.arg(
Arg::with_name("verbose")
.short("v")
.multiple(true)
.help("increase logging, can be repeated"),
)
.arg(
Arg::with_name("config")
.short("c")
.long("config")
.takes_value(true)
.help("set custom storage file, defaults to groups.json"),
)
.arg(
Arg::with_name("auth")
.short("a")
.long("auth")
.takes_value(true)
.value_name("HANDLE")
.help("authenticate to a new server (always using https)"),
)
.arg(
Arg::with_name("reauth")
.short("A")
.long("reauth")
.takes_value(true)
.value_name("HANDLE")
.help("authenticate to a new server (always using https)"),
)
.get_matches();
const LEVELS : [LevelFilter; 5] = [
/// Corresponds to the `Error` log level.
const LEVELS: [LevelFilter; 5] = [
LevelFilter::Error,
/// Corresponds to the `Warn` log level.
LevelFilter::Warn,
/// Corresponds to the `Info` log level.
LevelFilter::Info,
/// Corresponds to the `Debug` log level.
LevelFilter::Debug,
/// Corresponds to the `Trace` log level.
LevelFilter::Trace,
];
@@ -83,15 +78,18 @@ async fn main() -> anyhow::Result<()> {
let store = store::ConfigStore::new(StoreOptions {
store_path: args.value_of("config").unwrap_or("groups.json").to_string(),
save_pretty: true,
}).await?;
})
.await?;
if let Some(handle) = args.value_of("auth") {
let acct = handle.trim_start_matches('@');
if let Some(server) = acct_to_server(acct) {
let g = store.auth_new_group(NewGroupOptions {
server: format!("https://{}", server),
acct: acct.to_string()
}).await?;
let g = store
.auth_new_group(NewGroupOptions {
server: format!("https://{}", server),
acct: acct.to_string(),
})
.await?;
eprintln!("New group @{} added to config!", g.config.get_acct());
return Ok(());
@@ -108,13 +106,11 @@ async fn main() -> anyhow::Result<()> {
}
// Start
let mut groups = store.spawn_groups().await;
let groups = store.spawn_groups().await;
let mut handles = vec![];
for mut g in groups {
handles.push(tokio::spawn(async move {
g.run().await
}));
handles.push(tokio::spawn(async move { g.run().await }));
}
futures::future::join_all(handles).await;