module Idcf::Cli::Extend::Update

update settings

Constants

COMP_N

Protected Instance Methods

do_update(_o) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 18
def do_update(_o)
  s_schemas = schema_data_acquisition
  output_schema(s_schemas)
  output_complement
end
extract_command_infos(t_class, s_name, infos) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 192
def extract_command_infos(t_class, s_name, infos)
  commands = []
  return extract_commands(t_class, commands) if infos[s_name].nil?
  infos[s_name].each_key do |name|
    commands << name.to_s
  end
  extract_commands(t_class, commands)
end
extract_commands(thor_class, commands) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 184
def extract_commands(thor_class, commands)
  thor_class.commands.each_key do |k_c|
    commands << k_c if commands.index(k_c).nil?
  end

  commands.sort
end
latest_schema(schemas) click to toggle source

get latest schema

@param schemas [Array] @return Hash or nil

# File lib/idcf/cli/extend/update.rb, line 48
def latest_schema(schemas)
  result = nil
  v_str = '$version'
  schemas.each do |data|
    result ||= data
    v1 = Gem::Version.create(data[v_str])
    v2 = Gem::Version.create(result[v_str])
    next unless v1 > v2
    result = data
  end
  result
end
make_flat_variables(list, names = []) click to toggle source

bash 3.x

@param list [Hash] @param names [Array] @return Hash

# File lib/idcf/cli/extend/update.rb, line 171
def make_flat_variables(list, names = [])
  result = {}
  name = names.empty? ? 'top' : names.join('_')
  result[name] = list.keys
  list.each do |k, v|
    next unless v.class == Hash
    names << k
    result.merge!(make_flat_variables(v, names))
    names.pop
  end
  result
end
make_script_variables() click to toggle source
# File lib/idcf/cli/extend/update.rb, line 161
def make_script_variables
  self.class.init({})
  make_flat_variables(self.class.subcommand_structure)
end
output_complement() click to toggle source
# File lib/idcf/cli/extend/update.rb, line 61
def output_complement
  view = Idcf::Cli::Lib::Util::Template.new
  view.set('variables', make_script_variables)
  paths = {}
  Idcf::Cli::Conf::Const::COMP_PATHS.each_key do |k|
    str = view.fetch("#{k}/#{COMP_N}.erb")
    path = "#{Idcf::Cli::Conf::Const::OUT_DIR}/#{COMP_N}.#{k}"
    paths[k] = File.expand_path(path)
    output_complement_file(str, paths[k])
  end

  output_notification(paths)
end
output_default_schema(service, version, regions) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 37
def output_default_schema(service, version, regions)
  return nil if regions.keys.include?('default')
  latist = latest_schema(regions.values)
  path = make_schema_file_path(service, version, 'default')
  output_complement_file(JSON.pretty_generate(latist), path)
end
output_manual_writing(paths) click to toggle source

manual write

@param paths [Hash]

# File lib/idcf/cli/extend/update.rb, line 154
def output_manual_writing(paths)
  puts 'please write in'
  Idcf::Cli::Conf::Const::COMP_PATHS.each do |k, v|
    puts v, "source #{paths[k]}"
  end
end
output_notification(paths) click to toggle source

output notification

@param paths [Hash]

# File lib/idcf/cli/extend/update.rb, line 78
def output_notification(paths)
  script = ENV['SHELL'].split('/').pop.to_sym
  return output_manual_writing(paths) if paths[script].nil?
  startup_script_qa(paths, script)
end
output_schema(s_schemas) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 24
def output_schema(s_schemas)
  s_schemas.each do |service, infos|
    infos.each do |version, regions|
      next if regions.nil? || regions.empty?
      regions.each do |region, schema|
        path = make_schema_file_path(service, version, region)
        output_complement_file(JSON.pretty_generate(schema), path)
      end
      output_default_schema(service, version, regions)
    end
  end
end
output_startup_script(script, paths) click to toggle source

output start script

@param paths [Hash]

# File lib/idcf/cli/extend/update.rb, line 107
def output_startup_script(script, paths)
  s_script_path = startup_script_path(script)
  write_str = "source #{paths[script]}"

  if write_path?(s_script_path, write_str)
    File.open(s_script_path, 'a') do |f|
      f.puts write_str, ''
    end
  end

  puts 'Run the following command:', write_str
end
startup_script_path(script) click to toggle source

startup script path

@param script [String] @return String

# File lib/idcf/cli/extend/update.rb, line 100
def startup_script_path(script)
  File.expand_path(Idcf::Cli::Conf::Const::COMP_PATHS[script])
end
startup_script_qa(paths, script) click to toggle source
# File lib/idcf/cli/extend/update.rb, line 84
def startup_script_qa(paths, script)
  list = %w[y N]
  puts "Do you want to edit the startup script?(#{list.join('/')})"
  puts "[#{startup_script_path(script)}]"
  ans = Idcf::Cli::Lib::Util::Input.qa_answer_input(list)
  if ans == 'y'
    output_startup_script(script, paths)
  else
    output_manual_writing(paths)
  end
end
write_line_str_exist?(path, check_str) click to toggle source

write line str exist?

@param path [String] setting path @param check_str @return Boolean @raise

# File lib/idcf/cli/extend/update.rb, line 142
def write_line_str_exist?(path, check_str)
  File.open(path, 'r') do |f|
    f.each_line do |line|
      return true if line.strip == check_str
    end
  end
  false
end
write_path?(path, check_str) click to toggle source

write path?

@param path [String] setting path @param check_str @return Boolean @raise

# File lib/idcf/cli/extend/update.rb, line 126
def write_path?(path, check_str)
  if File.exist?(path)
    Idcf::Cli::Lib::Util::CliFile.writable(path)
    return !write_line_str_exist?(path, check_str)
  end

  Idcf::Cli::Lib::Util::CliFile.writable(File.expand_path('..', path))
  true
end