simple and stupid list creation. sets up aliases, creates the object, stores it.
[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::Schema;
7 use Promulger::List;
8
9 use Config::General;
10
11 sub abstract {
12   return "creates a new list";
13 }
14
15 sub opt_spec {
16   return (
17     [ "config|c=s", "configuration file", { required => 1 } ],
18   );
19 }
20
21 sub validate_args {
22   my ($self, $opt, $args) = @_;
23   my $cf = $opt->{config};
24
25   unless(-e $cf) {
26     die "Config file $cf doesn't exist\n";
27   }
28   unless(-f $cf) {
29     die "Config file $cf not a file\n";
30   }
31   unless(-r $cf) {
32     die "Config file $cf not readable\n";
33   }
34
35   $self->{config} = { Config::General->new($cf)->getall };
36   @$args == 1 or die "pmg newlist needs a list name\n";
37 }
38
39 sub run {
40   my ($self, $opt, $args) = @_;
41   Promulger::Schema->connect($self->{config}{store});
42   my $list = Promulger::List->new(
43     listname  => $args->[0],
44   );
45   $list->setup_aliases_at($self->{config});
46   Promulger::Schema->store($list);
47 }
48
49 1;