<commit_before>require "cyoi/cli"
require "cyoi/cli/auto_detection"
require "cyoi/cli/helpers"
class Cyoi::Cli::Address
  include Cyoi::Cli::Helpers

  def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
    @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
    @settings_dir = @argv.shift || "/tmp/provider_settings"
    @settings_dir = File.expand_path(@settings_dir)
  end

  def execute!
    unless valid_address?
      settings["address"] = address_cli.perform_and_return_attributes
      save_settings!
    end
    address_cli.display_confirmation
  end

  # Continue the interactive session with the user
  # specific to the address/infrastructure they have
  # chosen.
  #
  # The returned object is a class from cyoi/cli/addresss/provier_cli_NAME.rb
  # The class loads itself into `@address_clis` via `register_address_cli`
  #
  # Returns nil if settings.address.name not set
  def address_cli
    @address_cli ||= begin
      provider_name = settings.exists?("provider.name")
      return nil unless provider_name
      require "cyoi/cli/provider_addresses/address_cli_#{settings.provider.name}"
      klass = self.class.address_cli(settings.provider.name)
      settings["address"] ||= {}
      klass.new(settings.address, hl)
    end
  end

  def self.register_address_cli(name, klass)<commit_msg>Fail nicely if settings.provider.name missing<commit_after>require "cyoi/cli"
require "cyoi/cli/auto_detection"
require "cyoi/cli/helpers"
class Cyoi::Cli::Address
  include Cyoi::Cli::Helpers

  def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
    @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
    @settings_dir = @argv.shift || "/tmp/provider_settings"
    @settings_dir = File.expand_path(@settings_dir)
  end

  # TODO run Cyoi::Cli::Provider first if settings.provider.name missing
  def execute!
    unless settings.exists?("provider.name")
      $stderr.puts("Please run 'cyoi provider' first")
      exit 1
    end
    unless valid_address?
      settings["address"] = address_cli.perform_and_return_attributes
      save_settings!
    end
    address_cli.display_confirmation
  end

  # Continue the interactive session with the user
  # specific to the address/infrastructure they have
  # chosen.
  #
  # The returned object is a class from cyoi/cli/addresss/provier_cli_NAME.rb
  # The class loads itself into `@address_clis` via `register_address_cli`
  #
  # Returns nil if settings.address.name not set
  def address_cli
    @address_cli ||= begin
      provider_name = settings.exists?("provider.name")
      return nil unless provider_name
      require "cyoi/cli/provider_addresses/address_cli_#{settings.provider.name}"
      klass = self.class.address_cli(settings.provider.name)
      settings["address"] ||= {}
      klass.new(settings.address, hl)
    end
  end

  def self.register_address_cli(name, klass)
{'fraction_non_alphanumeric': 0.10270270270270271, 'fraction_numerical': 0.00033783783783783786, 'mean_word_length': 4.070205479452055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1967332', 'n_tokens_mistral': 934, 'n_tokens_neox': 920, 'n_words': 220}