#!/usr/bin/env perl
# ABSTRACT: Run Statocles commands
package statocles;
our $VERSION = '0.096';

use Statocles::Base;
use Encode qw( decode );
use Encode::Locale;
use open qw( :std :locale );
use POSIX qw( setlocale LC_ALL );

# Mojolicious::Commands currently calls GetOptions and clobbers a few of
# our command-line options. Since I don't want to rely on the envvars
# that get set in that process, we'll do this little dance here.
#
# This happens because we build a Mojolicious app inside the Statocles::Command
# module, which loads Mojolicious, which loads Mojolicious::Commands, which
# calls GetOptions on @ARGV
my @argv;
BEGIN { @argv = map { decode( locale => $_ ) } @ARGV };

binmode STDIN, ":encoding(locale)";
binmode STDOUT, ":encoding(locale)";
binmode STDERR, ":encoding(locale)";

use Statocles;
exit Statocles->run( @argv );

__END__

=pod

=encoding UTF-8

=head1 NAME

statocles - Run Statocles commands

=head1 VERSION

version 0.096

=head1 SYNOPSIS

    statocles [-v] [--config <file>] [--site <site>] <command>
    statocles -h|--help
    statocles -v|--version

=head1 DESCRIPTION

The Statocles command-line interface. This command manages Statocles
sites: building, testing, and deploying.

This command also helps to manage content in Statocles apps.

=head1 ARGUMENTS

=head2 <command>

The command to run. Available commands:

    create <url>                    - Create a new site
    build [--date YYYY-MM-DD]       - Build the site
    daemon [-p <port>] [--date]     - Run an HTTP daemon to test the site
    deploy [--clean] [--date]       - Deploy the site
    bundle theme <name> [<file>...] - Bundle a theme
    apps                            - List the applications in this site
    <app> help                      - Get help for a specific application

=head1 OPTIONS

=head2 config <file>

The configuration file to read for Sites. Defaults to C<site.yml>.

The configuration file is a L<Beam::Wire> container file.

=head2 site <name>

The site to use, which is the name of an object in the config file. Defaults to
C<site>.

=head2 -p <port>

When running the daemon, choose which port to listen on. Defaults to C<3000>.

=head2 --date <date>

When running C<build>, C<deploy>, and C<daemon>, set the current date for
applications. This forces, for example, the L<blog app|Statocles::App::Blog>
to show entries in the future.

Date should be in C<YYYY-MM-DD> format.

=head2 --clean

When running C<deploy>, delete the current site content before deploying. By
default, old build files may be kept around after their source file is deleted.
The C<--clean> option removes all the files, so the site only contains what
was built.

=head2 -v | --verbose

Display diagnostic information:

=head2 -h | --help

Display this help file

=head2 --version

Display version information

=head1 AUTHOR

Doug Bell <preaction@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Doug Bell.

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