Class: Idml::CLI
- Inherits:
-
Thor
- Object
- Thor
- Idml::CLI
- Defined in:
- lib/idml/cli.rb
Overview
Command-line interface. Thin wrapper around the gem's public API — no business logic lives here. Each subcommand is a Thor method that delegates to Package, Document, Validation::Validator, or Composition::Prefix.
Instance Method Summary collapse
- #parts(path) ⇒ Object
- #prefix(path, prefix) ⇒ Object
- #render(path) ⇒ Object
- #round_trip(path) ⇒ Object
- #text(path, story_self = nil) ⇒ Object
- #validate(path) ⇒ Object
- #version ⇒ Object
Instance Method Details
#parts(path) ⇒ Object
17 18 19 |
# File 'lib/idml/cli.rb', line 17 def parts(path) package(path).part_names.each { |name| puts name } end |
#prefix(path, prefix) ⇒ Object
40 41 42 43 44 |
# File 'lib/idml/cli.rb', line 40 def prefix(path, prefix) result = Idml::Composition::Prefix.new(package(path)).call(prefix: prefix) FileUtils.cp(result.path, [:output]) puts "Wrote #{[:output]}" end |
#render(path) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/idml/cli.rb', line 76 def render(path) pkg = package(path) print_verbose(pkg) if [:verbose] Idml::Render.render(package: pkg, to: [:output], **) puts "Wrote #{[:output]}" rescue Idml::Errors::PackageNotFound => e warn "Error: #{e.}" exit 1 end |
#round_trip(path) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/idml/cli.rb', line 31 def round_trip(path) pkg = package(path) parts = pkg.each_part.to_a.to_h { |name, content| [name, content] } Idml::Package.write(parts: parts, to: [:output]) puts "Wrote #{[:output]}" end |
#text(path, story_self = nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/idml/cli.rb', line 48 def text(path, story_self = nil) doc = Idml::Document.new(package(path)) if story_self puts doc.story_text(story_self) else doc.each_story do |sid, body| puts "[#{sid}]" puts body puts end end end |
#validate(path) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/idml/cli.rb', line 22 def validate(path) validator = Idml::Validation::Validator.new results = validator.validate_package(package(path)) any_failure = print_validation_results(results) exit 1 if any_failure end |