[6/9] pakfire: Add list upgrade functionality

Message ID 20220309225655.4472-7-robin.roevens@disroot.org
State Superseded
Headers
Series pakfire: remove dup. code + seperate ui/logic |

Commit Message

Robin Roevens March 9, 2022, 10:56 p.m. UTC
  - Added possibility to list available upgrades from commandline
  using 'pakfire list upgrade'.
- Bugfix: allow [options] between 'list' and [installed/notinstalled/
  upgrade]

Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
---
 src/pakfire/lib/functions.pl |  2 +-
 src/pakfire/pakfire          | 14 +++++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)
  

Comments

Michael Tremer March 21, 2022, 4:33 p.m. UTC | #1
Hello,

> On 9 Mar 2022, at 22:56, Robin Roevens <robin.roevens@disroot.org> wrote:
> 
> - Added possibility to list available upgrades from commandline
>  using 'pakfire list upgrade'.
> - Bugfix: allow [options] between 'list' and [installed/notinstalled/
>  upgrade]
> 
> Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
> ---
> src/pakfire/lib/functions.pl |  2 +-
> src/pakfire/pakfire          | 14 +++++++++++++-
> 2 files changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
> index 6287367f5..b35aed6a3 100644
> --- a/src/pakfire/lib/functions.pl
> +++ b/src/pakfire/lib/functions.pl
> @@ -114,7 +114,7 @@ sub usage {
>   &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>");
>   &Pakfire::message("               <update> - Contacts the servers for new lists of paks.");
>   &Pakfire::message("               <upgrade> - Installs the latest version of all paks.");
> -  &Pakfire::message("               <list> - Outputs a short list with all available paks.");
> +  &Pakfire::message("               <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks.");
>   &Pakfire::message("               <status> - Outputs a summary about available core upgrades, updates and a required reboot");
>   &Pakfire::message("");
>   &Pakfire::message("       Global options:");
> diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire
> index 2fb9adce7..b529db77a 100644
> --- a/src/pakfire/pakfire
> +++ b/src/pakfire/pakfire
> @@ -333,7 +333,9 @@
> 		my $reset_color = "";
> 		my $filter = "all";
> 
> -		if ("$ARGV[1]" =~ /installed|notinstalled/) {
> +		shift if ("$ARGV[1]" =~ "^-"); 
> +
> +		if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/) {
> 			$filter = "$ARGV[1]";
> 		} else {
> 			&Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); 
> @@ -347,6 +349,16 @@
> 			$use_color = "$Pakfire::color{'lightgreen'}";
> 		}
> 
> +  		# Check for available core upgrade first if list of upgrades is requested
> +		if ("$filter" eq "upgrade") {
> +			my %coredb = &Pakfire::coredbinfo();
> +
> +			if (defined $coredb{'AvailableRelease'}) {
> +				print "${use_color}Core-Update $coredb{'CoreVersion'}\n";
> +				print "Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}${reset_color}\n\n";
> +			}
> +		}

Here we should add an exit code, because monitoring people love them :)

> +
> 		foreach $pak (sort keys %paklist) {
> 			if ("$Pakfire::enable_colors" eq "1") {
> 				if ("$paklist{$pak}{'Installed'}" eq "yes") {
> -- 
> 2.34.1
> 
> 
> -- 
> Dit bericht is gescanned op virussen en andere gevaarlijke
> inhoud door MailScanner en lijkt schoon te zijn.
>
  
Robin Roevens March 22, 2022, 12:59 p.m. UTC | #2
Michael Tremer schreef op ma 21-03-2022 om 16:33 [+0000]:
> Hello,
> 
> > On 9 Mar 2022, at 22:56, Robin Roevens <robin.roevens@disroot.org>
> > wrote:
> > 
> > - Added possibility to list available upgrades from commandline
> >  using 'pakfire list upgrade'.
> > - Bugfix: allow [options] between 'list' and
> > [installed/notinstalled/
> >  upgrade]
> > 
> > Signed-off-by: Robin Roevens <robin.roevens@disroot.org>
> > ---
> > src/pakfire/lib/functions.pl |  2 +-
> > src/pakfire/pakfire          | 14 +++++++++++++-
> > 2 files changed, 14 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/pakfire/lib/functions.pl
> > b/src/pakfire/lib/functions.pl
> > index 6287367f5..b35aed6a3 100644
> > --- a/src/pakfire/lib/functions.pl
> > +++ b/src/pakfire/lib/functions.pl
> > @@ -114,7 +114,7 @@ sub usage {
> >   &Pakfire::message("Usage: pakfire <install|remove> [options]
> > <pak(s)>");
> >   &Pakfire::message("               <update> - Contacts the servers
> > for new lists of paks.");
> >   &Pakfire::message("               <upgrade> - Installs the latest
> > version of all paks.");
> > -  &Pakfire::message("               <list> - Outputs a short list
> > with all available paks.");
> > +  &Pakfire::message("               <list>
> > [installed/notinstalled/upgrade] - Outputs a list with all,
> > installed, available or upgradeable paks.");
> >   &Pakfire::message("               <status> - Outputs a summary
> > about available core upgrades, updates and a required reboot");
> >   &Pakfire::message("");
> >   &Pakfire::message("       Global options:");
> > diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire
> > index 2fb9adce7..b529db77a 100644
> > --- a/src/pakfire/pakfire
> > +++ b/src/pakfire/pakfire
> > @@ -333,7 +333,9 @@
> >                 my $reset_color = "";
> >                 my $filter = "all";
> > 
> > -               if ("$ARGV[1]" =~ /installed|notinstalled/) {
> > +               shift if ("$ARGV[1]" =~ "^-"); 
> > +
> > +               if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/)
> > {
> >                         $filter = "$ARGV[1]";
> >                 } else {
> >                         &Pakfire::message("PAKFIRE WARN: Not a
> > known option $ARGV[1]") if ($ARGV[1]); 
> > @@ -347,6 +349,16 @@
> >                         $use_color =
> > "$Pakfire::color{'lightgreen'}";
> >                 }
> > 
> > +               # Check for available core upgrade first if list of
> > upgrades is requested
> > +               if ("$filter" eq "upgrade") {
> > +                       my %coredb = &Pakfire::coredbinfo();
> > +
> > +                       if (defined $coredb{'AvailableRelease'}) {
> > +                               print "${use_color}Core-Update
> > $coredb{'CoreVersion'}\n";
> > +                               print "Release: $coredb{'Release'}
> > -> $coredb{'AvailableRelease'}${reset_color}\n\n";
> > +                       }
> > +               }
> 
> Here we should add an exit code, because monitoring people love them
> :)
Agreed :-).. will look into it.
> 
> > +
> >                 foreach $pak (sort keys %paklist) {
> >                         if ("$Pakfire::enable_colors" eq "1") {
> >                                 if ("$paklist{$pak}{'Installed'}"
> > eq "yes") {
> > -- 
> > 2.34.1
> > 
> > 
> > -- 
> > Dit bericht is gescanned op virussen en andere gevaarlijke
> > inhoud door MailScanner en lijkt schoon te zijn.
> > 
> 
>
  

Patch

diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
index 6287367f5..b35aed6a3 100644
--- a/src/pakfire/lib/functions.pl
+++ b/src/pakfire/lib/functions.pl
@@ -114,7 +114,7 @@  sub usage {
   &Pakfire::message("Usage: pakfire <install|remove> [options] <pak(s)>");
   &Pakfire::message("               <update> - Contacts the servers for new lists of paks.");
   &Pakfire::message("               <upgrade> - Installs the latest version of all paks.");
-  &Pakfire::message("               <list> - Outputs a short list with all available paks.");
+  &Pakfire::message("               <list> [installed/notinstalled/upgrade] - Outputs a list with all, installed, available or upgradeable paks.");
   &Pakfire::message("               <status> - Outputs a summary about available core upgrades, updates and a required reboot");
   &Pakfire::message("");
   &Pakfire::message("       Global options:");
diff --git a/src/pakfire/pakfire b/src/pakfire/pakfire
index 2fb9adce7..b529db77a 100644
--- a/src/pakfire/pakfire
+++ b/src/pakfire/pakfire
@@ -333,7 +333,9 @@ 
 		my $reset_color = "";
 		my $filter = "all";
 
-		if ("$ARGV[1]" =~ /installed|notinstalled/) {
+		shift if ("$ARGV[1]" =~ "^-"); 
+
+		if ("$ARGV[1]" =~ /installed|notinstalled|upgrade/) {
 			$filter = "$ARGV[1]";
 		} else {
 			&Pakfire::message("PAKFIRE WARN: Not a known option $ARGV[1]") if ($ARGV[1]); 
@@ -347,6 +349,16 @@ 
 			$use_color = "$Pakfire::color{'lightgreen'}";
 		}
 
+  		# Check for available core upgrade first if list of upgrades is requested
+		if ("$filter" eq "upgrade") {
+			my %coredb = &Pakfire::coredbinfo();
+
+			if (defined $coredb{'AvailableRelease'}) {
+				print "${use_color}Core-Update $coredb{'CoreVersion'}\n";
+				print "Release: $coredb{'Release'} -> $coredb{'AvailableRelease'}${reset_color}\n\n";
+			}
+		}
+
 		foreach $pak (sort keys %paklist) {
 			if ("$Pakfire::enable_colors" eq "1") {
 				if ("$paklist{$pak}{'Installed'}" eq "yes") {