fontist 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f376e0b45e530b28be9d60c132b3840d4485103995fc435c0512b07bf6e20435
4
- data.tar.gz: b8c8aa1f3de0b627bcaffe09b45398dd60a0ba2a3a2163599263461acb179292
3
+ metadata.gz: 2e0bff9ea15b251c5c03206705574e12cfc9fc4bc779d197d73d20a05977e745
4
+ data.tar.gz: 33a6538507cc014c1fd4a0b1b11fa908560ae8319e9de13d33120c02a86953b4
5
5
  SHA512:
6
- metadata.gz: 157c06d56119a5e94a7a15b33b7b1e65695eb94af595f618bbbcf382f8d201d8db7f1a51ed2e3b20cf56d0339a7bd33dc2be82900de1851e29ee31225d2f8054
7
- data.tar.gz: 3fabd78041974540dc3504c293e335cfd39d241c5cd80da8fd0eef2b6b0a0e6a49701baf4c13e4c151ff397c8aaa6d9d542b37a45b52610ca404bb0abcef004a
6
+ metadata.gz: bf17d3b2dd7a687f97db3bd24200d0bd07821bab47ac0c0ce8eeb1156ec1fc95b39660dfb75e6eb13e00080968de1168c83cca7d54caee0c09139d0a167651d6
7
+ data.tar.gz: 18b6c0294686dcf739b2d1654b8c3e8488d823cb2de1d62659f834c7f8ca443615170d29f3f3bb2b705b27b07cb8a79d80ca6a185d09979c8c0f2f37f8af547f
data/README.adoc CHANGED
@@ -127,6 +127,7 @@ available formulas would be installed.
127
127
  Supported options:
128
128
 
129
129
  -f, [--force]:: Install even if it's already installed in system
130
+ -F, [--formula]:: Install by formula instead of font
130
131
  -a, [--accept-all-licenses]:: Accept all license agreements
131
132
  -h, [--hide-licenses]:: Hide license texts
132
133
  -p, [--no-progress]:: Hide download progress
@@ -0,0 +1,14 @@
1
+ module Fontist
2
+ class CLI < Thor
3
+ module ClassOptions
4
+ def handle_class_options(options)
5
+ Fontist.preferred_family = options[:preferred_family]
6
+ Fontist.log_level = options[:quiet] ? :fatal : :info
7
+
8
+ if options[:formulas_path]
9
+ Fontist.formulas_path = Pathname.new(options[:formulas_path])
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
data/lib/fontist/cli.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require "thor"
2
+ require "fontist/cli/class_options"
2
3
  require "fontist/repo_cli"
3
4
  require "fontist/import_cli"
4
5
  require "fontist/google_cli"
5
6
 
6
7
  module Fontist
7
8
  class CLI < Thor
9
+ include ClassOptions
10
+
8
11
  STATUS_SUCCESS = 0
9
12
  STATUS_UNKNOWN_ERROR = 1
10
13
  STATUS_NON_SUPPORTED_FONT_ERROR = 2
@@ -18,6 +21,7 @@ module Fontist
18
21
  STATUS_REPO_COULD_NOT_BE_UPDATED = 10
19
22
  STATUS_MANUAL_FONT_ERROR = 11
20
23
  STATUS_SIZE_LIMIT_ERROR = 12
24
+ STATUS_FORMULA_NOT_FOUND = 13
21
25
 
22
26
  ERROR_TO_STATUS = {
23
27
  Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
@@ -39,6 +43,7 @@ module Fontist
39
43
  Fontist::Errors::FontIndexCorrupted => [STATUS_FONT_INDEX_CORRUPTED],
40
44
  Fontist::Errors::RepoNotFoundError => [STATUS_REPO_NOT_FOUND],
41
45
  Fontist::Errors::MainRepoNotFoundError => [STATUS_MAIN_REPO_NOT_FOUND],
46
+ Fontist::Errors::FormulaNotFoundError => [STATUS_FORMULA_NOT_FOUND],
42
47
  }.freeze
43
48
 
44
49
  def self.exit_on_failure?
@@ -49,9 +54,18 @@ module Fontist
49
54
  type: :boolean,
50
55
  desc: "Use Preferred Family when available"
51
56
 
57
+ class_option :quiet,
58
+ aliases: :q,
59
+ type: :boolean,
60
+ desc: "Hide all messages"
61
+
62
+ class_option :formulas_path, type: :string, desc: "Path to formulas"
63
+
52
64
  desc "install FONT", "Install font"
53
65
  option :force, type: :boolean, aliases: :f,
54
66
  desc: "Install even if it's already installed in system"
67
+ option :formula, type: :boolean, aliases: :F,
68
+ desc: "Install by formula instead of font"
55
69
  option :accept_all_licenses, type: :boolean,
56
70
  aliases: ["--confirm-license", :a],
57
71
  desc: "Accept all license agreements"
@@ -134,8 +148,12 @@ module Fontist
134
148
  end
135
149
 
136
150
  desc "manifest-install MANIFEST", "Install fonts from MANIFEST (yaml)"
137
- option :accept_all_licenses, type: :boolean, aliases: "--confirm-license", desc: "Accept all license agreements"
138
- option :hide_licenses, type: :boolean, desc: "Hide license texts"
151
+ option :accept_all_licenses, type: :boolean,
152
+ aliases: ["--confirm-license", :a],
153
+ desc: "Accept all license agreements"
154
+ option :hide_licenses, type: :boolean,
155
+ aliases: :h,
156
+ desc: "Hide license texts"
139
157
  def manifest_install(manifest)
140
158
  handle_class_options(options)
141
159
  paths = Fontist::Manifest::Install.from_file(
@@ -196,10 +214,6 @@ module Fontist
196
214
 
197
215
  private
198
216
 
199
- def handle_class_options(options)
200
- Fontist.preferred_family = options[:preferred_family]
201
- end
202
-
203
217
  def success
204
218
  STATUS_SUCCESS
205
219
  end
@@ -12,6 +12,16 @@ module Fontist
12
12
  # it depends on this exception to automatically download formulas
13
13
  class FormulaIndexNotFoundError < GeneralError; end
14
14
 
15
+ class FormulaNotFoundError < GeneralError
16
+ def initialize(formula)
17
+ super(<<~MSG.chomp)
18
+ Formula '#{formula}' not found locally nor available in the Fontist formula repository.
19
+ Perhaps it is available at the latest Fontist formula repository.
20
+ You can update the formula repository using the command `fontist update` and try again.
21
+ MSG
22
+ end
23
+ end
24
+
15
25
  class MainRepoNotFoundError < FormulaIndexNotFoundError; end
16
26
 
17
27
  class InvalidResourceError < GeneralError; end
data/lib/fontist/font.rb CHANGED
@@ -14,6 +14,7 @@ module Fontist
14
14
  @smallest = options[:smallest]
15
15
  @newest = options[:newest]
16
16
  @size_limit = options[:size_limit]
17
+ @by_formula = options[:formula]
17
18
 
18
19
  check_or_create_fontist_path!
19
20
  end
@@ -48,6 +49,8 @@ module Fontist
48
49
  end
49
50
 
50
51
  def install
52
+ return install_formula if @by_formula
53
+
51
54
  (find_system_font unless @force) || download_font || manual_font ||
52
55
  raise_non_supported_font
53
56
  end
@@ -103,6 +106,22 @@ module Fontist
103
106
  end
104
107
  end
105
108
 
109
+ def install_formula
110
+ download_formula || raise_formula_not_found
111
+ end
112
+
113
+ def download_formula
114
+ formula = Formula.find_by_key(@name)
115
+ return unless formula
116
+ return unless formula.downloadable?
117
+
118
+ request_formula_installation(formula)
119
+ end
120
+
121
+ def raise_formula_not_found
122
+ raise Errors::FormulaNotFoundError.new(@name)
123
+ end
124
+
106
125
  def font_installer(formula)
107
126
  FontInstaller.new(formula, no_progress: @no_progress)
108
127
  end
@@ -148,13 +167,17 @@ module Fontist
148
167
  return if sufficient_formulas.empty?
149
168
 
150
169
  sufficient_formulas.flat_map do |formula|
151
- confirmation = check_and_confirm_required_license(formula)
152
- paths = font_installer(formula).install(confirmation: confirmation)
170
+ request_formula_installation(formula)
171
+ end
172
+ end
153
173
 
154
- Fontist.ui.say("Fonts installed at:")
155
- paths.each do |path|
156
- Fontist.ui.say("- #{path}")
157
- end
174
+ def request_formula_installation(formula)
175
+ confirmation = check_and_confirm_required_license(formula)
176
+ paths = font_installer(formula).install(confirmation: confirmation)
177
+
178
+ Fontist.ui.say("Fonts installed at:")
179
+ paths.each do |path|
180
+ Fontist.ui.say("- #{path}")
158
181
  end
159
182
  end
160
183
 
@@ -45,6 +45,13 @@ module Fontist
45
45
  end.flatten
46
46
  end
47
47
 
48
+ def self.find_by_key(key)
49
+ path = Fontist.formulas_path.join("#{key}.yml")
50
+ return unless File.exist?(path)
51
+
52
+ new_from_file(path)
53
+ end
54
+
48
55
  def self.new_from_file(path)
49
56
  data = YAML.load_file(path)
50
57
  new(data, path)
@@ -72,7 +79,7 @@ module Fontist
72
79
  end
73
80
 
74
81
  def key
75
- @data["key"] || default_key
82
+ key_from_path
76
83
  end
77
84
 
78
85
  def description
@@ -137,7 +144,7 @@ module Fontist
137
144
 
138
145
  private
139
146
 
140
- def default_key
147
+ def key_from_path
141
148
  escaped = Regexp.escape(Fontist.formulas_path.to_s + "/")
142
149
  @path.sub(Regexp.new("^" + escaped), "").sub(/\.yml$/, "")
143
150
  end
@@ -1,6 +1,6 @@
1
1
  module Fontist
2
2
  class GoogleCLI < Thor
3
- class_option :formulas_path, type: :string, desc: "Path to formulas"
3
+ include CLI::ClassOptions
4
4
 
5
5
  desc "check", "Check Google fonts for updates"
6
6
  def check
@@ -17,13 +17,5 @@ module Fontist
17
17
  Fontist::Import::GoogleImport.new.call
18
18
  CLI::STATUS_SUCCESS
19
19
  end
20
-
21
- private
22
-
23
- def handle_class_options(options)
24
- if options[:formulas_path]
25
- Fontist.formulas_path = Pathname.new(options[:formulas_path])
26
- end
27
- end
28
20
  end
29
21
  end
@@ -4,7 +4,7 @@ module Fontist
4
4
  module SystemHelper
5
5
  class << self
6
6
  def run(command)
7
- Fontist.ui.say("Run `#{command}`") if Fontist.debug?
7
+ Fontist.ui.debug("Run `#{command}`")
8
8
 
9
9
  result = `#{command}`
10
10
  unless $CHILD_STATUS.to_i.zero?
@@ -1,16 +1,14 @@
1
1
  module Fontist
2
2
  class ImportCLI < Thor
3
+ include CLI::ClassOptions
4
+
3
5
  desc "macos", "Create formula for on-demand macOS fonts"
4
6
  option :name, desc: "Example: Big Sur", required: true
5
7
  option :fonts_link,
6
8
  desc: "A link to a list of available fonts in a current OS",
7
9
  required: true
8
- option :formulas_path, type: :string, desc: "Path to formulas"
9
10
  def macos
10
- if options[:formulas_path]
11
- Fontist.formulas_path = Pathname.new(options[:formulas_path])
12
- end
13
-
11
+ handle_class_options(options)
14
12
  require_relative "import/macos"
15
13
  Import::Macos.new(options).call
16
14
  CLI::STATUS_SUCCESS
@@ -1,9 +1,12 @@
1
1
  module Fontist
2
2
  class RepoCLI < Thor
3
+ include CLI::ClassOptions
4
+
3
5
  desc "setup NAME URL",
4
6
  "Setup a custom fontist repo named NAME for the repository at URL " \
5
7
  "and fetches its formulas"
6
8
  def setup(name, url)
9
+ handle_class_options(options)
7
10
  Repo.setup(name, url)
8
11
  Fontist.ui.success(
9
12
  "Fontist repo '#{name}' from '#{url}' has been successfully set up.",
@@ -13,6 +16,7 @@ module Fontist
13
16
 
14
17
  desc "update NAME", "Update formulas in a fontist repo named NAME"
15
18
  def update(name)
19
+ handle_class_options(options)
16
20
  Repo.update(name)
17
21
  Fontist.ui.success(
18
22
  "Fontist repo '#{name}' has been successfully updated.",
@@ -24,6 +28,7 @@ module Fontist
24
28
 
25
29
  desc "remove NAME", "Remove fontist repo named NAME"
26
30
  def remove(name)
31
+ handle_class_options(options)
27
32
  Repo.remove(name)
28
33
  Fontist.ui.success(
29
34
  "Fontist repo '#{name}' has been successfully removed.",
@@ -35,6 +40,7 @@ module Fontist
35
40
 
36
41
  desc "list", "List fontist repos"
37
42
  def list
43
+ handle_class_options(options)
38
44
  Repo.list.each do |name|
39
45
  Fontist.ui.say(name)
40
46
  end
@@ -3,16 +3,36 @@ require "thor"
3
3
  module Fontist
4
4
  module Utils
5
5
  class UI < Thor
6
+ ALL_LEVELS = %i[debug info warn error fatal unknown].freeze
7
+
8
+ def self.level=(level)
9
+ unless ALL_LEVELS.include?(level)
10
+ raise Errors::GeneralError,
11
+ "Unknown log level: #{level.inspect}. " \
12
+ "Supported levels are #{ALL_LEVELS.map(&:inspect).join(', ')}."
13
+ end
14
+
15
+ @level = level
16
+ end
17
+
18
+ def self.level
19
+ @level || default_level
20
+ end
21
+
22
+ def self.default_level
23
+ :fatal
24
+ end
25
+
6
26
  def self.success(message)
7
- new.say(message, :green)
27
+ new.say(message, :green) if log_levels.include?(:info)
8
28
  end
9
29
 
10
30
  def self.error(message)
11
- new.say(message, :red)
31
+ new.say(message, :red) if log_levels.include?(:warn)
12
32
  end
13
33
 
14
34
  def self.say(message)
15
- new.say(message)
35
+ new.say(message) if log_levels.include?(:info)
16
36
  end
17
37
 
18
38
  def self.ask(message, options = {})
@@ -20,7 +40,16 @@ module Fontist
20
40
  end
21
41
 
22
42
  def self.print(message)
23
- super
43
+ super if log_levels.include?(:info)
44
+ end
45
+
46
+ def self.debug(message)
47
+ new.say(message) if log_levels.include?(:debug)
48
+ end
49
+
50
+ def self.log_levels
51
+ @log_levels ||= {}
52
+ @log_levels[@level] ||= ALL_LEVELS.drop_while { |l| l != level }
24
53
  end
25
54
  end
26
55
  end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.13.1".freeze
2
+ VERSION = "1.13.2".freeze
3
3
  end
data/lib/fontist.rb CHANGED
@@ -119,11 +119,7 @@ module Fontist
119
119
  @preferred_family = bool
120
120
  end
121
121
 
122
- def self.debug?
123
- @debug || false
124
- end
125
-
126
- def self.debug=(bool)
127
- @debug = bool
122
+ def self.log_level=(level)
123
+ Fontist.ui.level = level
128
124
  end
129
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fontist
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-26 00:00:00.000000000 Z
11
+ date: 2022-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -299,6 +299,7 @@ files:
299
299
  - fontist.gemspec
300
300
  - lib/fontist.rb
301
301
  - lib/fontist/cli.rb
302
+ - lib/fontist/cli/class_options.rb
302
303
  - lib/fontist/errors.rb
303
304
  - lib/fontist/font.rb
304
305
  - lib/fontist/font_installer.rb