#!perl

#
# (c) Jan Gehring <jan.gehring@gmail.com>
#
# vim: set ts=3 sw=3 tw=0:
# vim: set expandtab:

use strict;
use warnings;

our $VERSION = '1.11.0.4'; # TRIAL VERSION

BEGIN {
  # this is for new package format
  if ( -d '/usr/lib/rex/lib' ) {
    use lib '/usr/lib/rex/lib';
  }
}

use Rex::CLI;

my $rex = Rex::CLI->new;
$rex->__run__;

__END__

=pod

=head1 NAME

Rex - the friendly automation framework

=head1 DESCRIPTION

Rex is an automation framework that is friendly to any combinations of local
and remote execution, push and pull style of management, or imperative and
declarative approach.

Its flexibility makes it a great fit for many different use cases, but most
commonly Rex is used to automate application deployment and data center
infrastructure management tasks.

=head1 SYNOPSIS

    bash# rex -h                      # Show usage
    bash# rex -T                      # List tasks
    bash# rex uname                   # Run the 'uname' task
    bash# rex -H server[01..10] uname # Run the 'uname' task on all the specified hosts
    bash# rex -G production uname     # Run 'uname' on hosts on the 'production' hostgroup
    bash# rex deploy --gracefully     # Pass '--gracefully' to the 'deploy' task

=head1 USAGE

    rex [<options>] [-H <host>] [-G <group>] <task> [<task-options>]
    rex -T[m|y|v] [<string>]

    -b     Run batch
    -e     Run the given code fragment
    -E     Execute a task on the given environment
    -G|-g  Execute a task on the given server groups
    -H     Execute a task on the given hosts (space delimited)
    -z     Execute a task on hosts from this command's output
  
    -K     Public key file for the ssh connection
    -P     Private key file for the ssh connection
    -p     Password for the ssh connection
    -u     Username for the ssh connection
  
    -d     Show debug output
    -ddd   Show more debug output (includes profiling output)
    -m     Monochrome output: no colors
    -o     Output format
    -q     Quiet mode: no log output
    -qw    Quiet mode: only output warnings and errors
    -Q     Really quiet: output nothing
  
    -T     List tasks
    -Ta    List all tasks, including hidden
    -Tm    List tasks in machine-readable format
    -Tv    List tasks verbosely
    -Ty    List tasks in YAML format
  
    -c     Turn cache ON
    -C     Turn cache OFF
    -f     Use this file instead of Rexfile
    -F     Force: disregard lock file
    -h     Display this help message
    -M     Load this module instead of Rexfile
    -O     Pass additional options, like CMDB path
    -s     Use sudo for every command
    -S     Password for sudo
    -t     Number of threads to use (aka 'parallelism' param)
    -v     Display (R)?ex version

=head1 Rexfile

When you run C<rex> it reads the file C<Rexfile> in the current working
directory. A Rexfile consists of 2 major parts: Configuration and Task
Definitions.

=head2 Configuration

=head3 Simple Authentication

    user "bruce";
    password "batman";
    pass_auth;

=head3 Key Authentication

    private_key "/path/to/your/private/key.file";
    public_key "/path/to/your/public/key.file";

=head3 Define Logging

    logging to_file => "rex.log";
    logging to_syslog => "local0";

=head3 Group your servers

Rex gives you the ability to define groups of servers. Groups can be defined the Rexfile:

    group "frontends" => "frontend01", "frontend02", "frontend03", "frontend04", "frontend[05..09]";

Groups can also be defined in a B<server.ini> file:

    [frontends]
    frontend[01..04]

=head2 Other Configuration

    timeout 10;    # ssh timeout
    parallelism 2; # execute tasks in parallel

=head2 Defining tasks

A basic task looks like this:

    # task description
    desc "This task tells you how long since the server was rebooted";
   
    # task definition
    task "shortname", sub {
        say run "uptime";
    };

You can also set a default server group:

    desc "This is a long description of a task";
    task "shortname", group => "frontends", sub {
        say run "uptime";
    };

=head1 TAB COMPLETION

Tab completion scripts are provided for Bash and Zsh in the L<share|https://metacpan.org/release/Rex/source/share> directory. They provide completions for the available CLI options, hosts, groups, environments and tasks.

=cut
