Class: Snapshot::CommandsGenerator

Inherits:
Object
  • Object
show all
Includes:
Commander::Methods
Defined in:
lib/snapshot/commands_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



10
11
12
13
14
15
# File 'lib/snapshot/commands_generator.rb', line 10

def self.start
  FastlaneCore::UpdateChecker.start_looking_for_update('snapshot')
  self.new.run
ensure
  FastlaneCore::UpdateChecker.show_update_status('snapshot', Snapshot::VERSION)
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
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
101
102
# File 'lib/snapshot/commands_generator.rb', line 17

def run
  program :name, 'snapshot'
  program :version, Snapshot::VERSION
  program :description, 'CLI for \'snapshot\' - Automate taking localized screenshots of your iOS app on every device'
  program :help, 'Author', 'Felix Krause <[email protected]>'
  program :help, 'Website', 'https://fastlane.tools'
  program :help, 'GitHub', 'https://github.com/fastlane/snapshot'
  program :help_formatter, :compact

  global_option('--verbose', 'Shows a more verbose output') { $verbose = true }

  always_trace!

  FastlaneCore::CommanderGenerator.new.generate(Snapshot::Options.available_options)

  command :run do |c|
    c.syntax = 'snapshot'
    c.description = 'Take new screenshots based on the Snapfile.'

    c.action do |args, options|
      load_config(options)

      Snapshot::DependencyChecker.check_simulators
      Snapshot::Runner.new.work
    end
  end

  command :init do |c|
    c.syntax = 'snapshot init'
    c.description = "Creates a new Snapfile in the current directory"

    c.action do |args, options|
      require 'snapshot/setup'
      path = (Snapshot::Helper.fastlane_enabled? ? './fastlane' : '.')
      Snapshot::Setup.create(path)
    end
  end

  command :update do |c|
    c.syntax = 'snapshot update'
    c.description = "Updates your SnapshotHelper.swift to the latest version"

    c.action do |args, options|
      require 'snapshot/update'
      Snapshot::Update.new.update
    end
  end

  command :reset_simulators do |c|
    c.syntax = 'snapshot reset_simulators'
    c.description = "This will remove all your existing simulators and re-create new ones"
    c.option '-i', '--ios String', String, 'The comma separated list of iOS Versions you want to use'
    c.option '--force', 'Disables confirmation prompts'

    c.action do |args, options|
      options.default ios_version: Snapshot::LatestOsVersion.ios_version
      versions = options.ios_version.split(',') if options.ios_version
      require 'snapshot/reset_simulators'

      Snapshot::ResetSimulators.clear_everything!(versions, options.force)
    end
  end

  command :clear_derived_data do |c|
    c.syntax = 'snapshot clear_derived_data -f path'
    c.description = "Clear the directory where build products and other derived data will go"

    c.action do |args, options|
      load_config(options)
      derived_data_path = Snapshot.config[:derived_data_path]

      if !derived_data_path
        Snapshot::UI.user_error! "No derived_data_path"
      elsif !Dir.exist?(derived_data_path)
        Snapshot::UI.important "Path #{derived_data_path} does not exist"
      else
        FileUtils.rm_rf(derived_data_path)
        Snapshot::UI.success "Removed #{derived_data_path}"
      end
    end
  end

  default_command :run

  run!
end