| 1 | package JiftyX::Fixtures::Script::Init; | ||
| 2 | our $VERSION = '0.07'; | ||
| 3 | |||
| 4 | # ABSTRACT: init subcommand | ||
| 5 | |||
| 6 | use warnings; | ||
| 7 | use strict; | ||
| 8 | |||
| 9 | use Jifty; | ||
| 10 | use Jifty::Everything; | ||
| 11 | |||
| 12 | use IO::File; | ||
| 13 | use File::Basename; | ||
| 14 | use File::Spec; | ||
| 15 | use YAML qw(Dump LoadFile); | ||
| 16 | |||
| 17 | use base qw( | ||
| 18 | App::CLI::Command | ||
| 19 | ); | ||
| 20 | |||
| 21 | my $super = 'JiftyX::Fixtures::Script'; | ||
| 22 | |||
| 23 | our $help_msg = qq{ | ||
| 24 | Usage: | ||
| 25 | |||
| 26 | jiftyx-fixtures init [options] | ||
| 27 | |||
| 28 | Options: | ||
| 29 | |||
| 30 | -h, --help: show help | ||
| 31 | |||
| 32 | }; | ||
| 33 | |||
| 34 | my $prototype = qq{ | ||
| 35 | development: | ||
| 36 | dir: "etc/fixtures/development" | ||
| 37 | format: "yml" | ||
| 38 | greeking: "false" | ||
| 39 | |||
| 40 | test: | ||
| 41 | dir: "etc/fixtures/test" | ||
| 42 | format: "yml" | ||
| 43 | greeking: "false" | ||
| 44 | |||
| 45 | }; | ||
| 46 | |||
| 47 | sub options { | ||
| 48 | my ($self) = @_; | ||
| 49 | return ( | ||
| 50 | $super->options, | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | sub before_run { | ||
| 55 | my ($self) = @_; | ||
| 56 | |||
| 57 | $super->before_run($self); | ||
| 58 | |||
| 59 | return; | ||
| 60 | } | ||
| 61 | |||
| 62 | sub run { | ||
| 63 | my ($self) = @_; | ||
| 64 | $self->before_run(); | ||
| 65 | |||
| 66 | unless ($self->{config}->{fixtures}) { | ||
| 67 | |||
| 68 | my $fixtures_config = IO::File->new; | ||
| 69 | if ($fixtures_config->open("> " . $self->{config}->{app_root} . "/etc/fixtures.yml")) { | ||
| 70 | print $fixtures_config $prototype; | ||
| 71 | } | ||
| 72 | |||
| 73 | mkdir $self->{config}->{app_root} . "/etc/fixtures"; | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | 1; | ||
| 78 | |||
| 79 | __END__ |