class Fontist::CLI

Constants

ERROR_TO_STATUS
STATUS_FONT_INDEX_CORRUPTED
STATUS_LICENSING_ERROR
STATUS_MAIN_REPO_NOT_FOUND
STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR
STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR
STATUS_MISSING_FONT_ERROR
STATUS_NON_SUPPORTED_FONT_ERROR
STATUS_REPO_COULD_NOT_BE_UPDATED
STATUS_REPO_NOT_FOUND
STATUS_SUCCESS
STATUS_UNKNOWN_ERROR

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/fontist/cli.rb, line 32
def self.exit_on_failure?
  false
end

Public Instance Methods

create_formula(url) click to toggle source
# File lib/fontist/cli.rb, line 138
def create_formula(url)
  handle_class_options(options)
  require "fontist/import/create_formula"
  name = Fontist::Import::CreateFormula.new(url, options).call
  Fontist.ui.say("#{name} formula has been successfully created")
  success
end
import_sil() click to toggle source
# File lib/fontist/cli.rb, line 161
def import_sil
  handle_class_options(options)
  require "fontist/import/sil_import"
  Fontist::Import::SilImport.new.call
end
install(font) click to toggle source
# File lib/fontist/cli.rb, line 46
def install(font)
  handle_class_options(options)
  Fontist::Font.install(
    font,
    force: options[:force],
    confirmation: options[:accept_all_licenses] ? "yes" : "no",
    hide_licenses: options[:hide_licenses],
    no_progress: options[:no_progress]
  )
  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
list(font = nil) click to toggle source
# File lib/fontist/cli.rb, line 84
def list(font = nil)
  handle_class_options(options)
  formulas = Fontist::Font.list(font)
  print_list(formulas)
  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
manifest_install(manifest) click to toggle source
# File lib/fontist/cli.rb, line 118
def manifest_install(manifest)
  handle_class_options(options)
  paths = Fontist::Manifest::Install.from_file(
    manifest,
    confirmation: options[:accept_all_licenses] ? "yes" : "no",
    hide_licenses: options[:hide_licenses]
  )

  print_yaml(paths)
  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
manifest_locations(manifest) click to toggle source
# File lib/fontist/cli.rb, line 106
def manifest_locations(manifest)
  handle_class_options(options)
  paths = Fontist::Manifest::Locations.from_file(manifest)
  print_yaml(paths)
  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
rebuild_index() click to toggle source
# File lib/fontist/cli.rb, line 153
def rebuild_index
  handle_class_options(options)
  Fontist::Index.rebuild
  Fontist.ui.say("Formula index has been rebuilt.")
  STATUS_SUCCESS
end
status(font = nil) click to toggle source
# File lib/fontist/cli.rb, line 73
def status(font = nil)
  handle_class_options(options)
  paths = Fontist::Font.status(font)
  return error("No font is installed.", STATUS_MISSING_FONT_ERROR) if paths.empty?

  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
uninstall(font) click to toggle source
# File lib/fontist/cli.rb, line 61
def uninstall(font)
  handle_class_options(options)
  fonts_paths = Fontist::Font.uninstall(font)
  Fontist.ui.success("These fonts are removed:")
  Fontist.ui.success(fonts_paths.join("\n"))
  success
rescue Fontist::Errors::GeneralError => e
  handle_error(e)
end
update() click to toggle source
# File lib/fontist/cli.rb, line 94
def update
  handle_class_options(options)
  Formula.update_formulas_repo
  Fontist.ui.success("Formulas have been successfully updated.")
  success
rescue Fontist::Errors::RepoCouldNotBeUpdatedError => e
  Fontist.ui.error(e.message)
  STATUS_REPO_COULD_NOT_BE_UPDATED
end

Private Instance Methods

error(message, status) click to toggle source
# File lib/fontist/cli.rb, line 190
def error(message, status)
  Fontist.ui.error(message)
  status
end
handle_class_options(options) click to toggle source
# File lib/fontist/cli.rb, line 175
def handle_class_options(options)
  Fontist.preferred_family = options[:preferred_family]
end
handle_error(exception) click to toggle source
# File lib/fontist/cli.rb, line 183
def handle_error(exception)
  status, message = ERROR_TO_STATUS[exception.class]
  raise exception unless status

  error(message || exception.message, status)
end
print_list(formulas) click to toggle source

rubocop:disable Metrics/AbcSize, Metrics/MethodLength

print_yaml(object) click to toggle source
success() click to toggle source
# File lib/fontist/cli.rb, line 179
def success
  STATUS_SUCCESS
end