Sha256: 9c5636f66960dbedd7669eb6932960d3dfa785b15c8aea657b941c5b8bdd88bf

Contents?: true

Size: 1.87 KB

Versions: 39

Compression:

Stored size: 1.87 KB

Contents

require 'cocoapods-bb-bin/config/config_hot_key_asker'

module Pod
  class Command
    class Bin < Command
      class Inithk < 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'

          UI.puts "开始下载配置文件...\n"
          file = open(url)
          contents = YAML.safe_load(file.read)

          UI.puts "开始同步配置文件...\n"
          CBin.config_hot_key.sync_config(contents.to_hash)
          UI.puts "设置完成.\n".green
        rescue Errno::ENOENT => e
          raise Informative, "配置文件路径 #{url} 无效,请确认后重试."
        end

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

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

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

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
cocoapods-bb-bin-0.2.3 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.2.2.2 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.2.2.1 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.2.2 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.2.1 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.2.0 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.9.2 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.9.1 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.9 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.8.1 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.8 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.7 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.6 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.5 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.4 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.3 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.2 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.1 lib/cocoapods-bb-bin/command/bin/initHotKey.rb
cocoapods-bb-bin-0.1.0 lib/cocoapods-bb-bin/command/bin/initHotKey.rb