Skip to content

Commit

Permalink
Merge pull request #32 from samsymons/no-color
Browse files Browse the repository at this point in the history
Add support for the --no-color option.
  • Loading branch information
ayanonagon committed Jun 30, 2014
2 parents 55858c5 + 415b1de commit 7e487bf
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bin/synx
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/synx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require "synx/pbx_variant_group"
require "synx/tabber"

require "colored"
require "colorize"

module Synx
end
2 changes: 1 addition & 1 deletion lib/synx/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions lib/synx/tabber.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Synx
class Tabber

@@quiet = false
@@options = {}
@@tabbing = 0

class << self
Expand All @@ -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
Expand Down
14 changes: 12 additions & 2 deletions spec/synx/tabber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion synx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7e487bf

Please sign in to comment.