refactor: create helpers file
This commit is contained in:
parent
f4f1b56f02
commit
b66089fc94
|
@ -0,0 +1,28 @@
|
|||
use std::fmt::Display;
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
use log::{debug, error, info, trace, warn};
|
||||
|
||||
pub fn some_non_empty(str: &str) -> Option<String> {
|
||||
if str.is_empty() { None } else { Some(str.to_owned()) }
|
||||
}
|
||||
|
||||
pub fn or_print<T, U: Display>(result: Result<T, U>) -> Option<T> {
|
||||
match result {
|
||||
Ok(value) => Some(value),
|
||||
Err(error) => {
|
||||
warn!("{}", error);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prompt(prompt: &str) -> Option<String> {
|
||||
print!("{} ", prompt);
|
||||
stdout().flush().unwrap();
|
||||
match stdin().lines().next() {
|
||||
Some(Ok(line)) => Some(line),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
25
src/main.rs
25
src/main.rs
|
@ -16,10 +16,12 @@ use log::{debug, error, info, trace, warn};
|
|||
use nostr_sdk::prelude::*;
|
||||
use xdg::BaseDirectories;
|
||||
|
||||
use crate::helpers::*;
|
||||
use crate::kinds::TRACKING_KIND;
|
||||
use crate::task::State;
|
||||
use crate::tasks::Tasks;
|
||||
|
||||
mod helpers;
|
||||
mod task;
|
||||
mod tasks;
|
||||
mod kinds;
|
||||
|
@ -79,29 +81,6 @@ impl Drop for EventSender {
|
|||
}
|
||||
}
|
||||
|
||||
fn some_non_empty(str: &str) -> Option<String> {
|
||||
if str.is_empty() { None } else { Some(str.to_owned()) }
|
||||
}
|
||||
|
||||
fn or_print<T, U: Display>(result: Result<T, U>) -> Option<T> {
|
||||
match result {
|
||||
Ok(value) => Some(value),
|
||||
Err(error) => {
|
||||
warn!("{}", error);
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt(prompt: &str) -> Option<String> {
|
||||
print!("{} ", prompt);
|
||||
stdout().flush().unwrap();
|
||||
match stdin().lines().next() {
|
||||
Some(Ok(line)) => Some(line),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
colog::init();
|
||||
|
|
|
@ -8,8 +8,8 @@ use itertools::Itertools;
|
|||
use log::{debug, error, info, trace, warn};
|
||||
use nostr_sdk::{Alphabet, Event, EventBuilder, EventId, Kind, Tag, TagStandard, Timestamp};
|
||||
|
||||
use crate::helpers::some_non_empty;
|
||||
use crate::kinds::is_hashtag;
|
||||
use crate::some_non_empty;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) struct Task {
|
||||
|
|
Loading…
Reference in New Issue