Class: Fontist::CLI
- Inherits:
-
Thor
- Object
- Thor
- Fontist::CLI
- Includes:
- ClassOptions
- Defined in:
- lib/fontist/cli.rb,
lib/fontist/cli/class_options.rb
Defined Under Namespace
Modules: ClassOptions
Constant Summary collapse
- STATUS_SUCCESS =
0- STATUS_UNKNOWN_ERROR =
1- STATUS_NON_SUPPORTED_FONT_ERROR =
2- STATUS_MISSING_FONT_ERROR =
3- STATUS_LICENSING_ERROR =
4- STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR =
5- STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR =
6- STATUS_FONT_INDEX_CORRUPTED =
7- STATUS_REPO_NOT_FOUND =
8- STATUS_MAIN_REPO_NOT_FOUND =
9- STATUS_REPO_COULD_NOT_BE_UPDATED =
10- STATUS_MANUAL_FONT_ERROR =
11- STATUS_SIZE_LIMIT_ERROR =
12- STATUS_FORMULA_NOT_FOUND =
13- ERROR_TO_STATUS =
{ Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR], Fontist::Errors::MissingFontError => [STATUS_MISSING_FONT_ERROR], Fontist::Errors::SizeLimitError => [ STATUS_SIZE_LIMIT_ERROR, :append, "Please specify higher `--size-limit`, or use the `--newest` or " \ "`--smallest` options.", ], Fontist::Errors::ManualFontError => [STATUS_MANUAL_FONT_ERROR], Fontist::Errors::LicensingError => [STATUS_LICENSING_ERROR], Fontist::Errors::ManifestCouldNotBeFoundError => [STATUS_MANIFEST_COULD_NOT_BE_FOUND_ERROR, :overwrite, "Manifest could not be found."], Fontist::Errors::ManifestCouldNotBeReadError => [STATUS_MANIFEST_COULD_NOT_BE_READ_ERROR, :overwrite, "Manifest could not be read."], Fontist::Errors::FontIndexCorrupted => [STATUS_FONT_INDEX_CORRUPTED], Fontist::Errors::RepoNotFoundError => [STATUS_REPO_NOT_FOUND], Fontist::Errors::MainRepoNotFoundError => [STATUS_MAIN_REPO_NOT_FOUND], Fontist::Errors::FormulaNotFoundError => [STATUS_FORMULA_NOT_FOUND], }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #create_formula(url) ⇒ Object
- #import_sil ⇒ Object
- #install(font) ⇒ Object
- #list(font = nil) ⇒ Object
- #manifest_install(manifest) ⇒ Object
- #manifest_locations(manifest) ⇒ Object
- #rebuild_index ⇒ Object
- #status(font = nil) ⇒ Object
- #uninstall(font) ⇒ Object
- #update ⇒ Object
Methods included from ClassOptions
Class Method Details
.exit_on_failure? ⇒ Boolean
49 50 51 |
# File 'lib/fontist/cli.rb', line 49 def self.exit_on_failure? false end |
Instance Method Details
#create_formula(url) ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/fontist/cli.rb', line 177 def create_formula(url) () require "fontist/import/create_formula" name = Fontist::Import::CreateFormula.new(url, ).call Fontist.ui.say("#{name} formula has been successfully created") success end |
#import_sil ⇒ Object
200 201 202 203 204 |
# File 'lib/fontist/cli.rb', line 200 def import_sil () require "fontist/import/sil_import" Fontist::Import::SilImport.new.call end |
#install(font) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/fontist/cli.rb', line 86 def install(font) () confirmation = [:accept_all_licenses] ? "yes" : "no" Fontist::Font.install(font, .merge(confirmation: confirmation)) success rescue Fontist::Errors::GeneralError => e handle_error(e) end |
#list(font = nil) ⇒ Object
119 120 121 122 123 124 125 126 |
# File 'lib/fontist/cli.rb', line 119 def list(font = nil) () formulas = Fontist::Font.list(font) print_list(formulas) success rescue Fontist::Errors::GeneralError => e handle_error(e) end |
#manifest_install(manifest) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/fontist/cli.rb', line 157 def manifest_install(manifest) () paths = Fontist::Manifest::Install.from_file( manifest, confirmation: [:accept_all_licenses] ? "yes" : "no", hide_licenses: [:hide_licenses] ) print_yaml(paths) success rescue Fontist::Errors::GeneralError => e handle_error(e) end |
#manifest_locations(manifest) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/fontist/cli.rb', line 141 def manifest_locations(manifest) () paths = Fontist::Manifest::Locations.from_file(manifest) print_yaml(paths) success rescue Fontist::Errors::GeneralError => e handle_error(e) end |
#rebuild_index ⇒ Object
192 193 194 195 196 197 |
# File 'lib/fontist/cli.rb', line 192 def rebuild_index () Fontist::Index.rebuild Fontist.ui.say("Formula index has been rebuilt.") STATUS_SUCCESS end |
#status(font = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/fontist/cli.rb', line 108 def status(font = nil) () 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) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/fontist/cli.rb', line 96 def uninstall(font) () 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 ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/fontist/cli.rb', line 129 def update () Formula.update_formulas_repo Fontist.ui.success("Formulas have been successfully updated.") success rescue Fontist::Errors::RepoCouldNotBeUpdatedError => e Fontist.ui.error(e.) STATUS_REPO_COULD_NOT_BE_UPDATED end |