Sha256: ad73dc89856f5438dff34c211ccbdd931ff960d492bc40ed0867bf820d6982c9

Contents?: true

Size: 1.87 KB

Versions: 18

Compression:

Stored size: 1.87 KB

Contents

require 'cocoapods-fy-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

18 entries across 18 versions & 1 rubygems

Version Path
cocoapods-fy-bin-0.1.8 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.7 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.6 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.5 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.4 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.3 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.2 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.1 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.1.0 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.9 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.8 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.7 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.6 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.5 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.4 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.3 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.2 lib/cocoapods-fy-bin/command/bin/initHotKey.rb
cocoapods-fy-bin-0.0.1 lib/cocoapods-fy-bin/command/bin/initHotKey.rb