| 1 | package AproJo::Command::config; | ||
| 2 | use Mojo::Base 'Mojolicious::Command'; | ||
| 3 | |||
| 4 | use Data::Dumper; | ||
| 5 | use Term::Prompt qw/prompt/; | ||
| 6 | use Getopt::Long; | ||
| 7 | |||
| 8 | has description => | ||
| 9 | "Write an optional configuration file for your AproJo application.\n"; | ||
| 10 | has usage => "usage: $0 config\n"; | ||
| 11 | |||
| 12 | sub run { | ||
| 13 | |||
| 14 | my $self = shift; | ||
| 15 | local @ARGV = @_; | ||
| 16 | |||
| 17 | my $force = 0; | ||
| 18 | GetOptions("force" => \$force); | ||
| 19 | |||
| 20 | my $file = $self->app->config_file; | ||
| 21 | |||
| 22 | if (-e $file and not $force) { | ||
| 23 | die "Configuration file $file exists, use '--force' to proceed anyway.\n"; | ||
| 24 | } | ||
| 25 | |||
| 26 | my $config = $self->app->config; | ||
| 27 | local $config->{secret} = prompt('x', 'Application Secret: ', '', ''); | ||
| 28 | |||
| 29 | open my $fh, '>', $file | ||
| 30 | or die "Could not open file $file for writing: $!\n"; | ||
| 31 | |||
| 32 | local $Data::Dumper::Terse = 1; | ||
| 33 | local $Data::Dumper::Sortkeys = 1; | ||
| 34 | |||
| 35 | print $fh Dumper $config | ||
| 36 | or die "Write to $file failed\n"; | ||
| 37 | |||
| 38 | print "Configuration file $file written sucessfully\n"; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 |