From bddede55b60a4a0758091ed18551eb8ef620bcc7 Mon Sep 17 00:00:00 2001 From: Yossef Mendelssohn Date: Wed, 10 Oct 2012 12:41:50 -0400 Subject: [PATCH] Add logic to Puppet status code This is used in multiple places now, and it should be boxed up with the Puppet status anyway. --- lib/boxen/puppeteer.rb | 10 +++++++++- test/boxen_puppeteer_test.rb | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/boxen/puppeteer.rb b/lib/boxen/puppeteer.rb index 143cc24..7e9ef73 100644 --- a/lib/boxen/puppeteer.rb +++ b/lib/boxen/puppeteer.rb @@ -6,6 +6,14 @@ module Boxen # Manages an invocation of puppet. class Puppeteer + + Status = Struct.new(:code) do + # Puppet's detailed exit codes reserves 2 for a successful run with changes + def success? + [0,2].include?(code) + end + end + attr_reader :config def initialize(config) @@ -77,7 +85,7 @@ module Boxen warn command.join " " if config.debug? Boxen::Util.sudo *command - $?.exitstatus + Status.new($?.exitstatus) end end end diff --git a/test/boxen_puppeteer_test.rb b/test/boxen_puppeteer_test.rb index 030a6bf..9df7416 100644 --- a/test/boxen_puppeteer_test.rb +++ b/test/boxen_puppeteer_test.rb @@ -75,4 +75,15 @@ class BoxenPuppeteerTest < Boxen::Test assert found, "Flags must include #{flag} #{value}." end + + def test_status + status = Boxen::Puppeteer::Status.new(0) + assert status.success? + + status = Boxen::Puppeteer::Status.new(2) + assert status.success? + + status = Boxen::Puppeteer::Status.new(1) + refute status.success? + end end