Skip to content

Commit

Permalink
feat(take): ALL functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Perkowski <[email protected]>
  • Loading branch information
adamperkowski committed Nov 25, 2024
1 parent 15b75d9 commit 0ee83eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 2 additions & 2 deletions man/nvrs.1
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Compare newver with oldver and display differences as updates

.TP
\fB\-t\fR, \fB\-\-take\fR \fI<packages>\fR
List of packages to update automatically, separated by a comma
Comma-separated list of packages to update automatically (use `ALL` for all)

.TP
\fB\-n\fR, \fB\-\-nuke\fR \fI<packages>\fR
List of packages to delete from the config, separated by a comma
Comma-separated list of packages to delete from the config

.TP
\fB\-\-config\fR \fI<path>\fR
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct Cli {
short = 't',
long,
value_name = "packages",
help = "List of packages to update automatically, separated by a comma",
help = "Comma-separated list of packages to update automatically (use `ALL` for all)",
value_delimiter = ','
)]
pub take: Option<Vec<String>>,
Expand All @@ -34,7 +34,7 @@ pub struct Cli {
short = 'n',
long,
value_name = "packages",
help = "List of packages to delete from the config",
help = "Comma-separated list of packages to delete from the config",
value_delimiter = ','
)]
pub nuke: Option<Vec<String>>,
Expand Down
28 changes: 17 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,36 @@ async fn take(core: Core, take_names: Option<Vec<String>>) -> error::Result<()>
let config = core.config;
let (mut oldver, newver) = core.verfiles;

for package_name in names {
if let Some(new_pkg) = newver.data.data.iter().find(|p| p.0 == &package_name) {
if let Some(old_pkg) = oldver.data.data.iter_mut().find(|p| p.0 == &package_name) {
if old_pkg.1.version != new_pkg.1.version {
let packages_to_update = if names.contains(&"ALL".to_string()) {
newver.data.data.keys().cloned().collect()
} else {
names
};

for package_name in packages_to_update {
if let Some(new_pkg) = newver.data.data.get(&package_name) {
if let Some(old_pkg) = oldver.data.data.get_mut(&package_name) {
if old_pkg.version != new_pkg.version {
println!(
"{} {} {} -> {}",
"+".white().on_black(),
package_name.blue(),
old_pkg.1.version.red(),
new_pkg.1.version.green()
old_pkg.version.red(),
new_pkg.version.green()
);
old_pkg.1.version = new_pkg.1.version.clone();
old_pkg.1.gitref = new_pkg.1.gitref.clone();
old_pkg.1.url = new_pkg.1.url.clone();
old_pkg.version = new_pkg.version.clone();
old_pkg.gitref = new_pkg.gitref.clone();
old_pkg.url = new_pkg.url.clone();
}
} else {
println!(
"{} {} {} -> {}",
"+".white().on_black(),
package_name.blue(),
"NONE".red(),
new_pkg.1.version.green()
new_pkg.version.green()
);
oldver.data.data.insert(package_name, new_pkg.1.clone());
oldver.data.data.insert(package_name, new_pkg.clone());
}
} else {
return Err(error::Error::PkgNotInNewver(package_name));
Expand Down

0 comments on commit 0ee83eb

Please sign in to comment.