bin/sup-config in sup-0.22.1 vs bin/sup-config in sup-0.23
- old
+ new
@@ -1,14 +1,14 @@
#!/usr/bin/env ruby
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
-require 'highline/import'
-require 'trollop'
+require 'optimist'
require "sup"
+require 'sup/util/axe'
-$opts = Trollop::options do
+$opts = Optimist::options do
version "sup-config (sup #{Redwood::VERSION})"
banner <<EOS
Interactive configuration tool for Sup. Won't destroy existing
configuration.
@@ -17,43 +17,29 @@
No options.
EOS
end
-def axe q, default=nil
- question = if default && !default.empty?
- "#{q} (enter for \"#{default}\"): "
- else
- "#{q}: "
- end
- ans = ask question
- ans.empty? ? default : ans.to_s
-end
-
-def axe_yes q, default="n"
- axe(q, default) =~ /^y|yes$/i
-end
-
def build_cmd cmd
(ENV["RUBY_INVOCATION"] ? ENV["RUBY_INVOCATION"] + " " : "") + File.join(File.dirname($0), cmd)
end
def add_source
require "sup/util/uri"
type = nil
- say "Ok, adding a new source."
- choose do |menu|
+ @cli.say "Ok, adding a new source."
+ @cli.choose do |menu|
menu.prompt = "What type of mail source is it? "
menu.choice("mbox file") { type = :mbox }
menu.choice("maildir directory") { type = :maildir }
menu.choice("Get me out of here!") { return }
end
while true do
- say "Ok, now for the details."
+ @cli.say "Ok, now for the details."
default_labels, components = case type
when :mbox
$last_fn ||= ENV["MAIL"]
fn = axe "What's the full path to the mbox file?", $last_fn
@@ -73,15 +59,15 @@
end
uri = begin
Redwood::Util::Uri.build components
rescue URI::Error => e
- say "Whoopsie! I couldn't build a URI from that: #{e.message}"
+ @cli.say "Whoopsie! I couldn't build a URI from that: #{e.message}"
if axe_yes("Try again?") then next else return end
end
- say "I'm going to add this source: #{uri}"
+ @cli.say "I'm going to add this source: #{uri}"
unless axe("Does that look right?", "y") =~ /^y|yes$/i
if axe_yes("Try again?") then next else return end
end
usual = axe_yes "Does this source ever receive new messages?", "y"
@@ -106,25 +92,25 @@
puts "Ok, trying to run \"#{cmd}\"..."
system cmd
if $?.success?
- say "Great! Added!"
+ @cli.say "Great! Added!"
break
else
- say "Rats, that failed. You may have to do it manually."
+ @cli.say "Rats, that failed. You may have to do it manually."
if axe_yes("Try again?") then next else return end
end
end
end
-$terminal.wrap_at = :auto
+@cli.wrap_at = :auto
Redwood::start
index = Redwood::Index.init
Redwood::SourceManager.load_sources
-say <<EOS
+@cli.say <<EOS
Howdy neighbor! This here's sup-config, ready to help you jack in to
the next generation of digital cyberspace: the text-based email
program. Get ready to be the envy of everyone in your internets
with your amazing keyboarding skills! Jump from email to email with
nary a click of the mouse!
@@ -136,15 +122,15 @@
account = $config[:accounts][:default]
name = axe "What's your name?", account[:name]
email = axe "What's your (primary) email address?", account[:email]
-say "Ok, your from header will look like this:"
-say " From: #{name} <#{email}>"
+@cli.say "Ok, your from header will look like this:"
+@cli.say " From: #{name} <#{email}>"
-say "\nDo you have any alternate email addresses that also receive email?"
-say "If so, enter them now, separated by spaces."
+@cli.say "\nDo you have any alternate email addresses that also receive email?"
+@cli.say "If so, enter them now, separated by spaces."
alts = axe("Alternate email addresses", account[:alternates].join(" ")).split(/\s+/)
sigfn = axe "What file contains your signature?", account[:signature]
editor = axe "What editor would you like to use?", $config[:editor]
@@ -157,40 +143,40 @@
$config[:editor] = editor
$config[:time_mode] = time_mode
done = false
until done
- say "\nNow, we'll tell Sup where to find all your email."
+ @cli.say "\nNow, we'll tell Sup where to find all your email."
Redwood::SourceManager.load_sources
- say "Current sources:"
+ @cli.say "Current sources:"
if Redwood::SourceManager.sources.empty?
- say " No sources!"
+ @cli.say " No sources!"
else
Redwood::SourceManager.sources.each { |s| puts "* #{s}" }
end
- say "\n"
- choose do |menu|
+ @cli.say "\n"
+ @cli.choose do |menu|
menu.prompt = "Your wish? "
menu.choice("Add a new source.") { add_source }
menu.choice("Done adding sources!") { done = true }
end
end
-say "\nSup needs to know where to store your sent messages."
-say "Only sources capable of storing mail will be listed.\n\n"
+@cli.say "\nSup needs to know where to store your sent messages."
+@cli.say "Only sources capable of storing mail will be listed.\n\n"
Redwood::SourceManager.load_sources
if Redwood::SourceManager.sources.empty?
- say "\nUsing the default sup://sent, since you haven't configured other sources yet."
+ @cli.say "\nUsing the default sup://sent, since you haven't configured other sources yet."
$config[:sent_source] = 'sup://sent'
else
# this handles the event that source.yaml already contains the SentLoader
# source.
have_sup_sent = false
- choose do |menu|
+ @cli.choose do |menu|
menu.prompt = "Store my sent mail in? "
menu.choice('Default (an mbox in ~/.sup, aka sup://sent)') { $config[:sent_source] = 'sup://sent'} unless have_sup_sent
valid_sents = Redwood::SourceManager.sources.each do |s|
@@ -200,13 +186,13 @@
end
end
Redwood::save_yaml_obj $config, Redwood::CONFIG_FN, false, true
-say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}."
+@cli.say "Ok, I've saved you up a nice lil' #{Redwood::CONFIG_FN}."
-say <<EOS
+@cli.say <<EOS
The final step is to import all your messages into the Sup index.
Depending on how many messages are in the sources, this could take
quite a while.
@@ -216,21 +202,21 @@
while true
cmd = build_cmd("sup-sync") + " --all-sources"
puts "Ok, trying to run \"#{cmd}\"..."
system cmd
if $?.success?
- say "Great! It worked!"
+ @cli.say "Great! It worked!"
break
else
- say "Rats, that failed. You may have to do it manually."
+ @cli.say "Rats, that failed. You may have to do it manually."
if axe_yes("Try again?") then next else break end
end
end
end
index.load
-say <<EOS
+@cli.say <<EOS
Okee doke, you've got yourself an index of #{index.size} messages. Looks
like you're ready to jack in to cyberspace there, cowboy.
Just one last command: