commit f894d5c2d9be902af5cb02d00a11454f12c10858
parent 7989b5b89f2e29a1fdf9762ff7e443cc0fd45067
Author: Gaute Hope <eg@gaute.vetsj.com>
Date: Thu, 24 Sep 2015 10:59:28 +0200
fix #473: use highline instance
Diffstat:
3 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/bin/sup-add b/bin/sup-add
@@ -3,9 +3,9 @@
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'uri'
-require 'highline/import'
require 'trollop'
require "sup"
+require 'sup/utils/axe'
$opts = Trollop::options do
version "sup-add (sup #{Redwood::VERSION})"
@@ -53,10 +53,10 @@ def get_login_info uri, sources
if $opts[:force_account]
host, username, password = accounts.find { |h, u, p| $opts[:force_account] == "#{u}@#{h}" }
unless username && password
- say "No previous account #{$opts[:force_account].inspect} found."
+ @cli.say "No previous account #{$opts[:force_account].inspect} found."
end
else
- say "Would you like to use the same account as for a previous source for #{uri}?"
+ @cli.say "Would you like to use the same account as for a previous source for #{uri}?"
choose do |menu|
accounts.each do |host, olduser, oldpw|
menu.choice("Use the account info for #{olduser}@#{host}") { username, password = olduser, oldpw }
@@ -68,8 +68,8 @@ def get_login_info uri, sources
end
unless username && password
- username = ask("Username for #{uri.host}: ");
- password = ask("Password for #{uri.host}: ") { |q| q.echo = false }
+ username = @cli.ask("Username for #{uri.host}: ");
+ password = @cli.ask("Password for #{uri.host}: ") { |q| q.echo = false }
puts # why?
end
@@ -90,7 +90,7 @@ begin
labels = $opts[:labels] ? $opts[:labels].split(/\s*,\s*/).uniq : []
if !$opts[:force_new] && Redwood::SourceManager.source_for(uri)
- say "Already know about #{uri}; skipping."
+ @cli.say "Already know about #{uri}; skipping."
next
end
@@ -107,7 +107,7 @@ begin
else
Trollop::die "Unknown source type #{parsed_uri.scheme.inspect}"
end
- say "Adding #{source}..."
+ @cli.say "Adding #{source}..."
Redwood::SourceManager.add_source source
end
ensure
diff --git a/bin/sup-config b/bin/sup-config
@@ -2,7 +2,6 @@
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
-require 'highline/import'
require 'trollop'
require "sup"
require 'sup/util/axe'
@@ -29,7 +28,7 @@ def add_source
type = nil
- say "Ok, adding a new source."
+ @cli.say "Ok, adding a new source."
choose do |menu|
menu.prompt = "What type of mail source is it? "
menu.choice("mbox file") { type = :mbox }
@@ -38,7 +37,7 @@ def add_source
end
while true do
- say "Ok, now for the details."
+ @cli.say "Ok, now for the details."
default_labels, components = case type
when :mbox
@@ -62,11 +61,11 @@ def add_source
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
@@ -95,10 +94,10 @@ def add_source
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
@@ -109,7 +108,7 @@ 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
@@ -125,11 +124,11 @@ 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]
@@ -146,16 +145,16 @@ $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"
+ @cli.say "\n"
choose do |menu|
menu.prompt = "Your wish? "
menu.choice("Add a new source.") { add_source }
@@ -163,12 +162,12 @@ until done
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
@@ -189,9 +188,9 @@ 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
@@ -205,10 +204,10 @@ if axe_yes "Run sup-sync to import all messages now?"
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
@@ -216,7 +215,7 @@ 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.
diff --git a/lib/sup/util/axe.rb b/lib/sup/util/axe.rb
@@ -1,4 +1,5 @@
-require 'highline/import'
+require 'highline'
+@cli = HighLine.new
def axe q, default=nil
question = if default && !default.empty?
@@ -6,7 +7,7 @@ def axe q, default=nil
else
"#{q}: "
end
- ans = ask question
+ ans = @cli.ask question
ans.empty? ? default : ans.to_s
end