| 1 | package Test::mysqld::DatadirDumper::CLI; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use Getopt::Long; | ||
| 6 | use Test::mysqld::DatadirDumper; | ||
| 7 | |||
| 8 | sub run { | ||
| 9 | my ($class, @argv) = @_; | ||
| 10 | |||
| 11 | my ($opt,) = $class->parse_options(@argv); | ||
| 12 | Test::mysqld::DatadirDumper->new($opt)->dump; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub parse_options { | ||
| 16 | my ($class, @argv) = @_; | ||
| 17 | |||
| 18 | my $parser = Getopt::Long::Parser->new( | ||
| 19 | config => [qw/posix_default no_ignore_case/], | ||
| 20 | ); | ||
| 21 | local @ARGV = @argv; | ||
| 22 | $parser->getoptions(\my %opt, qw/ | ||
| 23 | ddl=s | ||
| 24 | datadir=s | ||
| 25 | fixtures=s@ | ||
| 26 | /); | ||
| 27 | for my $opt (qw/ddl datadir/) { | ||
| 28 | die "$opt option is required!" unless exists $opt{$opt}; | ||
| 29 | } | ||
| 30 | |||
| 31 | if (exists $opt{fixtures}) { | ||
| 32 | $opt{fixtures} = [ | ||
| 33 | map { split /,/, $_ } @{ $opt{fixtures} } | ||
| 34 | ]; | ||
| 35 | } | ||
| 36 | $opt{ddl_file} = delete $opt{ddl}; | ||
| 37 | |||
| 38 | (\%opt, \@ARGV); | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; |