lib/travis/cli/command.rb in travis-1.5.7.travis.345.4 vs lib/travis/cli/command.rb in travis-1.5.7

- old
+ new

@@ -1,20 +1,22 @@ require 'travis/cli' require 'travis/tools/system' require 'travis/tools/formatter' +require 'travis/tools/assets' +require 'travis/tools/completion' require 'travis/version' require 'highline' require 'forwardable' require 'yaml' require 'timeout' module Travis module CLI class Command - extend Parser - extend Forwardable + include Tools::Assets + extend Parser, Forwardable, Tools::Assets def_delegators :terminal, :agree, :ask, :choose HighLine.use_color = !Tools::System.windows? && $stdout.tty? HighLine.color_scheme = HighLine::ColorScheme.new do |cs| cs[:command] = [ :bold ] @@ -35,10 +37,11 @@ c.force_interactive = v end on('-E', '--[no-]explode', "don't rescue exceptions") on('--skip-version-check', "don't check if travis client is up to date") + on('--skip-completion-check', "don't check if auto-completion is set up") def self.command_name name[/[^:]*$/].downcase end @@ -128,10 +131,20 @@ last_check['at'] = Time.now.to_i error "Outdated CLI version, run `gem install travis` or use --skip-version-check." if Travis::VERSION < last_check['version'] rescue Timeout::Error, Faraday::Error::ClientError end + def check_completion + return if skip_completion_check? or config['checked_completion'] or !interactive? + write_to($stderr) do + next if Tools::Completion.completion_installed? + next unless agree('Shell completion not installed. Would you like to like to install it now? ') { |q| q.default = "y" } + Tools::Completion.install_completion + end + config['checked_completion'] = true + end + def check_ruby return if RUBY_VERSION > '1.9.2' or skip_version_check? warn "Your Ruby version is outdated, please consider upgrading, as we will drop support for #{RUBY_VERSION} soon!" end @@ -139,10 +152,11 @@ setup_trap check_ruby check_arity(method(:run), *arguments) load_config check_version + check_completion setup run(*arguments) store_config rescue StandardError => e raise(e) if explode? @@ -251,31 +265,31 @@ def success(line) say color(line, :success) if interactive? end - def asset_path(name) + def config_path(name) path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) } Dir.mkdir(path, 0700) unless File.directory? path File.join(path, name) end - def load_asset(name, default = nil) - path = asset_path(name) + def load_file(name, default = nil) + path = config_path(name) File.exist?(path) ? File.read(path) : default end - def save_asset(name, content) - File.write(asset_path(name), content.to_s) + def save_file(name, content) + File.write(config_path(name), content.to_s) end def load_config - @config = YAML.load load_asset('config.yml', '{}') + @config = YAML.load load_file('config.yml', '{}') @original_config = @config.dup end def store_config - save_asset('config.yml', @config.to_yaml) + save_file('config.yml', @config.to_yaml) end def check_arity(method, *args) return unless method.respond_to? :parameters method.parameters.each do |type, name|