lots of refactoring
[p5sagit/Promulger.git] / lib / App / Promulger / Command / newlist.pm
CommitLineData
514dce63 1package App::Promulger::Command::newlist;
2use strict;
3use warnings;
4
5use App::Promulger -command;
514dce63 6use Promulger::List;
514dce63 7use Config::General;
8
9sub abstract {
10 return "creates a new list";
11}
12
13sub opt_spec {
14 return (
15 [ "config|c=s", "configuration file", { required => 1 } ],
16 );
17}
18
19sub validate_args {
20 my ($self, $opt, $args) = @_;
21 my $cf = $opt->{config};
22
23 unless(-e $cf) {
24 die "Config file $cf doesn't exist\n";
25 }
26 unless(-f $cf) {
27 die "Config file $cf not a file\n";
28 }
29 unless(-r $cf) {
30 die "Config file $cf not readable\n";
31 }
32
33 $self->{config} = { Config::General->new($cf)->getall };
f5baca29 34 $self->{config}{config_file} = $cf;
514dce63 35}
36
f5baca29 37
514dce63 38sub run {
39 my ($self, $opt, $args) = @_;
f5baca29 40 @$args == 1 or die "pmg newlist needs a list name\n";
514dce63 41 my $list = Promulger::List->new(
42 listname => $args->[0],
43 );
f5baca29 44 $list->setup($self->{config});
514dce63 45}
46
471;