Changeset 85 in bookmarks for trunk/bkmk


Ignore:
Timestamp:
06/04/15 00:54:06 (9 years ago)
Author:
peter
Message:

issue #9: enhanced command line tool

  • added action tag to set the tag list for a bookmark
  • fixed the list query to actually query by tags
  • changed the output to just display the YAML of the public bookmark properties
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bkmk

    r83 r85  
    3131    get => sub { 
    3232        my $identifier = shift; 
    33         my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier }; 
    34         my $bookmark = $bookmarks->get_bookmark($query); 
    35  
    36         print $bookmark ? Dump($bookmark) : "Not Found\n"; 
     33        my $bookmark = find_bookmark($identifier); 
     34        print $bookmark ? Dump($bookmark->TO_JSON) : "Not Found\n"; 
    3735    }, 
    3836     
     
    4139        my $title = defined $TITLE ? $TITLE : fetch_title($uri); 
    4240        my $bookmark = $bookmarks->add({ uri => $uri, title => $title, tags => \@tags }); 
    43         print Dump($bookmark); 
     41        print Dump($bookmark->TO_JSON); 
    4442    }, 
    4543 
    4644    list => sub { 
    4745        my @tags = @_; 
    48         my @resources = $bookmarks->get_bookmarks({ 
    49             tag => \@tags 
     46        my $resources = $bookmarks->get_bookmarks({ 
     47            tags => \@tags 
    5048        }); 
    5149        # TODO: list by tags, date, etc. 
    5250        # TODO: coordinate this commandline script with the CGI app 
    53         print Dump(\@resources); 
     51        print Dump([ map { $_->TO_JSON } @{ $resources->results } ]); 
    5452    }, 
     53 
     54    tag => sub { 
     55        my ($identifier, @tags) = @_; 
     56        my $bookmark = find_bookmark($identifier); 
     57        if ($bookmark) { 
     58            $bookmark->tags(\@tags); 
     59            $bookmarks->update($bookmark); 
     60            print Dump($bookmark->TO_JSON); 
     61        } else { 
     62            die "Not found\n"; 
     63        } 
     64    }, 
     65 
     66    #TODO: interactive editing of a bookmark 
    5567 
    5668    # bulk loading 
     
    6678$action_for{$command}->(@ARGV); 
    6779 
     80sub find_bookmark { 
     81    my $identifier = shift; 
     82    my $query = $identifier =~ /^\d+$/ ? { id => $identifier } : { uri => $identifier }; 
     83    return $bookmarks->get_bookmark($query); 
     84} 
     85 
    6886sub fetch_title { 
    6987    my $uri = shift; 
Note: See TracChangeset for help on using the changeset viewer.