Class: AppRepo::CommandsGenerator

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

Overview

This class is responsible for providing commands with respective actions

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



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

def self.start
  FastlaneCore::UpdateChecker.start_looking_for_update('apprepo')
  new.run
ensure
  checker = FastlaneCore::UpdateChecker
  checker.show_update_status('apprepo', AppRepo::VERSION)
end

Instance Method Details

#download_manifestObject



18
19
20
# File 'lib/apprepo/commands_generator.rb', line 18

def download_manifest
  command :download_manifest
end

#initObject



22
23
24
# File 'lib/apprepo/commands_generator.rb', line 22

def init
  command :init
end

#runObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Style/GlobalVars



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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/apprepo/commands_generator.rb', line 31

def run
  program :version, AppRepo::VERSION
  program :description, AppRepo::DESCRIPTION
  program :help, 'Author', 'Matej Sychra <[email protected]>'
  program :help, 'Website', 'https://github.com/suculent/apprepo'
  program :help, 'GitHub', 'https://github.com/suculent/apprepo/tree/master/apprepo'
  program :help_formatter, :compact

  generator = FastlaneCore::CommanderGenerator.new
  generator.generate(AppRepo::Options.available_options)

  global_option('--verbose') { $verbose = true }

  always_trace!

  command :run do |c|
    c.syntax = 'apprepo'
    c.description = 'Upload IPA and metadata to SFTP (e.g. AppRepo)'
    c.action do |_args, options|
      config = FastlaneCore::Configuration
      available_opts = AppRepo::Options.available_options
      options = config.create(available_opts, options.__hash__)
      loaded = options.load_configuration_file('Repofile')
      loaded = true if options[:repo_description] || options[:ipa]

      unless loaded
        UI.message('[AppRepo::CommandsGenerator] configuration file not loaded')
        if UI.confirm('No Repofile found. Do you want to setup apprepo?')
          require 'apprepo/setup'
          AppRepo::Setup.new.run(options)
          return 0
        end
      end

      AppRepo::Runner.new(options).run
    end
  end

  command :download_manifest do |c|
    c.syntax = 'apprepo download_manifest'
    c.description = 'Download metadata only'
    c.action do |_args, options|
      config = FastlaneCore::Configuration
      available_opts = AppRepo::Options.available_options
      options = config.create(available_opts, options.__hash__)
      options.load_configuration_file('Repofile')
      AppRepo::Runner.new(options).download_manifest
    end
  end

  command :submit do |c|
    c.syntax = 'apprepo submit'
    c.description = 'Submit a specific build-nr, use latest.'
    c.action do |_args, options|
      config = FastlaneCore::Configuration
      available_opts = AppRepo::Options.available_options
      options = config.create(available_opts, options.__hash__)
      options.load_configuration_file('Repofile')
      AppRepo::Runner.new(options).run
    end
  end

  command :init do |c|
    c.syntax = 'apprepo init'
    c.description = 'Create the initial `apprepo` configuration'
    c.action do |_args, options|
      if File.exist?('Repofile') || File.exist?('fastlane/Repofile')
        UI.important('You already got a running apprepo setup.')
        return 0
      end

      require 'apprepo/setup'
      config = FastlaneCore::Configuration
      available_opts = AppRepo::Options.available_options
      options = config.create(available_opts, options.__hash__)
      AppRepo::Runner.new(options)
      AppRepo::Setup.new.run(options)
    end
  end

  # rubocop:enable Metrics/AbcSize
  # rubocop:enable Metrics/MethodLength

  default_command :run

  run!
end