Last change
on this file since 26 was
26,
checked in by peter, 12 years ago
|
renamed Bookmarks::get_resources() to Bookmarks::get_bookmarks()
|
-
Property svn:executable set to
*
|
File size:
1.3 KB
|
Line | |
---|
1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | use YAML; |
---|
5 | use Bookmarks; |
---|
6 | use Getopt::Long; |
---|
7 | |
---|
8 | GetOptions( |
---|
9 | 'file|f=s' => \my $DBNAME, |
---|
10 | 'tag=s' => \my @TAGS, |
---|
11 | ); |
---|
12 | |
---|
13 | die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME; |
---|
14 | |
---|
15 | my $bookmarks = Bookmarks->new({ |
---|
16 | dbname => $DBNAME, |
---|
17 | }); |
---|
18 | |
---|
19 | my $command = shift; |
---|
20 | |
---|
21 | my %action_for = ( |
---|
22 | get => sub { |
---|
23 | my $identifier = shift; |
---|
24 | my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier }; |
---|
25 | my $bookmark = $bookmarks->get_bookmark($query); |
---|
26 | |
---|
27 | print $bookmark ? Dump($bookmark) : "Not Found\n"; |
---|
28 | }, |
---|
29 | add => sub { |
---|
30 | my ($uri, $title, @tags) = @_; |
---|
31 | my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags }); |
---|
32 | print Dump($bookmark); |
---|
33 | }, |
---|
34 | list => sub { |
---|
35 | my @resources = $bookmarks->get_bookmarks({ |
---|
36 | tag => \@TAGS |
---|
37 | }); |
---|
38 | # TODO: list by tags, date, etc. |
---|
39 | # TODO: coordinate this commandline script with the CGI app |
---|
40 | print Dump(\@resources); |
---|
41 | }, |
---|
42 | load => sub { |
---|
43 | my ($src_file) = @_; |
---|
44 | my $src_bookmarks = YAML::LoadFile($src_file); |
---|
45 | for my $bookmark (@{ $src_bookmarks }) { |
---|
46 | $bookmarks->add($bookmark); |
---|
47 | } |
---|
48 | }, |
---|
49 | ); |
---|
50 | |
---|
51 | $action_for{$command}->(@ARGV); |
---|
52 | |
---|
53 | =begin |
---|
54 | |
---|
55 | use YAML; |
---|
56 | |
---|
Note: See
TracBrowser
for help on using the repository browser.