Class: AsciiChem::Cli
- Inherits:
-
Thor
- Object
- Thor
- AsciiChem::Cli
- Defined in:
- lib/asciichem/cli.rb
Overview
Thor-based command line interface. Invoked via the asciichem
executable (exe/asciichem).
Class Method Summary collapse
-
.banner(command, _namespace = nil, _subcommand = false) ⇒ Object
Override banner to use lowercase program name consistently.
Instance Method Summary collapse
Class Method Details
.banner(command, _namespace = nil, _subcommand = false) ⇒ Object
Override banner to use lowercase program name consistently.
77 78 79 |
# File 'lib/asciichem/cli.rb', line 77 def self.(command, _namespace = nil, _subcommand = false) "asciichem #{command.usage}" end |
Instance Method Details
#convert ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/asciichem/cli.rb', line 20 def convert source = read_source formula = AsciiChem.parse(source) puts render(formula, [:format]) rescue AsciiChem::ParseError => e warn "Parse error: #{e.}" exit 1 rescue AsciiChem::FormatError => e warn "Format error: #{e.}" exit 2 end |
#lint ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/asciichem/cli.rb', line 60 def lint formula = AsciiChem.parse([:input]) diagnostics = AsciiChem::Linter.run(formula) diagnostics.each { |d| puts d } exit diagnostics.any? { |d| d.severity == :error } ? 1 : 0 rescue AsciiChem::ParseError => e warn "Parse error: #{e.}" exit 1 end |
#parse_cml ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/asciichem/cli.rb', line 35 def parse_cml formula = AsciiChem::Cml.parse([:input]) puts formula.to_text rescue AsciiChem::Error => e warn "CML parse error: #{e.}" exit 1 end |
#roundtrip ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/asciichem/cli.rb', line 45 def roundtrip original = [:input] rendered = AsciiChem.parse(original).to_text if rendered == original puts rendered exit 0 else warn "round-trip mismatch:\n input: #{original.inspect}\n rendered: #{rendered.inspect}" exit 1 end end |