The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!perl

our $DATE = '2015-08-17'; # DATE
our $VERSION = '0.17'; # VERSION

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

my $cmd = Perinci::CmdLine::Classic->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.17 of trash-u (from Perl distribution File-Trash-Undoable), released on 2015-08-17.

=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>

{en_US Clear actions history}.

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

{en_US Select subcommand}.

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

{en_US Set path to configuration file}.

Can be specified multiple times.

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

{en_US Set configuration profile to use}.

=item B<--empty>

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

{en_US Pass options to formatter}.

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

{en_US Choose output format, e.g. json, text}.

Default value:

 undef

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

{en_US Display help message and exit}.

=item B<--history>

{en_US List actions history}.

=item B<--json>

{en_US Equivalent to --format=json-pretty}.

=item B<--list-contents>

=item B<--no-config>

{en_US Do not use any configuration file}.

=item B<--no-env>

{en_US Do not read environment for default options}.

=item B<--redo>

{en_US Redo previous undone action}.

=item B<--subcommands>

{en_US List available subcommands}.

=item B<--undo>

{en_US Undo previous action}.

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

{en_US Display program's version and exit}.

=back

=head2 Options for subcommand trash

=over

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

{en_US Files/dirs to delete} (JSON-encoded).

See C<--files>.

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

{en_US Files/dirs to delete} (YAML-encoded).

See C<--files>.

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

{en_US Files/dirs to delete}.

{en_US 
Files must exist.
}


Can be specified multiple times.

=back

=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 ENVIRONMENT

=head2 => str

Specify additional command-line options

=head1 CONFIGURATION FILE

This script can read configuration file, which by default is searched at C<~/.config/.conf>, C<~/.conf> or C</etc/.conf> (can be changed by specifying C<--config-path>). All found files will be read and merged.

To disable searching for configuration files, pass C<--no-config>.

Configuration file is in the format of L<IOD>, which is basically INI with some extra features. Section names map to subcommand names. 

You can put multiple profiles in a single file by using section names like C<[profile=SOMENAME]> or C<[SUBCOMMAND_NAME profile=SOMENAME]>. Those sections will only be read if you specify the matching C<--config-profile SOMENAME>.

List of available configuration parameters:

=head2 Common for all subcommands

 format (see --format)
 format_options (see --format-options)

=head2 For subcommand 'empty'


=head2 For subcommand 'list_contents'


=head2 For subcommand 'trash'

 files (see --files)

=head1 FILES

~/.config/.conf

~/.conf

/etc/.conf

=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/sharyanto/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) 2015 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