Class: BranchIOCLI::Configuration::ReportConfiguration

Inherits:
Configuration
  • Object
show all
Defined in:
lib/branch_io_cli/configuration/report_configuration.rb

Instance Attribute Summary collapse

Attributes inherited from Configuration

#cartfile_path, #options, #pod_repo_update, #podfile, #podfile_path, #sdk_integration_mode, #target, #workspace, #workspace_path, #xcodeproj, #xcodeproj_path

Instance Method Summary collapse

Methods inherited from Configuration

#bridging_header_path, #bridging_header_required?, #helper, #initialize, #modules_enabled?, #open_podfile, #print_identification, #swift_version, #uses_frameworks?, #validate_buildfile_at_path, #validate_buildfile_path, #validate_target, #validate_xcodeproj_path

Constructor Details

This class inherits a constructor from BranchIOCLI::Configuration::Configuration

Instance Attribute Details

#cleanObject (readonly)

Returns the value of attribute clean.



4
5
6
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 4

def clean
  @clean
end

#configurationObject (readonly)

Returns the value of attribute configuration.



7
8
9
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 7

def configuration
  @configuration
end

#header_onlyObject (readonly)

Returns the value of attribute header_only.



5
6
7
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 5

def header_only
  @header_only
end

#report_pathObject (readonly)

Returns the value of attribute report_path.



8
9
10
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 8

def report_path
  @report_path
end

#schemeObject (readonly)

Returns the value of attribute scheme.



6
7
8
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 6

def scheme
  @scheme
end

#sdkObject (readonly)

Returns the value of attribute sdk.



9
10
11
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 9

def sdk
  @sdk
end

Instance Method Details

#all_schemesObject



155
156
157
158
159
160
161
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 155

def all_schemes
  if workspace_path
    workspace.schemes.keys.reject { |scheme| scheme == "Pods" }
  else
    Xcodeproj::Project.schemes xcodeproj_path
  end
end

#logObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 36

def log
  super
  say <<EOF
<%= color('Xcode workspace:', BOLD) %> #{workspace_path || '(none)'}
<%= color('Xcode project:', BOLD) %> #{xcodeproj_path || '(none)'}
<%= color('Scheme:', BOLD) %> #{scheme || '(none)'}
<%= color('Target:', BOLD) %> #{target || '(none)'}
<%= color('Configuration:', BOLD) %> #{configuration}
<%= color('SDK:', BOLD) %> #{sdk}
<%= color('Podfile:', BOLD) %> #{podfile_path || '(none)'}
<%= color('Cartfile:', BOLD) %> #{cartfile_path || '(none)'}
<%= color('Pod repo update:', BOLD) %> #{pod_repo_update.inspect}
<%= color('Clean:', BOLD) %> #{clean.inspect}
<%= color('Report path:', BOLD) %> #{report_path}
EOF
end

#validate_optionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 11

def validate_options
  @clean = options.clean
  @header_only = options.header_only
  @scheme = options.scheme
  @target = options.target
  @configuration = options.configuration
  @report_path = options.out
  @sdk = options.sdk
  @pod_repo_update = options.pod_repo_update

  validate_xcodeproj_and_workspace options
  validate_target options
  validate_scheme options

  # If neither --podfile nor --cartfile is present, arbitrarily look for a Podfile
  # first.

  # If --cartfile is present, don't look for a Podfile. Just validate that
  # Cartfile.
  validate_buildfile_path(options.podfile, "Podfile") if options.cartfile.nil?

  # If --podfile is present or a Podfile was found, don't look for a Cartfile.
  validate_buildfile_path(options.cartfile, "Cartfile") if sdk_integration_mode.nil?
end

#validate_scheme(options) ⇒ Object

rubocop: enable Metrics/PerceivedComplexity



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 133

def validate_scheme(options)
  schemes = all_schemes
  # TODO: Prompt if --scheme specified but not found.
  if options.scheme && schemes.include?(options.scheme)
    @scheme = options.scheme
  elsif schemes.count == 1
    @scheme = schemes.first
  elsif !schemes.empty?
    # By default, take a scheme with the same name as the target name.
    return if (@scheme = schemes.find { |s| s == target.name })

    say "Please specify one of the following for the --scheme argument:"
    schemes.each do |scheme|
      say " #{scheme}"
    end
    exit 1
  else
    say "No scheme defined in project."
    exit(-1)
  end
end

#validate_xcodeproj_and_workspace(options) ⇒ Object

rubocop: disable Metrics/PerceivedComplexity



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/branch_io_cli/configuration/report_configuration.rb', line 54

def validate_xcodeproj_and_workspace(options)
  # 1. What was passed in?
  begin
    if options.workspace
      path = options.workspace
      @workspace = Xcodeproj::Workspace.new_from_xcworkspace options.workspace
      @workspace_path = options.workspace
    end
    if options.xcodeproj
      path = options.xcodeproj
      @xcodeproj = Xcodeproj::Project.open options.xcodeproj
      @xcodeproj_path = options.xcodeproj
    else
      # Pass --workspace and --xcodeproj to override this inference.
      if workspace && workspace.file_references.count > 0 && workspace.file_references.first.path =~ /\.xcodeproj$/
        @xcodeproj_path = File.expand_path "../#{@workspace.file_references.first.path}", workspace_path
        @xcodeproj = Xcodeproj::Project.open xcodeproj_path
      end
    end
    return if @workspace || @xcodeproj
  rescue StandardError => e
    say e.message
  end

  # Try to find first a workspace, then a project
  all_workspace_paths = Dir[File.expand_path(File.join(".", "**/*.xcworkspace"))]
                        .reject { |w| w =~ %r{/project.xcworkspace$} }
                        .select do |p|
    valid = true
    Pathname.new(p).each_filename do |f|
      valid = false && break if f == "Carthage" || f == "Pods"
    end
    valid
  end

  if all_workspace_paths.count == 1
    path = all_workspace_paths.first
  elsif all_workspace_paths.count == 0
    all_xcodeproj_paths = Dir[File.expand_path(File.join(".", "**/*.xcodeproj"))]
    xcodeproj_paths = all_xcodeproj_paths.select do |p|
      valid = true
      Pathname.new(p).each_filename do |f|
        valid = false && break if f == "Carthage" || f == "Pods"
      end
      valid
    end

    path = xcodeproj_paths.first if xcodeproj_paths.count == 1
  end
  # If more than one workspace. Don't try to find a project. Just prompt.

  loop do
    path = ask "Please enter a path to your Xcode project or workspace: " if path.nil?
    begin
      if path =~ /\.xcworkspace$/
        @workspace = Xcodeproj::Workspace.new_from_xcworkspace path
        @workspace_path = path

        # Pass --workspace and --xcodeproj to override this inference.
        if workspace.file_references.count > 0 && workspace.file_references.first.path =~ /\.xcodeproj$/
          @xcodeproj_path = File.expand_path "../#{workspace.file_references.first.path}", workspace_path
          @xcodeproj = Xcodeproj::Project.open xcodeproj_path
        end

        return
      elsif path =~ /\.xcodeproj$/
        @xcodeproj = Xcodeproj::Project.open path
        @xcodeproj_path = path
        return
      else
        say "Path must end with .xcworkspace or .xcodeproj"
      end
    rescue StandardError => e
      say e.message
    end
  end
end