Even more work in the 'gruta' script.
[gruta.git] / bin / gruta
blob173a1e8346f2047701043be4a75a82d04c737950
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use Gruta;
7 use Gruta::Source::DBI;
8 use Gruta::Source::FS;
10 my $usage = 0;
12 my $g;
13 my $src;
14 my $cmd;
15 my $src_str;
17 $cmd = shift(@ARGV) or usage();
18 $src_str = shift(@ARGV) or usage();
20 $src = new_source($src_str);
21 $g = Gruta->new( sources => $src );
23 if ($cmd eq 'copy') {
24 my $new_src = shift(@ARGV) or usage();
25 my $dst = new_source( $new_src );
27 $dst->create();
29 $g->transfer_to_source( $dst );
31 elsif ($cmd eq 'topics') {
32 foreach my $t ($g->topics()) {
33 print $t, "\n";
36 elsif ($cmd eq 'topic') {
37 my $topic_id = shift(@ARGV) or usage();
39 my $topic = $g->topic($topic_id);
41 foreach my $f ($topic->afields()) {
42 print $f, ': ', ($topic->get($f) || 'UNDEF'), "\n";
45 elsif ($cmd eq 'edit_story') {
46 my $topic = shift(@ARGV) or usage();
47 my $id = shift(@ARGV) or usage();
49 my $story = $g->story($topic, $id);
51 else {
52 usage();
55 exit 0;
58 sub usage
60 print "Usage: $0 {cmd} {source}\n";
61 exit 1;
64 sub new_source
66 my $src_str = shift;
67 my $src;
69 if ($src_str =~ /^dbi:/) {
70 $src = Gruta::Source::DBI->new( string => $src_str );
72 else {
73 $src = Gruta::Source::FS->new( path => $src_str );
76 return $src;