Class: EnsureXcodeHasNoCiSources::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ensure_xcode_has_no_ci_sources/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
# File 'lib/ensure_xcode_has_no_ci_sources/cli.rb', line 10

def initialize(argv)
  @argv = argv

  @warn = false
  @silent = false
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



5
6
7
# File 'lib/ensure_xcode_has_no_ci_sources/cli.rb', line 5

def argv
  @argv
end

#silentObject (readonly)

Returns the value of attribute silent.



8
9
10
# File 'lib/ensure_xcode_has_no_ci_sources/cli.rb', line 8

def silent
  @silent
end

#warnObject (readonly)

Returns the value of attribute warn.



7
8
9
# File 'lib/ensure_xcode_has_no_ci_sources/cli.rb', line 7

def warn
  @warn
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ensure_xcode_has_no_ci_sources/cli.rb', line 17

def run
  OptionParser.new do |opts|
    opts.on("-w", "--warn", "Exit with 0, even if case insensitive files are found") { @warn = true }
    opts.on("-s", "--silent", "Does not print anything") { @silent = true }
  end.parse!(argv)

  failed = false

  argv.each do |path|
    project = Xcodeproj::Project.open(path)
    ci_sources = EnsureXcodeHasNoCiSources::Test.new(project).case_insensitive_sources
    if ci_sources.size > 0
      failed = true

      unless silent
        puts Rainbow("#{project.path.relative_path_from(Pathname(".").realpath)} has case insensitive sources 💣").red
        ci_sources.each do |source|
          puts "  In Xcode Project: #{source.project_path.basename}"
          puts "    In File System: #{source.file_path.relative_path_from(project.path.parent)}"
        end
      end
    else
      unless silent
        puts Rainbow("#{project.path.relative_path_from(Pathname(".").realpath)} has no case insensitive sources 👍").green
      end          
    end
  end

  if failed
    exit 1 if !warn
  end
end