= hoe-highline
== Description
A Hoe plugin for building interactive Rake tasks.
Hoe-highline, as you might have guessed from the name, adds prompting and
displaying functions from the HighLine[http://highline.rubyforge.org/] gem to your Rake
environment, allowing you to ask questions, prompt for passwords, build menus,
and other fun stuff.
== Installation
gem install hoe-highline
== Usage
In your Rakefile:
Hoe.plugin :highline
Hoe.spec 'mygem' do
# Configure the highline terminal to your liking
highline.wrap_at = :auto # Auto-wrap output
end
# Generate an email, show it, confirm they want to send it, then prompt
# for a SMTP connection information before sending
task :send_email do
message = generate_email( :full )
say "About to send this:"
say( mail )
if agree( "Okay to send it? " )
require 'socket'
require 'net/smtp'
require 'etc'
username = ask( "Email username: " ) do |q|
q.default = Etc.getlogin # default to the current user
end
password = ask( "Email password: " ) do |q|
q.echo = '*' # Hide the password
end
say "Creating SMTP connection to #{SMTP_HOST}:#{SMTP_PORT}"
smtp = Net::SMTP.new( SMTP_HOST, SMTP_PORT )
smtp.set_debug_output( $stderr )
smtp.esmtp = true
smtp.enable_starttls
helo = Socket.gethostname
smtp.start( helo, username, password, :plain ) do |smtp|
smtp.send_message( message, email_from, *email_to )
end
else
abort "Okay, aborting."
end
end
There is also a 'demo' task in this library's Rakefile that has a few ideas for things you might want to do. Running it looks like this:
hoe-highline Demo
You can prompt for a yes-or-no answer with agree()
Know what I mean (nudge, nudge, wink, wink)? [yn] y
What's it like?
You can ask for input with ask()
What could be better than that? Nothing!
Actually, that was a rhetorical question, but you answered: "Nothing!"
You can also ask() for things like passwords with a little configuration
Super sekrit password: **********
Okay, using your 10-character password for something nefarious...
You can also use choose() for building a menu.
What editor do you prefer?
1. Emacs
2. vi
3. Textmate
4. pico
5. RubyMine
6. FreeRIDE
? 3
Good to know (you picked "Textmate").
Or build a complex menu using a block.
Announce a new release:
1. ruby-talk
2. Blog
3. Twitter
4. Exit
? 2
Posting to blog.you.com!
1. ruby-talk
2. Twitter
3. Exit
? 1
Sending mail!
1. Twitter
2. Exit
? 2
There is also a list() function for display stuff in a compact list
For example, here's a list of the available tasks:
.hg/branch ChangeLog
check_extra_deps check_manifest
clobber clobber_docs
commit-msg.txt config_hoe
default demo
deps:list doc
gem generate_key
hg:ci hg:commit
hg:prep_release hg:pull
hg:push_without_confirmation hg:update
newb package
pkg/hoe-highline-0.0.1.gem pkg/hoe-highline-0.0.1.tgz
pre prerelease
rcov rcov_overlay
release_sanity release_to
ridocs
== Contributing
You can check out the current development source with Mercurial via its
{Bitbucket project}[https://bitbucket.org/ged/hoe-highline]. Or if you prefer Git, via
{its Github mirror}[https://github.com/ged/ruby-openldap].
After checking out the source, run:
$ rake newb
This task will install any missing dependencies, run the tests/specs,
and generate the API documentation.
== License
Copyright (c) 2011-2014, Michael Granger
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
-
Neither the name of the author/s, nor the names of the project's
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.