bin/sup-add in sup-0.0.8 vs bin/sup-add in sup-0.1

- old
+ new

@@ -35,10 +35,11 @@ Options are: EOS opt :archive, "Automatically archive all new messages from these sources." opt :unusual, "Do not automatically poll these sources for new messages." + opt :labels, "A comma-separated set of labels to apply to all messages from this source", :type => String opt :force_new, "Create a new account for this source, even if one already exists." end Trollop::die "require one or more sources" if ARGV.empty? @@ -75,38 +76,47 @@ end $terminal.wrap_at = :auto Redwood::start index = Redwood::Index.new -index.load -ARGV.each do |uri| - if !$opts[:force_new] && index.source_for(uri) - say "Already know about #{uri}; skipping." - next - end +index.lock_or_die - parsed_uri = URI(uri) +begin + index.load_sources - 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 - Redwood::MBox::SSHLoader.new uri, username, password, nil, !$opts[:unusual], $opts[:archive] - when "imap", "imaps" - username, password = get_login_info uri, index.sources - Redwood::IMAP.new uri, username, password, nil, !$opts[:unusual], $opts[:archive] - when "maildir" - Redwood::Maildir.new uri, nil, !$opts[:unusual], $opts[:archive] - when "mbox" - Redwood::MBox::Loader.new uri, nil, !$opts[:unusual], $opts[:archive] - else - Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}" + ARGV.each do |uri| + labels = $opts[:labels] ? $opts[:labels].split(/\s*,\s*/).uniq : [] + + if !$opts[:force_new] && index.source_for(uri) + say "Already know about #{uri}; skipping." + next end - say "Adding #{source}..." - index.add_source source -end -index.save -Redwood::finish + 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 + 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 + 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 + else + Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}" + end + say "Adding #{source}..." + index.add_source source + end +ensure + index.save + index.unlock + Redwood::finish +end