lots of refactoring
[p5sagit/Promulger.git] / lib / App / Promulger / Command / newlist.pm
1 package App::Promulger::Command::newlist;
2 use strict;
3 use warnings;
4
5 use App::Promulger -command;
6 use Promulger::List;
7 use Config::General;
8
9 sub abstract {
10   return "creates a new list";
11 }
12
13 sub opt_spec {
14   return (
15     [ "config|c=s", "configuration file", { required => 1 } ],
16   );
17 }
18
19 sub 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 };
34   $self->{config}{config_file} = $cf;
35 }
36
37
38 sub run {
39   my ($self, $opt, $args) = @_;
40   @$args == 1 or die "pmg newlist needs a list name\n";
41   my $list = Promulger::List->new(
42     listname  => $args->[0],
43   );
44   $list->setup($self->{config});
45 }
46
47 1;