mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
Polish agree usage in crew (#10333)
* Adjust agree options. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Add agree_default_no function. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Add more verbosity to agree_to_remove. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Adjust crew use of agree. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Adjust asks in vim packages. Signed-off-by: Satadru Pramanik <satadru@gmail.com> * Add color to highline questions. Signed-off-by: Satadru Pramanik <satadru@gmail.com> --------- Signed-off-by: Satadru Pramanik <satadru@gmail.com>
This commit is contained in:
committed by
GitHub
parent
12352730e5
commit
984bfec896
9
bin/crew
9
bin/crew
@@ -23,7 +23,6 @@ def require_gem(gem_name_and_require = nil, require_override = nil)
|
||||
end
|
||||
# The json gem can break when upgrading from a much older version of ruby.
|
||||
require_gem('json')
|
||||
require_gem('highline/import')
|
||||
require_gem('activesupport', 'active_support/core_ext/object/blank')
|
||||
require 'digest/sha2'
|
||||
require 'fileutils'
|
||||
@@ -1234,9 +1233,7 @@ def resolve_dependencies
|
||||
|
||||
if @opt_force
|
||||
puts 'Proceeding with dependency package installation...'.orange
|
||||
elsif agree('Do you agree? ')
|
||||
puts 'Proceeding...'
|
||||
else
|
||||
elsif !Package.agree_default_yes('Proceed')
|
||||
abort 'No changes made.'
|
||||
end
|
||||
|
||||
@@ -1479,7 +1476,7 @@ def upload(pkg_name = nil, pkg_version = nil, gitlab_token = nil, binary_compres
|
||||
|
||||
if `curl -sI #{new_url}`.lines.first.split[1] == '200'
|
||||
puts "\n#{new_tarfile} has already been uploaded.\nPlease change the #{package} package version from #{new_version} and try again.\n".lightred
|
||||
unless agree('Do you want to overwrite the existing upload instead? ')
|
||||
unless Package.agree_default_no('Do you want to overwrite the existing upload instead')
|
||||
puts 'Will NOT overwite the existing upload.'.orange
|
||||
next
|
||||
end
|
||||
@@ -1574,7 +1571,7 @@ def copy_package(pkg_name, prompt_msg = '')
|
||||
# This pulls the operation from the calling function
|
||||
operation = caller_locations(1, 2)[1].to_s.split[3].split('_')[0]
|
||||
puts prompt_msg.yellow
|
||||
if agree("\nWould you like to copy #{pkg_name}.rb to crew and start the #{operation}? ")
|
||||
if Package.agree_default_yes("\nWould you like to copy #{pkg_name}.rb to crew and start the #{operation}")
|
||||
FileUtils.cp pkg_file, "#{CREW_PACKAGES_PATH}/"
|
||||
puts "\nCopied #{pkg_file} to #{CREW_PACKAGES_PATH}.\n".lightgreen
|
||||
else
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Defines common constants used in different parts of crew
|
||||
require 'etc'
|
||||
|
||||
CREW_VERSION = '1.50.8'
|
||||
CREW_VERSION = '1.50.9'
|
||||
|
||||
# Kernel architecture.
|
||||
KERN_ARCH = Etc.uname[:machine]
|
||||
|
||||
23
lib/fixup.rb
23
lib/fixup.rb
@@ -6,27 +6,6 @@ require_relative 'color'
|
||||
require_relative 'package'
|
||||
require_relative 'package_utils'
|
||||
|
||||
def require_gem(gem_name_and_require = nil, require_override = nil)
|
||||
# Allow only loading gems when needed.
|
||||
return if gem_name_and_require.nil?
|
||||
|
||||
gem_name = gem_name_and_require.split('/')[0]
|
||||
begin
|
||||
gem gem_name
|
||||
rescue LoadError
|
||||
puts " -> install #{gem_name} gem".orange
|
||||
Gem.install(gem_name)
|
||||
gem gem_name
|
||||
end
|
||||
requires = if require_override.nil?
|
||||
gem_name_and_require.split('/')[1].nil? ? gem_name_and_require.split('/')[0] : gem_name_and_require
|
||||
else
|
||||
require_override
|
||||
end
|
||||
require requires
|
||||
end
|
||||
require_gem('highline/import')
|
||||
|
||||
# All needed constants & variables should be defined here in case they
|
||||
# have not yet been loaded or fixup is being run standalone.
|
||||
|
||||
@@ -204,7 +183,7 @@ pkg_update_arr.each do |pkg|
|
||||
next if pkg[:pkg_deprecated].to_s.empty?
|
||||
puts "#{pkg[:pkg_name].capitalize} is deprecated and should be removed.".lightpurple
|
||||
puts "#{pkg[:pkg_name].capitalize}: #{pkg[:comments]}".lightpurple unless pkg[:comments].to_s.empty?
|
||||
if agree("\nWould you like to remove deprecated package #{pkg[:pkg_name].capitalize}? ")
|
||||
if Package.agree_default_yes("\nWould you like to remove deprecated package #{pkg[:pkg_name].capitalize}")
|
||||
# Create a minimal Package object and pass it to Command.remove
|
||||
pkg_object = Package
|
||||
pkg_object.instance_eval do
|
||||
|
||||
@@ -25,7 +25,8 @@ def require_gem(gem_name_and_require = nil, require_override = nil)
|
||||
require requires
|
||||
end
|
||||
|
||||
def agree_with_default(yes_or_no_question, character = nil, default:)
|
||||
def agree_with_default(yes_or_no_question_msg, character = nil, default:)
|
||||
yes_or_no_question = yes_or_no_question_msg.lightpurple
|
||||
require_gem('highline')
|
||||
answer_type = ->(yn) { yn.downcase[0] == 'y' || (yn.empty? && default.downcase[0] == 'y') }
|
||||
|
||||
@@ -66,15 +67,28 @@ class Package
|
||||
attr_accessor :name, :cached_build, :in_build, :build_from_source, :in_upgrade
|
||||
end
|
||||
|
||||
def self.agree_to_remove(config_file = nil)
|
||||
if File.file? config_file
|
||||
if agree_with_default("Would you like to remove the #{name} config file: #{config_file} (YES/no)?", true, default: 'y')
|
||||
FileUtils.rm_rf config_file
|
||||
puts "#{config_file} removed.".lightgreen
|
||||
else
|
||||
puts "#{config_file} saved.".lightgreen
|
||||
end
|
||||
def self.agree_to_remove(config_object = nil)
|
||||
if File.file? config_object
|
||||
identifier = 'file'
|
||||
elsif File.directory? config_object
|
||||
identifier = 'directory'
|
||||
else
|
||||
abort "Cannot identify #{config_object}.".lightred
|
||||
end
|
||||
if agree_with_default("Would you like to remove the config #{identifier}: #{config_object} (YES/no)?", true, default: 'y')
|
||||
FileUtils.rm_rf config_object
|
||||
puts "#{config_object} removed.".lightgreen
|
||||
else
|
||||
puts "#{config_object} saved.".lightgreen
|
||||
end
|
||||
end
|
||||
|
||||
def self.agree_default_no(message = nil)
|
||||
return agree_with_default("#{message} (yes/NO)?", true, default: 'n')
|
||||
end
|
||||
|
||||
def self.agree_default_yes(message = nil)
|
||||
return agree_with_default("#{message} (YES/no)?", true, default: 'y')
|
||||
end
|
||||
|
||||
def self.load_package(pkg_file)
|
||||
|
||||
@@ -99,9 +99,7 @@ class Gvim < Autotools
|
||||
@create_vi_symlink = true if !@system_vi && !@crew_vi
|
||||
@create_vi_symlink_ask = true if @crew_vi || @system_vi
|
||||
if @create_vi_symlink_ask
|
||||
print "\nWould you like to set vim to be the default vi [y/N] "
|
||||
case $stdin.gets.chomp.downcase
|
||||
when 'y', 'yes'
|
||||
if Package.agree_default_yes('Would you like to set vim to be the default vi')
|
||||
@create_vi_symlink = true
|
||||
else
|
||||
@create_vi_symlink = false
|
||||
|
||||
@@ -91,9 +91,7 @@ class Vim < Autotools
|
||||
@create_vi_symlink = true if !@system_vi && !@crew_vi
|
||||
@create_vi_symlink_ask = true if @crew_vi || @system_vi
|
||||
if @create_vi_symlink_ask
|
||||
print "\nWould you like to set vim to be the default vi [y/N] "
|
||||
case $stdin.gets.chomp.downcase
|
||||
when 'y', 'yes'
|
||||
if Package.agree_default_yes('Would you like to set vim to be the default vi')
|
||||
@create_vi_symlink = true
|
||||
else
|
||||
@create_vi_symlink = false
|
||||
|
||||
Reference in New Issue
Block a user