diff options
-rw-r--r-- | DEVNOTES | 7 | ||||
-rw-r--r-- | README.md | 45 | ||||
-rw-r--r-- | Rakefile | 103 | ||||
-rwxr-xr-x | bin/leap | 2 | ||||
-rw-r--r-- | leap_cli.gemspec | 4 |
5 files changed, 113 insertions, 48 deletions
@@ -80,6 +80,13 @@ ssh keygen invoke puppet https://github.com/davidwinter/sooty/blob/master/lib/sooty.rb +shell +================================ + +http://devver.wordpress.com/2009/10/12/ruby-subprocesses-part_3/ +http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby +http://stackoverflow.com/questions/3874604/how-do-i-get-the-pty-spawn-child-exit-code +https://gist.github.com/148765 ssh ================================ @@ -6,9 +6,17 @@ This gem installs an executable 'leap' that allows you to manage servers using t Installation ================================= -To install the gem: +Prerequisites: - gem install leap_cli + sudo apt-get install ruby ruby-dev rsync openssh-client + +To install leap command system-wide: + + sudo gem install leap_cli + +To install without root privileges: + + gem install leap_cli --user-install To run from a clone of the git repo, see "Development", below. @@ -139,29 +147,31 @@ Debian Squeeze Debian Wheezy - sudo apt-get install git ruby ruby-dev - sudo gem install bundler + sudo apt-get install git ruby ruby-dev bundler -Ubuntu Quantal +Ubuntu sudo apt-get install git ruby ruby-dev sudo gem install bundler Install from git ---------------------------------- +-------------------------------------- -Install requirements +Download the source and install the required gems: git clone git://leap.se/leap_cli # clone leap_cli code cd leap_cli bundle # install required gems -Symlink bin/leap into your path: +Running from the source directory +-------------------------------------- + +To run the ``leap`` command directly from the source tree, symlink bin/leap +into your path: cd leap_cli - ln -s `pwd`/bin/leap /usr/local/bin # link executable somewhere in your bin path - which leap # make sure you will run leap_cli/bin/leap, - # and not /var/lib/gems/1.x/bin/leap + ln -s `pwd`/bin/leap ~/bin # link executable somewhere in your bin path + which leap # make sure you will run leap_cli/bin/leap leap help If you get an error, make sure to check ``which leap``. Some versions of ``bundle`` will @@ -172,3 +182,16 @@ working directory is under leap_cli. Because the point is to be able to run ``le other places, it is easier to create the symlink. If you run ``leap`` directly, and not via the command launcher that rubygems installs, leap will run in a mode that simulates ``bundle exec leap`` (i.e. only gems included in Gemfile are allow to be loaded). + +Running as a gem +-------------------------------------- + +To install ``leap`` as a gem, do this: + + cd leap_cli + rake build + rake install + +And then make sure your PATH is set to include where leap is installed. +It should warn you if this is not the case. + @@ -1,44 +1,77 @@ -require 'rake/clean' -require 'rubygems' -require 'rubygems/package_task' -require 'rdoc/task' -require 'cucumber' -require 'cucumber/rake/task' -Rake::RDocTask.new do |rd| - rd.main = "README.rdoc" - rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*") - rd.title = 'Your application title' -end +require "rubygems" +require "highline/import" +require "pty" +require "fileutils" -spec = eval(File.read('leap_cli.gemspec')) +## +## HELPER +## -Gem::PackageTask.new(spec) do |pkg| +def run(cmd) + PTY.spawn(cmd) do |output, input, pid| + begin + while line = output.gets do + puts line + end + rescue Errno::EIO + end + end +rescue PTY::ChildExited end -CUKE_RESULTS = 'results.html' -CLEAN << CUKE_RESULTS -desc 'Run features' -Cucumber::Rake::Task.new(:features) do |t| - opts = "features --format html -o #{CUKE_RESULTS} --format progress -x" - opts += " --tags #{ENV['TAGS']}" if ENV['TAGS'] - t.cucumber_opts = opts - t.fork = false + +## +## GEM BUILDING AND INSTALLING +## + +$spec_path = 'leap_cli.gemspec' +$spec = eval(File.read($spec_path)) +$base_dir = File.dirname(__FILE__) +$gem_path = File.join($base_dir, 'pkg', "#{$spec.name}-#{$spec.version}.gem") + +def built_gem_path + Dir[File.join($base_dir, "#{$spec.name}-*.gem")].sort_by{|f| File.mtime(f)}.last end -desc 'Run features tagged as work-in-progress (@wip)' -Cucumber::Rake::Task.new('features:wip') do |t| - tag_opts = ' --tags ~@pending' - tag_opts = ' --tags @wip' - t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}" - t.fork = false +desc "Build #{$spec.name}-#{$spec.version}.gem into the pkg directory" +task 'build' do + FileUtils.mkdir_p(File.join($base_dir, 'pkg')) + FileUtils.rm($gem_path) if File.exists?($gem_path) + run "gem build -V '#{$spec_path}'" + file_name = File.basename(built_gem_path) + FileUtils.mv(built_gem_path, 'pkg') + say "#{$spec.name} #{$spec.version} built to pkg/#{file_name}" end -task :cucumber => :features -task 'cucumber:wip' => 'features:wip' -task :wip => 'features:wip' -require 'rake/testtask' -Rake::TestTask.new do |t| - t.libs << "test" - t.test_files = FileList['test/*_test.rb'] +desc "Build and install #{$spec.name}-#{$spec.version}.gem into either system-wide or user gems" +task 'install' do + if !File.exists?($gem_path) + say("Could not file #{$gem_path}. Try running 'rake build'") + else + if ENV["USER"] == "root" + run "gem install '#{$gem_path}'" + else + say("A system-wide install requires that you run 'rake install' as root, which you are not.") + if agree("Do you want to continue installing to #{Gem.path.grep /home/}? ") + run "gem install '#{$gem_path}' --user-install" + end + end + end end -task :default => [:test,:features] +## +## TESTING +## + +# task :default => [:test,:features] + +## +## DOCUMENTATION +## + +# require 'rdoc/task' + +# Rake::RDocTask.new do |rd| +# rd.main = "README.rdoc" +# rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*") +# rd.title = 'Your application title' +# end @@ -17,8 +17,8 @@ rescue LoadError lib_dir = File.expand_path(File.dirname(file) + '/../lib') $LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) require 'rubygems' - require 'leap_cli' require 'bundler/setup' # force evaluation of "Gemfile" + require 'leap_cli' end require 'gli' diff --git a/leap_cli.gemspec b/leap_cli.gemspec index e8e7af4..b0c9a9e 100644 --- a/leap_cli.gemspec +++ b/leap_cli.gemspec @@ -14,11 +14,13 @@ spec = Gem::Specification.new do |s| s.email = 'root@leap.se' s.homepage = 'https://leap.se' s.platform = Gem::Platform::RUBY - s.summary = 'Command line interface to the leap platform.' + s.summary = 'Command line interface to the LEAP platform.' + s.description = 'Provides the command "leap", used to manage a bevy of servers running the LEAP platform from the comfort of your own home.' ## ## GEM FILES ## + s.files = `find lib vendor -name '*.rb'`.split("\n") << "bin/leap" s.require_paths << 'lib' |