App-Raps2

 view release on metacpan or  search on metacpan

bin/raps2  view on Meta::CPAN


our $VERSION = '0.54';

GetOptions(
	'c|cost=i'      => \$default_cost,
	'C|chrome'      => \$chrome,
	'E|no-echo'     => \$no_echo,
	'h|help'        => sub { cmd_help(0) },
	'p|pwgen-cmd=s' => \$pwgen_cmd,
	'P|paste'       => \$paste,
	'V|version'     => sub { say "raps2 version ${VERSION}"; exit 0 },
	'x|xclip-cmd=s' => \$xclip_cmd,

) or cmd_help(1);

if ($chrome) {
	$xclip_cmd = 'xclip -l 2';
}

my ( $action, @args ) = @ARGV;
my $raps2 = App::Raps2->new(
	cost      => $default_cost,
	pwgen_cmd => $pwgen_cmd,
	xclip_cmd => $xclip_cmd,
);

sub file_must_exist {
	my ( $file, $name ) = @_;

	if ( not defined $file ) {
		say STDERR "No such account: ${name}";
		exit 2;
	}

	return;
}

sub file_must_not_exist {
	my ( $file, $name ) = @_;

	if ( -e $file ) {
		say STDERR "Account already exists: ${name}";
		exit 2;
	}

	return;
}

sub cmd_add {
	my ($name) = @_;

	if ( not $name ) {

bin/raps2  view on Meta::CPAN


	my $url   = $raps2->ui->read_line('URL');
	my $login = $raps2->ui->read_line('Login');
	my $pass  = $raps2->ui->read_pw( 'Password', 1 );
	my $extra = $raps2->ui->read_multiline('Additional content');

	if ( length($pass) == 0 ) {
		$pass = $raps2->generate_password();

		if ( not $pass ) {
			say STDERR "Password generation failed: ${!}: "
			  . $raps2->conf('pwgen_cmd');
			exit 3;
		}

		if ($paste) {
			$raps2->ui->to_clipboard( $pass, $raps2->conf('xclip_cmd') );
		}
		elsif ( not $no_echo ) {
			$raps2->ui->output( [ 'Generated password', $pass ] );
		}

bin/raps2  view on Meta::CPAN

	}

	return;
}

sub cmd_help {
	my ( $exit_status, $subcmd ) = @_;

	$subcmd //= 'add|get|dump|... [account]';

	say "Usage: raps2 ${subcmd}";
	say 'See also: "man raps2"';

	exit $exit_status;
}

sub cmd_info {
	my ($name) = @_;

	if ( not $name ) {
		cmd_help( 1, 'info <account>' );
	}

lib/App/Raps2/UI.pm  view on Meta::CPAN

	my $input = $self->{term_readline}->readline( "${str}: ", $pre );

	return $input;
}

sub read_multiline {
	my ( $self, $str ) = @_;

	my $in;

	say "${str} (^D or empty line to quit)";

	while ( my $line = $self->read_line('multiline') ) {
		$in .= "${line}\n";
	}

	return $in;
}

sub read_pw {
	my ( $self, $str, $verify ) = @_;



( run in 1.418 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )