Can I offer new action? Non-interactive attach one file to entry.
It's quick cut-off of cli_attach
sub cli_attachfile {
my $self = shift @;
my $params = shift @;
our $state;
if (recent_sigint() || warn_if_file_changed()) {
return;
}
my $target = $params->{args}->[0];
my $ent=find_target_entry_by_number_or_path($target);
if (! defined($ent)) {
print no_entry_at_path_msg($target);
return -1;
}
my $tmp_ent = entry_as_hash($ent);
$state->{attach_changed} = 0;
my @strings_keys = ();
if (defined($tmp_ent->{binary}) && ref($tmp_ent->{binary}) eq 'HASH') {
@strings_keys = sort keys %{$tmp_ent->{binary}};
}
my $strings_count = scalar(@strings_keys);
if (deny_if_readonly(2)) { return; }
if ($strings_count > 0 && $state->{kdb_ver} == 1) {
print "\n" .color('yellow').
'KeePass v1 files support only one attachment per entry.' .
color('clear')."\n";
return;
}
my $filename = $params->{args}->[1];
if (! length($filename)) { return; }
print "File to attach is ".$filename."\n";
my $errmsg = do_attach_file($tmp_ent, $filename);
if (defined($errmsg)) {
print color('yellow'). "Error: $errmsg" .color('clear'). "\n";
}
if ($state->{attach_changed}) {
# Recycle the entry if changes were made unless --no-recycle
if (!(defined($opts->{'no-recycle'}) && int($opts->{'no-recycle'}))) {
my $errmsg = recycle_entry($state, $ent);
if (defined($errmsg)) { print "WARNING: $errmsg\n"; }
}
# Update the entry with the new binaries
my $changes = { binary => $tmp_ent->{binary} };
update_entry($state->{kdb}, $ent, $changes);
delete $state->{attach_changed}; # Delete our temporary state var
$state->{kdb_has_changed} = 1;
cli_save(undef);
}
return;
}
If you actually code this, please send a patch (unified diff) and/or a copy of your kpcli that you added it to and I will review and consider it.