Allow specifying how many items go into the feed
Signed-off-by: Jacob Kiers <code@kiers.eu>
This commit is contained in:
parent
b7e284aba0
commit
48caa99423
@ -31,6 +31,9 @@ pub(crate) struct FeedBuilderSettings {
|
|||||||
/// Create an HTML file for each message
|
/// Create an HTML file for each message
|
||||||
#[clap(short, long, value_parser, default_value_t = false)]
|
#[clap(short, long, value_parser, default_value_t = false)]
|
||||||
pub include_html: bool,
|
pub include_html: bool,
|
||||||
|
/// Maximum number of items in the feed (default: unlimited)
|
||||||
|
#[clap(short = 'n', long, value_parser)]
|
||||||
|
pub max_items: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let data_directory = "data";
|
let data_directory = "data";
|
||||||
|
|
||||||
let result = match &cli.command {
|
match &cli.command {
|
||||||
cli::Command::FetchFromImap(imap_settings) => fetch_from_imap(
|
cli::Command::FetchFromImap(imap_settings) => fetch_from_imap(
|
||||||
data_directory,
|
data_directory,
|
||||||
imap_settings.server.to_owned(),
|
imap_settings.server.to_owned(),
|
||||||
@ -41,14 +41,13 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
&settings.filename,
|
&settings.filename,
|
||||||
&settings.hostname,
|
&settings.hostname,
|
||||||
settings.include_html,
|
settings.include_html,
|
||||||
|
settings.max_items
|
||||||
),
|
),
|
||||||
|
|
||||||
cli::Command::Update => command::update::self_update(),
|
cli::Command::Update => command::update::self_update(),
|
||||||
|
|
||||||
_ => unimplemented!("This method is not yet implemented."),
|
_ => unimplemented!("This method is not yet implemented."),
|
||||||
};
|
}
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_directory<P: AsRef<Path>>(dir: P) -> Result<(), std::io::Error> {
|
fn create_directory<P: AsRef<Path>>(dir: P) -> Result<(), std::io::Error> {
|
||||||
@ -63,6 +62,7 @@ fn build_feed(
|
|||||||
filename: &PathBuf,
|
filename: &PathBuf,
|
||||||
hostname: &String,
|
hostname: &String,
|
||||||
include_html: bool,
|
include_html: bool,
|
||||||
|
max_items_in_feed: Option<usize>
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let dir = filename.parent().ok_or(format!(
|
let dir = filename.parent().ok_or(format!(
|
||||||
"Could not get parent directory of {}",
|
"Could not get parent directory of {}",
|
||||||
@ -87,7 +87,9 @@ fn build_feed(
|
|||||||
|
|
||||||
let mut reader = DataDirectoryMessageReader::new(Path::new("data").to_path_buf());
|
let mut reader = DataDirectoryMessageReader::new(Path::new("data").to_path_buf());
|
||||||
|
|
||||||
for msg in reader.read_rfc822_messages() {
|
let max_items_in_feed = max_items_in_feed.unwrap_or_else(|| usize::MAX);
|
||||||
|
|
||||||
|
for msg in reader.read_rfc822_messages().take(max_items_in_feed) {
|
||||||
let parsed = msg.get_parsed().expect("A parsed messsage.");
|
let parsed = msg.get_parsed().expect("A parsed messsage.");
|
||||||
|
|
||||||
let date = parsed.date().ok_or(format!(
|
let date = parsed.date().ok_or(format!(
|
||||||
|
Loading…
Reference in New Issue
Block a user