#!perl

our $DATE = '2015-07-28'; # DATE
our $DIST = 'App-pause-Unpacked'; # DIST
our $VERSION = '0.44'; # VERSION

use 5.010001;
use strict;
use warnings;

require Perinci::CmdLine::pause;

our %SPEC;

$SPEC{':package'} = { v=>1.1 };

$ENV{DATA_SAH_CORE_OR_PP} = 1;

my $prefix = '/WWW/PAUSE/Simple/';

Perinci::CmdLine::pause->new(
    summary => 'A CLI for PAUSE',
    url => '/main/',
    extra_urls_for_version => [$prefix],
    subcommands => {
        upload     => { url => "${prefix}upload_files" },
        list       => { url => "${prefix}list_files" },
        ls         => {
            url => "${prefix}list_files",
            summary => 'Alias for list',
            is_alias => 1,
        },
        "list-dists" => { url => "${prefix}list_dists" },
        delete     => { url => "${prefix}delete_files" },
        rm         => {
            url => "${prefix}delete_files",
            summary => 'Alias for delete',
            is_alias => 1,
        },
        undelete   => { url => "${prefix}undelete_files" },
        reindex    => { url => "${prefix}reindex_files" },
        #password   => { url => "${prefix}set_password" },
        #'account-info' => { url => "${prefix}set_account_info" },
        cleanup    => { url => "${prefix}delete_old_releases" },
    },
    log => 1,
)->run;

# ABSTRACT: A CLI for PAUSE
# PODNAME: pause-unpacked

__END__

=pod

=encoding UTF-8

=head1 NAME

pause-unpacked - A CLI for PAUSE

=head1 VERSION

This document describes version 0.44 of pause-unpacked (from Perl distribution App-pause-Unpacked), released on 2015-07-28.

=head1 SYNOPSIS

First create a config file C<~/pause.conf> containing:

 username=<Your PAUSE ID>
 password=<Your PAUSE password>

or if you have C<~/.pause> from L<cpan-upload>, C<pause> can read it too
(encrypted C<.pause> is currently not supported).

Then:

 # upload one or more files
 % pause upload Foo-Bar-0.12.tar.gz Baz-2.24.tar.gz
 % pause upload Foo-Bar-0.12.tar.gz --subdir old/2014; # upload to a subdir

 # list your files
 % pause list
 % pause ls 'App-*'; # accept filenames/wildcard patterns, note: quote first
 % pause ls -l     ; # see file sizes/mtimes/etc instead of just names

 # delete files
 % pause delete Foo-Bar-0.12.tar.gz Foo-Bar-0.12.readme Foo-Bar-0.12.meta
 % pause rm 'Foo-Bar-*'; # accept wildcard patterns, but quote first

 # undelete files scheduled for deletion (but not actually deleted yet)
 % pause undelete Foo-Bar-0.12.tar.gz Foo-Bar-0.12.readme Foo-Bar-0.12.meta
 % pause undelete 'Foo-Bar-*'; # accept wildcard patterns, but quote first

 # force reindexing
 % pause reindex Foo-Bar-0.12.tar.gz Foo-Bar-0.12.meta
 % pause reindex 'Foo-Bar-*'; # accept wildcard patterns, but quote first

 # clean old releases, by default will only leave the newest non-dev version
 % pause cleanup
 % pause cleanup -n 3 ; # keep 3 versions (newest + previous two)

 # view permissions (not yet implemented)
 ...

 # change permissions (not yet implemented)
 ...

 # change your password (not yet implemented)
 ...

 # view your account info (not yet implemented)
 ...

 # change your email forwarding (not yet implemented)
 ...

=head1 SUBCOMMANDS

=head2 B<cleanup>

Delete older versions of distributions on your PAUSE account.

Developer releases will not be deleted.

To delete developer releases, you can use C<delete_files> (rm), e.g. from the
command line:

 % pause rm 'My-Module-*TRIAL*'; # delete a dist's trial releases
 % pause rm '*TRIAL*' '*_*'; # delete all files containing TRIAL or underscore


=head2 B<delete>

Delete files.

When a file is deleted, it is not immediately deleted but has
scheduled_for_deletion status for 72 hours, then deleted. During that time, the
file can be undeleted.


=head2 B<list>

List files on your PAUSE account.

=head2 B<list-dists>

List distributions on your PAUSE account.

Distribution names will be extracted from tarball/zip filenames.

Unknown/unparseable filenames will be skipped.


=head2 B<ls>

Alias for list.

=head2 B<reindex>

Force reindexing.

=head2 B<rm>

Alias for delete.

=head2 B<undelete>

Undelete files.

When a file is deleted, it is not immediately deleted but has
scheduled_for_deletion status for 72 hours, then deleted. During that time, the
file can be undeleted.


=head2 B<upload>

Upload file(s) to your PAUSE account.

=head1 OPTIONS

C<*> marks required options.

=head2 Common options

=over

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

Set path to configuration file.

Can be specified multiple times.

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

Set configuration profile to use.

=item B<--debug>

Set log level to debug.

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

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

Default value:

 undef

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

Display help message and exit.

=item B<--json>

Set output format to json.

=item B<--log-level>=I<s>

Set log level.

=item B<--naked-res>

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

    [200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
`--naked-res` so you just get:

    [1,2,3]


=item B<--no-config>

Do not use any configuration file.

=item B<--no-env>

Do not read environment for default options.

=item B<--password>=I<s>*

PAUSE password.

=item B<--quiet>

Set log level to quiet.

=item B<--subcommands>

List available subcommands.

=item B<--trace>

Set log level to trace.

=item B<--username>=I<s>*

PAUSE ID.

=item B<--verbose>

Set log level to info.

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

Display program's version and exit.

=back

=head2 Options for subcommand cleanup

=over

=item B<--detail>, B<-l>

Whether to return detailed records.

=item B<--num-keep>=I<i>, B<-n>

Number of new versions (including newest) to keep.

Default value:

 1

1 means to only keep the newest version, 2 means to keep the newest and the
second newest, and so on.


=back

=head2 Options for subcommand delete

=over

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

File name/wildcard pattern.

Can be specified multiple times.

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

File names/wildcard patterns (JSON-encoded).

See C<--file>.

=back

=head2 Options for subcommand list

=over

=item B<--del>

Only list files which are scheduled for deletion.

=item B<--detail>, B<-l>

Whether to return detailed records.

=item B<--file>=I<s@>

File name/wildcard pattern.

Can be specified multiple times.

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

File names/wildcard patterns (JSON-encoded).

See C<--file>.

=back

=head2 Options for subcommand list-dists

=over

=item B<--detail>, B<-l>

Whether to return detailed records.

=item B<--newest>

Only show newest non-dev version.

Dev versions will be skipped.


=item B<--newest-n>=I<i>

Only show this number of newest non-dev versions.

Dev versions will be skipped.


=back

=head2 Options for subcommand reindex

=over

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

File name/wildcard pattern.

Can be specified multiple times.

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

File names/wildcard patterns (JSON-encoded).

See C<--file>.

=back

=head2 Options for subcommand undelete

=over

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

File name/wildcard pattern.

Can be specified multiple times.

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

File names/wildcard patterns (JSON-encoded).

See C<--file>.

=back

=head2 Options for subcommand upload

=over

=item B<--delay>=I<i>

Pause a number of seconds between files.

If you upload a lot of files (e.g. 7-10 or more) at a time, the PAUSE indexer
currently might choke with SQLite database locking problem and thus fail to
index your releases. Giving a delay of say 2-3 minutes (120-180 seconds) between
files will alleviate this problem.


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

File name/wildcard pattern.

Can be specified multiple times.

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

File names/wildcard patterns (JSON-encoded).

See C<--file>.

=item B<--group-delay>=I<i>

Pause a number of seconds between groups of files.

As an alternative to the `delay` option, you can also use this option. This will
group the files to be uploaded by versions and prevent files of the same dist
and different versions to be uploaded too close to one another, as this might
cause indexing problem too. For example, suppose you're uploading Foo-1.zip
Foo-2.zip Foo-3.zip Bar-1.zip Baz-1.zip Baz-2.zip. The files will be uploaded in
this order:

    upload: Foo-1.zip Bar-1.zip Baz-1.zip
    group delay
    upload: Foo-2.zip Baz-2.zip
    group delay
    upload: Foo-3.zip

As with the `delay` option, it is recommended that if you upload several files
at once, you set this option to 2-3 minutes (120-180 seconds).


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

Subdirectory to put the file(s) into.

Default value:

 ""

=back

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

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 pause-unpacked 'p/*/`pause-unpacked`/'

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

Specify additional command-line options

=head1 CONFIGURATION FILE

This script can read configuration file, which by default is searched at C<~/.config/pause-unpacked.conf>, C<~/pause-unpacked.conf> or C</etc/pause-unpacked.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)
 log_level (see --log-level)
 naked_res (see --naked-res)
 password (see --password)
 username (see --username)

=head2 For subcommand 'cleanup'

 detail (see --detail)
 num_keep (see --num-keep)

=head2 For subcommand 'delete'

 files (see --file)

=head2 For subcommand 'list'

 del (see --del)
 detail (see --detail)
 files (see --file)

=head2 For subcommand 'list-dists'

 detail (see --detail)
 newest (see --newest)
 newest_n (see --newest-n)

=head2 For subcommand 'reindex'

 files (see --file)

=head2 For subcommand 'undelete'

 files (see --file)

=head2 For subcommand 'upload'

 delay (see --delay)
 files (see --file)
 group_delay (see --group-delay)
 subdir (see --subdir)

=head1 FILES

~/.pause

~/.config/pause-unpacked.conf

~/pause-unpacked.conf

/etc/pause-unpacked.conf

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-pause-Unpacked>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-pause-Unpacked>.

=head1 BUGS

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

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
