提交 f08b9559 编写于 作者: C Chris Wanstrath

hub install standalone

上级 b0f705ed
......@@ -133,6 +133,15 @@ module Hub
end
alias_method "--version", :version
# $ hub install standalone ~/bin
def install(args)
command, subcommand, target = args
if subcommand.to_s == 'standalone'
Standalone.save('hub', target.empty? ? '.' : target)
exit
end
end
# $ hub help
# (print improved help text)
def help(args)
......
......@@ -18,6 +18,15 @@ premable
POSTAMBLE = "Hub::Runner.execute(*ARGV)"
def save(filename, path)
target = File.join(File.expand_path(path), filename)
File.open(target, 'w') do |f|
f.puts build
end
rescue Errno::EACCES, Errno::ENOENT
puts "** can't write to #{target}"
end
def build
root = File.dirname(__FILE__)
......
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'helper'
require 'fileutils'
class StandaloneTest < Test::Unit::TestCase
include FileUtils
def setup
rm "hub" if File.exists? 'hub'
rm_rf "/tmp/_hub_private" if File.exists? '/tmp/_hub_private'
mkdir "/tmp/_hub_private"
chmod 0400, "/tmp/_hub_private"
end
def teardown
rm "hub" if File.exists? 'hub'
rm_rf "/tmp/_hub_private" if File.exists? "/tmp/_hub_private"
end
def test_standalone
standalone = Hub::Standalone.build
assert_includes "This file, hub, is generated code", standalone
......@@ -11,4 +26,19 @@ class StandaloneTest < Test::Unit::TestCase
assert_includes ".execute(*ARGV)", standalone
assert_not_includes "module Standalone", standalone
end
def test_standalone_save
hub("install standalone .")
assert_equal Hub::Standalone.build + "\n", File.read('./hub')
end
def test_standalone_save_permission_denied
out = hub("install standalone /tmp/_hub_private")
assert_equal "** can't write to /tmp/_hub_private/hub\n", out
end
def test_standalone_save_doesnt_exist
out = hub("install standalone /tmp/something/not/real")
assert_equal "** can't write to /tmp/something/not/real/hub\n", out
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册