source: bookmarks/trunk/bkmk @ 53

Last change on this file since 53 was 47, checked in by peter, 11 years ago
  • added a create_tables method to Bookmarks that uses the bookmarks.sql file to create the tables
  • added an "init" command to the bkmk script
  • 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    init => sub {
23        $bookmarks->create_tables;
24    },
25    get => sub {
26        my $identifier = shift;
27        my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier };
28        my $bookmark = $bookmarks->get_bookmark($query);
29
30        print $bookmark ? Dump($bookmark) : "Not Found\n";
31    },
32    add => sub {
33        my ($uri, $title, @tags) = @_;
34        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags });
35        print Dump($bookmark);
36    },
37    list => sub {
38        my @resources = $bookmarks->get_bookmarks({
39            tag => \@TAGS
40        });
41        # TODO: list by tags, date, etc.
42        # TODO: coordinate this commandline script with the CGI app
43        print Dump(\@resources);
44    },
45    load => sub {
46        my ($src_file) = @_;
47        my $src_bookmarks = YAML::LoadFile($src_file);
48        for my $bookmark (@{ $src_bookmarks }) {
49            $bookmarks->add($bookmark);
50        }
51    },
52);
53
54$action_for{$command}->(@ARGV);
55
56=begin
57
58use YAML;
59
Note: See TracBrowser for help on using the repository browser.