diff --git a/README.md b/README.md index 66e9ae1..6859a65 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Synx supports the following options: ``` --prune, -p remove source files and image resources that are not referenced by the the xcode project + --no-color removes all color from the output --no-default-exclusions doesn't use the default exclusions of /Libraries, /Frameworks, and /Products --quiet, -q silence all output --exclusion, -e EXCLUSION ignore an Xcode group while syncing diff --git a/bin/synx b/bin/synx index 8b004c6..1aad4af 100755 --- a/bin/synx +++ b/bin/synx @@ -7,13 +7,14 @@ Clamp do parameter "xcodeproj", "Path to the xcodeproj", :attribute_name => :xcodeproj_path option ["--prune", "-p"], :flag, "remove source files and image resources that are not referenced by the the xcode project" + option "--no-color", :flag, "removes all color from the output" option "--no-default-exclusions", :flag, "doesn't use the default exclusions of /Libraries, /Frameworks, and /Products" option ["--quiet", "-q"], :flag, "silence all output" option ["--exclusion", "-e"], "EXCLUSION", "ignore an Xcode group while syncing", :multivalued => true def execute project = Synx::Project.open(xcodeproj_path) - project.sync(:prune => prune?, :quiet => quiet?, :no_default_exclusions => no_default_exclusions?, :group_exclusions => exclusion_list) + project.sync(:prune => prune?, :quiet => quiet?, :no_color => no_color?, :no_default_exclusions => no_default_exclusions?, :group_exclusions => exclusion_list) end end diff --git a/lib/synx.rb b/lib/synx.rb index 8931932..88f8124 100644 --- a/lib/synx.rb +++ b/lib/synx.rb @@ -7,7 +7,7 @@ require "synx/pbx_variant_group" require "synx/tabber" -require "colored" +require "colorize" module Synx end diff --git a/lib/synx/project.rb b/lib/synx/project.rb index e82d44c..46ad362 100644 --- a/lib/synx/project.rb +++ b/lib/synx/project.rb @@ -49,7 +49,7 @@ def set_options(options) self.group_exclusions |= options[:group_exclusions] if options[:group_exclusions] - Synx::Tabber.quiet = options[:quiet] + Synx::Tabber.options = options end private :set_options diff --git a/lib/synx/tabber.rb b/lib/synx/tabber.rb index c6be381..c2a5030 100644 --- a/lib/synx/tabber.rb +++ b/lib/synx/tabber.rb @@ -1,7 +1,7 @@ module Synx class Tabber - @@quiet = false + @@options = {} @@tabbing = 0 class << self @@ -20,19 +20,20 @@ def current def reset @@tabbing = 0 - self.quiet = false + self.options = {} end - def quiet=(quiet) - @@quiet = quiet + def options=(options = {}) + @@options = options end - def quiet? - @@quiet + def options + @@options end def puts(str="") - Kernel.puts (a_single_tab * @@tabbing) + str.to_s unless quiet? + str = str.uncolorize if options[:no_color] + Kernel.puts (a_single_tab * @@tabbing) + str.to_s unless options[:quiet] end def a_single_tab diff --git a/spec/synx/tabber_spec.rb b/spec/synx/tabber_spec.rb index 521b092..1caf815 100644 --- a/spec/synx/tabber_spec.rb +++ b/spec/synx/tabber_spec.rb @@ -55,11 +55,21 @@ end it "should not print anything if quiet is true" do - Synx::Tabber.quiet = true - Synx::Tabber.increase(3) + Synx::Tabber.options = { quiet: true } expect(Kernel).to_not receive(:puts) Synx::Tabber.puts("Hello, world.") end + + it "should print colors if no_color is false or not present" do + expect(Kernel).to receive(:puts).with("\e[0;31;49mHello, world.\e[0m") + Synx::Tabber.puts("Hello, world.".red) + end + + it "should not print colors if no_color is true" do + Synx::Tabber.options = { no_color: true } + expect(Kernel).to receive(:puts).with("Hello, world.") + Synx::Tabber.puts("Hello, world.".red) + end end describe "::a_single_tab" do diff --git a/synx.gemspec b/synx.gemspec index a34864f..e2111ba 100644 --- a/synx.gemspec +++ b/synx.gemspec @@ -27,6 +27,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry", "~> 0.9" spec.add_dependency "clamp", "~> 0.6" - spec.add_dependency "colored", "~> 1.2" + spec.add_dependency "colorize", "~> 0.7" spec.add_dependency "xcodeproj", "~> 0.17" end