add cli support for --list-services, --enable-services, and --disable-services

This commit is contained in:
Will Farrington
2012-10-09 07:54:06 -10:00
parent ca02b6aa6a
commit 79c6ef595a
2 changed files with 95 additions and 2 deletions

View File

@@ -43,6 +43,41 @@ module Boxen
exit
end
# --disable-services stops all services
if flags.disable_services?
Dir["/Library/LaunchDaemons/com.boxen.*.plist"]. each do |service|
service_human_name = service.match(/com\.boxen\.(.+)\.plist$/)[1]
puts "Disabling #{service_human_name}..."
Boxen::Util.sudo("/bin/launchctl", "unload", "-w", service)
end
exit
end
# --enable-services starts all services
if flags.enable_services?
Dir["/Library/LaunchDaemons/com.boxen.*.plist"]. each do |service|
service_human_name = service.match(/com\.boxen\.(.+)\.plist$/)[1]
puts "Enabling #{service_human_name}..."
Boxen::Util.sudo("/bin/launchctl", "load", "-w", service)
end
exit
end
# --list-services lists all services
if flags.list_services?
Dir["/Library/LaunchDaemons/com.boxen.*.plist"]. each do |service|
service_human_name = service.match(/com\.boxen\.(.+)\.plist$/)[1]
puts service_human_name
end
exit
end
# Actually run Puppet and return its exit code.
puppet.run

View File

@@ -6,6 +6,9 @@ class BoxenCLITest < Boxen::Test
@config = Boxen::Config.new
@flags = Boxen::Flags.new
@cli = Boxen::CLI.new(@config, @flags)
$stdout.stubs(:puts).returns(true)
$stdout.stubs(:write).returns(true)
end
def test_initialize
@@ -17,7 +20,7 @@ class BoxenCLITest < Boxen::Test
assert_equal config, cli.config
assert_equal flags, cli.flags
assert_equal config, cli.puppet.config
assert_equal config, cli.reporter.config
assert_equal config, cli.reporter.checkout.config
assert_equal cli.checkout, cli.reporter.checkout
@@ -121,4 +124,59 @@ class BoxenCLITest < Boxen::Test
@cli.run
end
end
def test_disable_services
config = Boxen::Config.new
flags = Boxen::Flags.new('--disable-services')
cli = Boxen::CLI.new config, flags
Dir.expects(:[]).with("/Library/LaunchDaemons/com.boxen.*.plist").returns([
"/Library/LaunchDaemons/com.boxen.test.plist"
])
Boxen::Util.expects(:sudo).with(
"/bin/launchctl",
"unload",
"-w",
"/Library/LaunchDaemons/com.boxen.test.plist"
).returns(true)
assert_raises(SystemExit) do
cli.process
end
def test_enable_services
config = Boxen::Config.new
flags = Boxen::Flags.new('--enable-services')
cli = Boxen::CLI.new config, flags
Dir.expects(:[]).with("/Library/LaunchDaemons/com.boxen.*.plist").returns([
"/Library/LaunchDaemons/com.boxen.test.plist"
])
Boxen::Util.expects(:sudo).with(
"/bin/launchctl",
"load",
"-w",
"/Library/LaunchDaemons/com.boxen.test.plist"
).returns(true)
assert_raises(SystemExit) do
cli.process
end
def test_list_services
config = Boxen::Config.new
flags = Boxen::Flags.new('--list-services')
cli = Boxen::CLI.new config, flags
Dir.expects(:[]).with("/Library/LaunchDaemons/com.boxen.*.plist").returns([
"/Library/LaunchDaemons/com.boxen.test.plist"
])
assert_raises(SystemExit) do
cli.process
end
end
end
end
end