Sha256: d2ce8c438f8c06d9655f8dd043a9f9117bba80d225c8c92763a0c34df1267f38

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

require 'cocoapods-tj/config/config_asker'

module Pod
  class Command
    class Bin < Command
      class Init < Bin
        self.summary = ''
        self.description = <<-DESC

        DESC

        def self.options
          [
            ['--bin-url=URL', '配置文件地址,直接从此地址下载配置文件']
          ].concat(super)
        end

        def initialize(argv)
          @bin_url = argv.option('bin-url')
          super
        end

        def run
          if @bin_url.nil?
            config_with_asker
          else
            config_with_url(@bin_url)
          end
        end

        private

        def config_with_url(url)
          require 'open-uri'

          file = open(url)
          contents = YAML.safe_load(file.read)

          CBin.config.sync_config(contents.to_hash)
        rescue Errno::ENOENT => e
          raise Informative, "配置文件路径 #{url} 无效,请确认后重试."
        end

        def config_with_asker
          asker = CBin::Config::Asker.new
          asker.wellcome_message

          config = {}
          template_hash = CBin.config.template_hash
          template_hash.each do |k, v|
            default = begin
                        CBin.config.send(k)
                      rescue StandardError
                        nil
                      end
            config[k] = asker.ask_with_answer(v[:description], default, v[:selection])
          end

          CBin.config.sync_config(config)
          asker.done_message
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cocoapods-tj-1.0.7 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.6 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.5 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.4 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.3 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.2 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.1 lib/cocoapods-tj/command/bin/init.rb
cocoapods-tj-1.0.0 lib/cocoapods-tj/command/bin/init.rb