]> git.cworth.org Git - sup/blobdiff - bin/sup-add
Merge branch 'locking-refactor'
[sup] / bin / sup-add
old mode 100644 (file)
new mode 100755 (executable)
index 78df022..e27a0eb
@@ -77,43 +77,44 @@ end
 
 $terminal.wrap_at = :auto
 Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
 
-index.lock_or_die
+index.lock_interactively or exit
 
 begin
-  index.load_sources
+  Redwood::SourceManager.load_sources
 
   ARGV.each do |uri|
     labels = $opts[:labels] ? $opts[:labels].split(/\s*,\s*/).uniq : []
 
-    if !$opts[:force_new] && index.source_for(uri) 
+    if !$opts[:force_new] && Redwood::SourceManager.source_for(uri)
       say "Already know about #{uri}; skipping."
       next
     end
 
     parsed_uri = URI(uri)
-    Trollop::die "no path component to uri: #{parsed_uri}" unless parsed_uri.path
 
     source = 
       case parsed_uri.scheme
       when "mbox+ssh"
         say "For SSH connections, if you will use public key authentication, you may leave the username and password blank."
         say ""
-        username, password = get_login_info uri, index.sources
+        username, password = get_login_info uri, Redwood::SourceManager.sources
         Redwood::MBox::SSHLoader.new uri, username, password, nil, !$opts[:unusual], $opts[:archive], nil, labels
       when "imap", "imaps"
-        username, password = get_login_info uri, index.sources
+        username, password = get_login_info uri, Redwood::SourceManager.sources
         Redwood::IMAP.new uri, username, password, nil, !$opts[:unusual], $opts[:archive], nil, labels
       when "maildir"
         Redwood::Maildir.new uri, nil, !$opts[:unusual], $opts[:archive], nil, labels
       when "mbox"
         Redwood::MBox::Loader.new uri, nil, !$opts[:unusual], $opts[:archive], nil, labels
+      when nil
+        Trollop::die "Sources must be specified with an URI"
       else
         Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}"      
       end
     say "Adding #{source}..."
-    index.add_source source
+    Redwood::SourceManager.add_source source
   end
 ensure
   index.save