From 4149a04c9857873553b2b39feaa84181c2320813 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 13 May 2011 12:32:28 +0200 Subject: Add raps2 list --- bin/raps2 | 1 + lib/App/Raps2.pm | 21 ++++++++++++++++++++- lib/App/Raps2/UI.pm | 11 +++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/bin/raps2 b/bin/raps2 index 2763500..0329e59 100755 --- a/bin/raps2 +++ b/bin/raps2 @@ -22,6 +22,7 @@ given ($action) { when ('dump') { $raps2->cmd_dump(@args) } when ('get') { $raps2->cmd_get(@args) } when ('info') { $raps2->cmd_info(@args) } + when ('list') { $raps2->cmd_list(@args) } when ('version') { say "raps2 version ${VERSION}" } } diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm index f05f21e..6b4929c 100644 --- a/lib/App/Raps2.pm +++ b/lib/App/Raps2.pm @@ -40,7 +40,7 @@ use App::Raps2::UI; use Carp q(confess); use File::BaseDir qw(config_home data_home); use File::Path qw(make_path); -use File::Slurp qw(slurp write_file); +use File::Slurp qw(read_dir slurp write_file); our @EXPORT_OK = (); our $VERSION = '0.1'; @@ -327,3 +327,22 @@ sub cmd_info { ['Login', $key{'login'}], ); } + +=head2 ->cmd_list() + +Lists all saved passwords and their logins and urls + +=cut + +sub cmd_list { + my ($self) = @_; + + for my $file (read_dir($self->{xdg_data})) { + my %key = file_to_hash($self->{xdg_data} . "/${file}"); + $self->ui->list( + ['Account', $file], + ['Login', $key{login}], + ['URL', $key{url}], + ); + } +} diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm index 82b2acd..29e8ef1 100644 --- a/lib/App/Raps2/UI.pm +++ b/lib/App/Raps2/UI.pm @@ -19,6 +19,17 @@ sub new { return bless($ref, $obj); } +sub list { + my ($self, @list) = @_; + my $format = "%-20s %-20s %s\n"; + + if (not $self->{list}->{header}) { + printf($format, map { $_->[0] } @list); + $self->{list}->{header} = 1; + } + printf($format, map { $_->[1] // q{} } @list); +} + sub read_line { my ($self, $str) = @_; -- cgit v1.2.3