#!perl

our $DATE = '2014-12-19'; # DATE
our $VERSION = '0.15'; # VERSION

use 5.010;
use strict;
use warnings;
use Perinci::CmdLine;

my $cmd = Perinci::CmdLine->new(
    url => '/File/Trash/Undoable/',
    subcommands => {
        trash         => {
            url  => '/File/Trash/Undoable/trash_files',
        },
        list_contents => {
            url  => '/File/Trash/Undoable/list_trash_contents',
            undo => 0,
        },
        empty         => {
            url  => '/File/Trash/Undoable/empty_trash',
            pass_cmdline_object => 1,
            undo => 0,
        },
    },
    default_subcommand => 'trash',
    undo => 1,
);

delete $cmd->common_opts->{list};

$cmd->common_opts->{empty} = {
    getopt  => 'empty',
    handler => sub {
        my ($go, $val, $r) = @_;
        $r->{subcommand_name} = 'empty';
        $r->{subcommand_name_from} = '--cmd'; # XXX not exactly accurate
        $r->{skip_parse_subcommand_argv} = 1;
    },
};

$cmd->common_opts->{list_contents} = {
    getopt  => 'list-contents',
    handler => sub {
        my ($go, $val, $r) = @_;
        $r->{subcommand_name} = 'list_contents';
        $r->{subcommand_name_from} = '--cmd'; # XXX not exactly accurate
        $r->{skip_parse_subcommand_argv} = 1;
    },
};

$cmd->run;

1;
# ABSTRACT: Trash files, with undo/redo capability
# PODNAME: trash-u

__END__

=pod

=encoding UTF-8

=head1 NAME

trash-u - Trash files, with undo/redo capability

=head1 VERSION

This document describes version 0.15 of trash-u (from Perl distribution File-Trash-Undoable), released on 2014-12-19.

=head1 SYNOPSIS

 # trash some files, but in simulation mode, not really trashing the files
 % VERBOSE=1 trash-u --dry-run *.bak

 # trash some files, for real
 % trash-u *.bak

 # list trash contents
 % trash-u --list-contents

 # trash some more files
 % trash-u * .tmp

 # oops, made a mistake; no worry, let's undo; now previous trashing is reversed
 % trash-u --undo

 # undo again; now the *.bak files are also restored
 % trash-u --undo

 # redo; now the *.bak files are trashed again
 % trash-u --redo

 # show history
 % trash-u --history

 # forget history; past actions can no longer be undone/redone
 % trash-u --clear-history

 # empty trash; this action is not undoable (the point is to reclaim space)
 % trash-u --empty

 # display help for more options
 % trash-u --help

=head1 DESCRIPTION

This command-line program is an interface to L<File::Trash::Undoable>, which in
turn uses L<File::Trash::FreeDesktop>.

Features: undo/redo, dry run mode, per-filesystem trash dir.

This program is relatively new and have not yet been tested extensively. Use
with caution.

=head1 SUBCOMMANDS

=head2 B<empty>

Empty trash.

=head2 B<list_contents>

List contents of trash directory.

=head2 B<trash>

Trash files (with undo support).

=head1 OPTIONS

C<*> marks required options.

=head2 Common options

=over

=item B<--clear-history>

Clear actions history.

=item B<--cmd>=I<s>

Select subcommand.

=item B<--config-path>=I<s>

Set path to configuration file.

Can be specified multiple times.

=item B<--config-profile>=I<s>

Set configuration profile to use.

=item B<--empty>

=item B<--format-options>=I<s>

Pass options to formatter.

=item B<--format>=I<s>

Choose output format, e.g. json, text.

=item B<--help>, B<-h>, B<-?>

Display this help message.

=item B<--history>

List actions history.

=item B<--list-contents>

=item B<--no-config>

Do not use any configuration file.

=item B<--redo>

Redo previous undone action.

=item B<--subcommands>

List available subcommands.

=item B<--undo>

Undo previous action.

=item B<--version>, B<-v>

=back

=head2 Options for subcommand empty

=over

=back

=head2 Options for subcommand list_contents

=over

=back

=head2 Options for subcommand trash

=over

=item B<--files-json>=I<s>

Files/dirs to delete (JSON-encoded).

See C<--files>.

=item B<--files-yaml>=I<s>

Files/dirs to delete (YAML-encoded).

See C<--files>.

=item B<--files>=I<s@>*

Files/dirs to delete.

Files must exist.


Can be specified multiple times.

=back

=head1 FILES

B</etc/trash-u.conf>

B<~/trash-u.conf>

=head1 USING AS rm REPLACEMENT

B<trash-u> can be used as B<rm> replacement (a.k.a. alias) with some caveats:

=over 4

=item * trash-u deletes directories by default

That is, it behaves as if -R rm option is in effect.

=item * Some rm options exist but do not have any effect (noop)

=item * Some rm options are still missing/unknown

This include: C<-i>/C<-I>/C<--interactive>, C<--one-file-system>,
C<--no-preserve-root>.

=back

=head1 SEE ALSO

L<File::Trash::Undoable>

L<File::Trash::FreeDesktop>

B<trash-cli>

B<gvfs-trash>

B<rmv>

=head1 COMPLETION

This script has shell tab completion capability with support for several shells.

=head2 bash

To activate bash completion for this script, put:

 complete -C trash-u trash-u

in your bash startup (e.g. C<~/.bashrc>). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is recommended, however, that you install L<shcompgen> which allows you to activate completion scripts for several kinds of scripts on multiple shells. Some CPAN distributions (those that are built with L<Dist::Zilla::Plugin::GenShellCompletion>) will even automatically enable shell completion for their included scripts (using C<shcompgen>) at installation time, so you can immadiately have tab completion.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete trash-u 'p/*/`trash-u`/'

in your tcsh startup (e.g. C<~/.tcshrc>). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.

It is also recommended to install C<shcompgen> (see above).

=head2 other shells

For fish and zsh, install C<shcompgen> as described above.

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/File-Trash-Undoable>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-File-Trash-Undoable>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=File-Trash-Undoable>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
