From ca02b6aa6a724b0908f47a565383cb9d19efb6ad Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Oct 2012 07:27:27 -1000 Subject: [PATCH 1/5] add --list-services, --enable-services, --disable-services flags --- lib/boxen/flags.rb | 45 ++++++++++++++++++++++++++++++++-------- test/boxen_flags_test.rb | 15 ++++++++++++++ 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/boxen/flags.rb b/lib/boxen/flags.rb index fb222c8..21401ad 100644 --- a/lib/boxen/flags.rb +++ b/lib/boxen/flags.rb @@ -20,15 +20,18 @@ module Boxen # parse immediately. def initialize(*args) - @args = [] - @debug = false - @env = false - @fde = true - @help = false - @pretend = false - @profile = false - @projects = false - @stealth = false + @args = [] + @debug = false + @env = false + @fde = true + @help = false + @pretend = false + @profile = false + @projects = false + @stealth = false + @disable_services = false + @enable_services = false + @list_services = false @options = OptionParser.new do |o| o.banner = "Usage: #{File.basename $0} [options] [projects...]\n\n" @@ -49,6 +52,18 @@ module Boxen @help = true end + o.on "--disable-services", "Disable Boxen services." do + @disable_services = true + end + + o.on "--enable-services", "Enable Boxen services." do + @enable_services = true + end + + o.on "--list-services", "List Boxen services." do + @list_services = true + end + o.on "--homedir DIR", "Boxen's home directory." do |homedir| @homedir = homedir end @@ -131,6 +146,18 @@ module Boxen @help end + def disable_services? + @disable_services + end + + def enable_services? + @enable_services + end + + def list_services? + @list_services + end + # Parse `args` as an array of CLI argument Strings. Raises # Boxen::Error if anything goes wrong. Returns `self`. diff --git a/test/boxen_flags_test.rb b/test/boxen_flags_test.rb index 7fed932..1f7ba6b 100644 --- a/test/boxen_flags_test.rb +++ b/test/boxen_flags_test.rb @@ -53,6 +53,21 @@ class BoxenFlagsTest < Boxen::Test end end + def test_disable_services? + refute flags.disable_services? + assert flags("--disable-services").disable_services? + end + + def test_enable_services? + refute flags.enable_services? + assert flags("--enable-services").enable_services? + end + + def test_list_services? + refute flags.list_services? + assert flags("--list-services").list_services? + end + def test_homedir assert_nil flags.homedir assert_equal "foo", flags("--homedir", "foo").homedir From 79c6ef595a123c68537aa06781fbd63b6307a710 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Oct 2012 07:54:06 -1000 Subject: [PATCH 2/5] add cli support for --list-services, --enable-services, and --disable-services --- lib/boxen/cli.rb | 35 ++++++++++++++++++++++++ test/boxen_cli_test.rb | 62 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/lib/boxen/cli.rb b/lib/boxen/cli.rb index 8a1efce..86a03d1 100644 --- a/lib/boxen/cli.rb +++ b/lib/boxen/cli.rb @@ -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 diff --git a/test/boxen_cli_test.rb b/test/boxen_cli_test.rb index ebe2ae2..ee1c1a7 100644 --- a/test/boxen_cli_test.rb +++ b/test/boxen_cli_test.rb @@ -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 \ No newline at end of file From ac9958890a9d08e94a9b34cd303fa0e9a49023fb Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Oct 2012 08:12:11 -1000 Subject: [PATCH 3/5] travis-ci up in hurr --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..80707b4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +--- +script: "./script/cibuild" +gemfile: "this/does/not/exist" +rvm: + - "1.8.7" From 7a54b3090057fc38c549c28fe32c277bf39d7198 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Oct 2012 08:27:09 -1000 Subject: [PATCH 4/5] don't mind me, just blindly copy-pasting --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 80707b4..aa47a24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ --- -script: "./script/cibuild" +script: "./script/test" gemfile: "this/does/not/exist" rvm: - "1.8.7" From b1cdbfd8f5c8f68c21ef0560a9746c8d556671c3 Mon Sep 17 00:00:00 2001 From: Will Farrington Date: Tue, 9 Oct 2012 08:39:15 -1000 Subject: [PATCH 5/5] typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aa47a24..09ab35e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ --- -script: "./script/test" +script: "./script/tests" gemfile: "this/does/not/exist" rvm: - "1.8.7"