source: bookmarks/trunk/bkmk @ 74

Last change on this file since 74 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
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 = (
[47]22    init => sub {
23        $bookmarks->create_tables;
24    },
[2]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    },
[14]37    list => sub {
[26]38        my @resources = $bookmarks->get_bookmarks({
[20]39            tag => \@TAGS
40        });
[14]41        # TODO: list by tags, date, etc.
42        # TODO: coordinate this commandline script with the CGI app
43        print Dump(\@resources);
[15]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    },
[2]52);
53
54$action_for{$command}->(@ARGV);
55
56=begin
57
58use YAML;
59
Note: See TracBrowser for help on using the repository browser.