source: bookmarks/trunk/bkmk @ 30

Last change on this file since 30 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
RevLine 
[2]1#!/usr/bin/perl -w
2use strict;
3
4use YAML;
5use Bookmarks;
[15]6use Getopt::Long;
[2]7
[15]8GetOptions(
9    'file|f=s' => \my $DBNAME,
[20]10    'tag=s' => \my @TAGS,
[15]11);
[2]12
[15]13die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME;
[2]14
15my $bookmarks = Bookmarks->new({
[15]16    dbname => $DBNAME,
[2]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    },
[14]34    list => sub {
[26]35        my @resources = $bookmarks->get_bookmarks({
[20]36            tag => \@TAGS
37        });
[14]38        # TODO: list by tags, date, etc.
39        # TODO: coordinate this commandline script with the CGI app
40        print Dump(\@resources);
[15]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    },
[2]49);
50
51$action_for{$command}->(@ARGV);
52
53=begin
54
55use YAML;
56
Note: See TracBrowser for help on using the repository browser.