fontist 1.18.2 → 1.19.0

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: 7df8791fd4754d729546380e67e6c29866f12e4d85bb917b427284c1be610dff
4
- data.tar.gz: be7991cacf763d3abc89aeea2841d02b4cc58b7e3a24c99551ee48639b07a3f8
3
+ metadata.gz: 2f726f1ac899163c9c7346d540f5bcaf831d522dd59f3e3afd5bed661560ea40
4
+ data.tar.gz: a94c77482bd16d9f751b2d3d713e13bf1aefd78703d7bba973c8d2649469035d
5
5
  SHA512:
6
- metadata.gz: 5ec6f6dfa9169caddd99e3641d05864d49bb1bfa2f59ae4887dd72b703c18c599628711fa5f414cb5863832f14751fddc7536cea549358eebbb926231eaf7651
7
- data.tar.gz: a87e924b0741861b59114ae75ea93a09ba86eb43510787501f20980a488ec3a181bba20ea0307e6b7f51f83d989c0edaf7db7ea1c74680534eec3280dc1a8d47
6
+ metadata.gz: 9d0fbfe9abf98ee2b28b2cf7f1aa73d0d3003519345d2f68f684043fb462f5df26a19a662e005ff07eb882923e3becbd52c616254ab6a704423a08f7c4588797
7
+ data.tar.gz: 74dd96f8a564fbcfab6d6372e0729b4aab1c3e80d14fd358626e8beaec505acdeb21b3e4de1eb589a13c9a490c8f595dc1e3ca40fc9650ae24dc29e68234a214
data/README.adoc CHANGED
@@ -306,11 +306,13 @@ Roboto Mono:
306
306
 
307
307
  Fontist supports system-wide settings for the following parameters:
308
308
 
309
+ `fonts_path`:: Sets path where to install fonts (default: `~/.fontist/fonts`)
310
+
309
311
  `open_timeout`:: Sets timeout for opening a connection during download
310
- (default: 10)
312
+ (default: `10`)
311
313
 
312
314
  `read_timeout`:: Sets timeout for reading the opened connection during download
313
- (default: 10)
315
+ (default: `10`)
314
316
 
315
317
  Show current attributes in the config:
316
318
 
@@ -377,7 +379,7 @@ List of all commands could be seen by:
377
379
  fontist help
378
380
  ----
379
381
 
380
- === Configuration
382
+ === Configuration with environment variables
381
383
 
382
384
  By default Fontist uses the `~/.fontist` directory to store fonts and its
383
385
  files. It could be changed with the `FONTIST_PATH` environment variable.
data/lib/fontist/cli.rb CHANGED
@@ -27,6 +27,7 @@ module Fontist
27
27
  STATUS_FONTCONFIG_NOT_FOUND = 14
28
28
  STATUS_FONTCONFIG_FILE_NOT_FOUND = 15
29
29
  STATUS_FONTIST_VERSION_ERROR = 15
30
+ STATUS_INVALID_CONFIG_ATTRIBUTE = 16
30
31
 
31
32
  ERROR_TO_STATUS = {
32
33
  Fontist::Errors::UnsupportedFontError => [STATUS_NON_SUPPORTED_FONT_ERROR],
@@ -15,42 +15,58 @@ module Fontist
15
15
  end
16
16
 
17
17
  def set(key, value)
18
+ attr = key.to_sym
19
+ unless default_values.key?(attr)
20
+ raise Errors::InvalidConfigAttributeError,
21
+ "No such attribute '#{attr}' exists."
22
+ end
23
+
18
24
  v = normalize_value(value)
19
- @custom_values[key.to_s] = v
25
+ if respond_to?("#{attr}=")
26
+ public_send("#{attr}=", v)
27
+ else
28
+ @custom_values[attr] = v
29
+ end
20
30
 
21
31
  persist
22
32
  end
23
33
 
24
34
  def delete(key)
25
- @custom_values.delete(key.to_s)
35
+ @custom_values.delete(key.to_sym)
26
36
 
27
37
  persist
28
38
  end
29
39
 
30
40
  def default_value(key)
31
- default_values[key.to_s]
41
+ default_values[key.to_sym]
32
42
  end
33
43
 
34
44
  def default_values
35
- { open_timeout: 10,
36
- read_timeout: 10 }.transform_keys(&:to_s)
45
+ { fonts_path: Fontist.fontist_path.join("fonts"),
46
+ open_timeout: 10,
47
+ read_timeout: 10 }
37
48
  end
38
49
 
39
50
  def persist
51
+ values = @custom_values.transform_keys(&:to_s)
40
52
  FileUtils.mkdir_p(File.dirname(Fontist.config_path))
41
- File.write(Fontist.config_path, YAML.dump(@custom_values))
53
+ File.write(Fontist.config_path, YAML.dump(values))
42
54
  end
43
55
 
44
56
  def load
45
57
  @custom_values = load_config_file
46
58
  end
47
59
 
60
+ def fonts_path=(value)
61
+ @custom_values[:fonts_path] = File.expand_path(value)
62
+ end
63
+
48
64
  private
49
65
 
50
66
  def load_config_file
51
67
  return {} unless File.exist?(Fontist.config_path)
52
68
 
53
- YAML.load_file(Fontist.config_path)
69
+ YAML.load_file(Fontist.config_path).transform_keys(&:to_sym)
54
70
  end
55
71
 
56
72
  def normalize_value(value)
@@ -2,15 +2,19 @@ module Fontist
2
2
  class ConfigCLI < Thor
3
3
  include CLI::ClassOptions
4
4
 
5
- STATUS_SUCCESS = 0
6
-
7
5
  desc "show", "Show values of the current config"
8
6
  def show
9
7
  handle_class_options(options)
10
8
  values = Config.instance.custom_values
11
- Fontist.ui.success("Current config:")
12
- Fontist.ui.success(format_hash(values))
13
- STATUS_SUCCESS
9
+
10
+ if values.empty?
11
+ Fontist.ui.success("Config is empty.")
12
+ else
13
+ Fontist.ui.success("Current config:")
14
+ Fontist.ui.success(format_hash(values))
15
+ end
16
+
17
+ CLI::STATUS_SUCCESS
14
18
  end
15
19
 
16
20
  desc "set KEY VALUE", "Set the KEY attribute to VALUE in the current config"
@@ -18,7 +22,10 @@ module Fontist
18
22
  handle_class_options(options)
19
23
  Config.instance.set(key, value)
20
24
  Fontist.ui.success("'#{key}' set to '#{value}'.")
21
- STATUS_SUCCESS
25
+ CLI::STATUS_SUCCESS
26
+ rescue Errors::InvalidConfigAttributeError => e
27
+ Fontist.ui.error(e.message)
28
+ CLI::STATUS_INVALID_CONFIG_ATTRIBUTE
22
29
  end
23
30
 
24
31
  desc "delete KEY", "Delete the KEY attribute from the current config"
@@ -28,13 +35,24 @@ module Fontist
28
35
  Fontist.ui.success(
29
36
  "'#{key}' reset to default ('#{Config.instance.default_value(key)}').",
30
37
  )
31
- STATUS_SUCCESS
38
+ CLI::STATUS_SUCCESS
39
+ end
40
+
41
+ desc "keys", "Print all available config attributes"
42
+ def keys
43
+ handle_class_options(options)
44
+ Fontist.ui.say("Available keys:")
45
+ Config.instance.default_values.each do |key, value|
46
+ Fontist.ui.say("#{key} (default: #{value})")
47
+ end
48
+ CLI::STATUS_SUCCESS
32
49
  end
33
50
 
34
51
  private
35
52
 
36
53
  def format_hash(hash)
37
- YAML.dump(hash).gsub(/^---.*$/, "").strip
54
+ h = hash.transform_keys(&:to_s)
55
+ YAML.dump(h).gsub(/^---.*$/, "").strip
38
56
  end
39
57
  end
40
58
  end
@@ -40,6 +40,8 @@ module Fontist
40
40
 
41
41
  class MainRepoNotFoundError < FormulaIndexNotFoundError; end
42
42
 
43
+ class InvalidConfigAttributeError < GeneralError; end
44
+
43
45
  class InvalidResourceError < GeneralError; end
44
46
 
45
47
  class LicensingError < GeneralError; end
@@ -1,3 +1,3 @@
1
1
  module Fontist
2
- VERSION = "1.18.2".freeze
2
+ VERSION = "1.19.0".freeze
3
3
  end
data/lib/fontist.rb CHANGED
@@ -37,7 +37,7 @@ module Fontist
37
37
  end
38
38
 
39
39
  def self.fonts_path
40
- Fontist.fontist_path.join("fonts")
40
+ Pathname.new(config[:fonts_path])
41
41
  end
42
42
 
43
43
  def self.formulas_repo_path
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.18.2
4
+ version: 1.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down