Changeset 83 in bookmarks


Ignore:
Timestamp:
06/03/15 20:21:19 (7 years ago)
Author:
peter
Message:

issue #9: minor improvements to the bkmk script

  • loads the Bookmarks library correctly
  • tags are given as positional arguments on the command line instead of switches
  • the db filename defaults to the value of the environment variable $BKMK_DBNAME
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bkmk

    r47 r83  
    22use strict; 
    33 
     4use FindBin; 
     5use lib "$FindBin::RealBin/lib"; 
     6 
    47use YAML; 
     8use Getopt::Long; 
     9 
    510use Bookmarks; 
    6 use Getopt::Long; 
    711 
    812GetOptions( 
    913    'file|f=s' => \my $DBNAME, 
    10     'tag=s' => \my @TAGS, 
     14    'title=s' => \my $TITLE, 
    1115); 
    1216 
    13 die "Usage: $0 --file <dbname> <command>\n" unless $DBNAME; 
     17my $dbname = $DBNAME || $ENV{BKMK_DBNAME}; 
     18die "Usage: $0 --file <dbname> <command>\n" unless $dbname; 
    1419 
    1520my $bookmarks = Bookmarks->new({ 
    16     dbname => $DBNAME, 
     21    dbname => $dbname, 
    1722}); 
    1823 
     
    2328        $bookmarks->create_tables; 
    2429    }, 
     30     
    2531    get => sub { 
    2632        my $identifier = shift; 
     
    3036        print $bookmark ? Dump($bookmark) : "Not Found\n"; 
    3137    }, 
     38     
    3239    add => sub { 
    33         my ($uri, $title, @tags) = @_; 
     40        my ($uri, @tags) = @_; 
     41        my $title = defined $TITLE ? $TITLE : fetch_title($uri); 
    3442        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags }); 
    3543        print Dump($bookmark); 
    3644    }, 
     45 
    3746    list => sub { 
     47        my @tags = @_; 
    3848        my @resources = $bookmarks->get_bookmarks({ 
    39             tag => \@TAGS 
     49            tag => \@tags 
    4050        }); 
    4151        # TODO: list by tags, date, etc. 
     
    4353        print Dump(\@resources); 
    4454    }, 
     55 
     56    # bulk loading 
    4557    load => sub { 
    4658        my ($src_file) = @_; 
     
    5466$action_for{$command}->(@ARGV); 
    5567 
    56 =begin 
    57  
    58 use YAML; 
    59  
     68sub fetch_title { 
     69    my $uri = shift; 
     70    require WWW::Mechanize; 
     71    my $mech = WWW::Mechanize->new; 
     72    $mech->get($uri); 
     73    return $mech->title || $uri; 
     74} 
Note: See TracChangeset for help on using the changeset viewer.