package Common::DB::Deploy::CommandOption;

use strict;
use warnings;

use Getopt::Long qw(:config no_ignore_case);;
our $AUTOLOAD;

sub new {
    my ($class, %args) = @_;

    my $self = bless {
        'start|S'    => 0,
        'help|h'     => 0,
        'sync|s'     => 0,
        'dryrun|d'   => 0,
        'prodmode|p' => 0,
    }, $class;

    $self->_init;
    return $self;
}

sub _init {
    my $self = shift;

    GetOptions( $self, keys %$self );
    if ( !$self->{start} || $self->{help} ) {
        die $self->usage;
    }

    return 1;
}

sub AUTOLOAD {
    my $self = shift;

    my $method = $AUTOLOAD;
    $method =~ s/.*:://;

    return exists $self->{$method} ? $self->{$method} : 0;
}


sub usage {
    my $self = shift;

    return <<"EOT";
Usage: $0 <actions> [--dryrun]

ACTIONS:
    --start    | --S     Start process
    --help     | --h     Help

OPTIONS:
    --sync     | --s     Sync the changelog in the 'db_changelog' table only with no changes made
    --dryrun   | --d     Perform a trial run with no changes made
    --prodmode | --p     Production mode (otherwise the devmode will be applied)

NOTE:
    A set of options "--sync --dryrun" will create the 'db_changelog' table if it doesn't exist,
    without updating the changelog.

EOT
}


1;