source: bookmarks/trunk/bkmk @ 35

Last change on this file since 35 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
2use strict;
3
4use YAML;
5use Bookmarks;
6use Getopt::Long;
7
8GetOptions(
9    'file|f=s' => \my $DBNAME,
10    'tag=s' => \my @TAGS,
11);
12
13die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME;
14
15my $bookmarks = Bookmarks->new({
16    dbname => $DBNAME,
17});
18
19my $command = shift;
20
21my %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
55use YAML;
56
Note: See TracBrowser for help on using the repository browser.