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



102
103
104
# File 'lib/branch_io_cli/command/report_command.rb', line 102

def report_helper
  Helper::ReportHelper
end

#run!Object



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
36
37
38
39
# File 'lib/branch_io_cli/command/report_command.rb', line 7

def run!
  say "\n"

  task = Helper::Task.new
  task.begin "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?
    task.success "Done."
  else
    task.error "Failed."
    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



106
107
108
# File 'lib/branch_io_cli/command/report_command.rb', line 106

def tool_helper
  Helper::ToolHelper
end

#write_report(report) ⇒ Object



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
95
96
97
98
99
100
# File 'lib/branch_io_cli/command/report_command.rb', line 41

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", obfuscate: true)

  # 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, obfuscate: true
    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
    task = Helper::Task.new use_spinner: report != STDOUT
    task.begin "Cleaning."
    if report.sh(*base_cmd, "clean", obfuscate: true).success?
      task.success "Done."
    else
      task.error "Clean failed."
    end
  end

  task = Helper::Task.new use_spinner: report != STDOUT
  task.begin "Building."
  if report.sh(*base_cmd, "-verbose", obfuscate: true).success?
    task.success "Done."
  else
    task.error "Failed."
  end
end