Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add news_url in config.rs #1071

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions man/paru.8
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ gpg config\%.


.TP
.B \-\-newsonupgrade
Print new news during sysupgrade.
.B \-\-newsonupgrade[=URL]
Print new news during sysupgrade. By default paru fetches news from the Arch Linux
RSS news feed. Users of other distributions can customize the RSS feed URL here.

.TP
.B \-\-useask
Expand Down
5 changes: 3 additions & 2 deletions man/paru.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,9 @@ are built or a package in the build queue is needed as a dependency to build
another package, install all the packages in the install queue.

.TP
.B NewsOnUpgrade
Print new news during sysupgrade.
.B NewsOnUpgrade [= URL]
Print new news during sysupgrade. By default paru fetches news from the Arch Linux
RSS news feed. Users of other distributions can customize the RSS feed URL here.

.TP
.B UseAsk
Expand Down
13 changes: 11 additions & 2 deletions src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,16 @@ impl Config {
Arg::Long("noinstall") => self.no_install = true,

Arg::Long("print") | Arg::Short('p') => self.print = true,
Arg::Long("newsonupgrade") => self.news_on_upgrade = true,
Arg::Long("nonewsonupgrade") => self.news_on_upgrade = false,
Arg::Long("newsonupgrade") => {
let url: Option<Url>;
if let Some(value) = value.ok() {
url = Some(value.parse()?);
} else {
url = None;
}
self.enable_news(url)?;
}
Arg::Long("nonewsonupgrade") => self.news_url = None,
Arg::Long("comments") => self.comments = true,
Arg::Long("ssh") => self.ssh = true,
Arg::Long("failfast") => self.fail_fast = true,
Expand Down Expand Up @@ -414,6 +422,7 @@ fn takes_value(arg: Arg) -> TakesValue {
Arg::Long("redownload") => TakesValue::Optional,
Arg::Long("rebuild") => TakesValue::Optional,
Arg::Long("sudoloop") => TakesValue::Optional,
Arg::Long("newsonupgrade") => TakesValue::Optional,
Arg::Long("develsuffixes") => TakesValue::Required,
Arg::Long("localrepo") => TakesValue::Optional,
Arg::Long("chroot") => TakesValue::Optional,
Expand Down
19 changes: 17 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ pub struct Config {
pub aur_rpc_url: Option<Url>,
#[default(Url::parse("https://archlinux.org").unwrap())]
pub arch_url: Url,
pub news_url: Option<Url>,
pub build_dir: PathBuf,
pub cache_dir: PathBuf,
pub state_dir: PathBuf,
Expand Down Expand Up @@ -467,7 +468,6 @@ pub struct Config {
pub optional: bool,
pub complete: bool,
pub print: bool,
pub news_on_upgrade: bool,
pub comments: bool,
pub ssh: bool,
pub keep_repo_cache: bool,
Expand Down Expand Up @@ -1056,7 +1056,15 @@ impl Config {
"BatchInstall" => self.batch_install = true,
"UseAsk" => self.use_ask = true,
"SaveChanges" => self.save_changes = true,
"NewsOnUpgrade" => self.news_on_upgrade = true,
uetcis marked this conversation as resolved.
Show resolved Hide resolved
"NewsOnUpgrade" => {
let url: Option<Url>;
if let Some(l) = value {
url = Some(l.parse()?);
} else {
url = None;
}
self.enable_news(url)?;
}
"InstallDebug" => self.install_debug = true,
"Redownload" => self.redownload = YesNoAll::Yes.default_or(key, value)?,
"Rebuild" => self.rebuild = YesNoAllTree::Yes.default_or(key, value)?,
Expand Down Expand Up @@ -1158,6 +1166,13 @@ impl Config {
"aur"
}
}

// sets url to the one specified if url is Some,
// or the defualt arch news url if it's None
pub fn enable_news(&mut self, url: Option<Url>) -> Result<()> {
self.news_url = Some(url.unwrap_or(self.arch_url.join("feeds/news")?));
Ok(())
}
}

pub fn version() {
Expand Down
2 changes: 1 addition & 1 deletion src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Installer {
async fn news(&self, config: &Config) -> Result<()> {
let c = config.color;

if config.news_on_upgrade && config.args.has_arg("u", "sysupgrade") {
if config.news_url.is_some() && config.args.has_arg("u", "sysupgrade") {
let mut ret = 0;
match news::news(config).await {
Ok(v) => ret = v,
Expand Down
7 changes: 5 additions & 2 deletions src/news.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::fmt::print_indent;
use std::str::Chars;

use ansi_term::Style;
use anyhow::{bail, Result};
use anyhow::{bail, Context, Result};
use htmlescape::decode_html;
use rss::Channel;
use tr::tr;
Expand All @@ -30,7 +30,10 @@ pub fn newest_pkg(config: &Config) -> i64 {
}

pub async fn news(config: &Config) -> Result<i32> {
let url = config.arch_url.join("feeds/news")?;
let url = config
.news_url
.clone()
.with_context(|| "NewsOnUpgrade is not set")?;
let client = config.raur.client();

let resp = client.get(url.clone()).send().await?;
Expand Down