Class: BranchIOCLI::Command::ReportCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/branch_io_cli/command/report_command.rb

Instance Attribute Summary

Attributes inherited from Command

#config, #options

Instance Method Summary collapse

Methods inherited from Command

available_options, command_name, configuration_class, #env, examples, #helper, #initialize, #patch_helper, return_value

Constructor Details

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

Instance Method Details

#report_helperObject



96
97
98
# File 'lib/branch_io_cli/command/report_command.rb', line 96

def report_helper
  Helper::ReportHelper
end

#run!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/branch_io_cli/command/report_command.rb', line 6

def run!
  say "\n"

  say "Loading settings from Xcode"
  # In case running in a non-CLI context (e.g., Rake or Fastlane) be sure
  # to reset Xcode settings each time, since project, target and
  # configurations will change.
  Configuration::XcodeSettings.reset
  if Configuration::XcodeSettings.all_valid?
    say "Done ✅"
  else
    say "Failed to load settings from Xcode. Some information may be missing.\n"
  end

  if config.header_only
    say "\n"
    say env.ruby_header
    say report_helper.report_header
    return 0
  end

  if config.report_path == "stdout"
    write_report STDOUT
  else
    File.open(config.report_path, "w") { |f| write_report f }
    say "Report generated in #{config.report_path}"
  end

  0
end

#tool_helperObject



100
101
102
# File 'lib/branch_io_cli/command/report_command.rb', line 100

def tool_helper
  Helper::ToolHelper
end

#write_report(report) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
# File 'lib/branch_io_cli/command/report_command.rb', line 37

def write_report(report)
  report.write "Branch.io Xcode build report v #{VERSION} #{Time.now}\n\n"
  report.write "#{config.report_configuration}\n"

  if report == STDOUT
    say env.ruby_header
  else
    report.write env.ruby_header(terminal: false, include_load_path: true)
  end

  report.write "#{report_helper.report_header}\n"

  tool_helper.pod_install_if_required report
  tool_helper.carthage_bootstrap_if_required report

  # run xcodebuild -list
  report.sh(*report_helper.base_xcodebuild_cmd, "-list")

  # If using a workspace, -list all the projects as well
  if config.workspace_path
    config.workspace.file_references.map(&:path).each do |project_path|
      path = File.join File.dirname(config.workspace_path), project_path
      report.sh "xcodebuild", "-list", "-project", path
    end
  end

  # xcodebuild -showBuildSettings
  config.configurations.each do |configuration|
    Configuration::XcodeSettings[configuration].log_xcodebuild_showbuildsettings report
  end

  base_cmd = report_helper.base_xcodebuild_cmd
  # Add more options for the rest of the commands
  base_cmd += [
    "-scheme",
    config.scheme,
    "-configuration",
    config.configuration || config.configurations_from_scheme.first,
    "-sdk",
    config.sdk
  ]

  if config.clean
    say "Cleaning"
    if report.sh(*base_cmd, "clean").success?
      say "Done ✅"
    else
      say "Clean failed."
    end
  end

  say "Building"
  if report.sh(*base_cmd, "-verbose").success?
    say "Done ✅"
  else
    say "Build failed."
  end
end