Class: Fontisan::UcdCli

Inherits:
Thor
  • Object
show all
Defined in:
lib/fontisan/cli/ucd_cli.rb

Overview

Thor subcommand for managing the local UCD (Unicode Character Database) cache used by fontisan audit.

fontisan ucd download [VERSION]   fetch + index UCDXML
fontisan ucd status               show what's cached
fontisan ucd path [VERSION]       print local cache path
fontisan ucd list                 list known versions
fontisan ucd remove VERSION       delete a cached version

With no arguments, download resolves the configured default version (see lib/fontisan/config/ucd.yml).

Instance Method Summary collapse

Instance Method Details

#download(version = nil) ⇒ Object

Download (and index) UCDXML for a version.

Parameters:

  • version (String, nil) (defaults to: nil)

    explicit version, or omit for default



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fontisan/cli/ucd_cli.rb', line 27

def download(version = nil)
  intent = resolve_intent(version, options[:latest])
  actual = Ucd::VersionResolver.resolve(intent)

  path = Ucd::Downloader.download(actual, force: options[:force])
  Ucd::IndexBuilder.build(actual) unless index_present?(actual)
  puts "UCD #{actual} ready at: #{path}"
rescue Ucd::Error => e
  warn "ERROR: #{e.message}"
  exit 1
end

#listObject

Print the curated list of versions this Fontisan release supports.



62
63
64
# File 'lib/fontisan/cli/ucd_cli.rb', line 62

def list
  Ucd::Config.known_versions.each { |v| puts v }
end

#path(version = nil) ⇒ Object

Print the cache directory path for a version (default: default version).

Parameters:

  • version (String, nil) (defaults to: nil)


52
53
54
55
56
57
58
# File 'lib/fontisan/cli/ucd_cli.rb', line 52

def path(version = nil)
  actual = Ucd::VersionResolver.resolve(version)
  puts Ucd::CacheManager.version_dir(actual)
rescue Ucd::UnknownVersionError => e
  warn "ERROR: #{e.message}"
  exit 1
end

#remove(version) ⇒ Object

Delete one cached version. No-op if absent.

Parameters:

  • version (String)


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fontisan/cli/ucd_cli.rb', line 70

def remove(version)
  Ucd::VersionResolver.validate!(version)
  unless Ucd::CacheManager.cached?(version)
    warn "Version #{version} is not cached; nothing to remove."
    return
  end

  Ucd::CacheManager.remove_version(version)
  puts "Removed UCD #{version}."
rescue Ucd::UnknownVersionError => e
  warn "ERROR: #{e.message}"
  exit 1
end

#statusObject

Print a one-screen summary of the local cache state.



41
42
43
44
45
46
# File 'lib/fontisan/cli/ucd_cli.rb', line 41

def status
  cached = Ucd::CacheManager.cached_versions
  puts "Default version: #{Ucd::Config.default_version}"
  puts "Cache root:      #{Ucd::CacheManager.root}"
  puts "Cached versions: #{cached.empty? ? '(none)' : cached.join(', ')}"
end