class Xantora::CLI
Class responsible for the CLI
logic based on thor
Constants
- Error
Error
raised by this runner
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/xantora/cli.rb, line 13 def self.exit_on_failure? true end
Public Instance Methods
capture_stderr() { || ... }
click to toggle source
# File lib/xantora/cli.rb, line 68 def capture_stderr real_stderr = $stderr $stderr = StringIO.new yield $stderr.string ensure $stderr = real_stderr end
convert(source)
click to toggle source
# File lib/xantora/cli.rb, line 38 def convert(source) if File.directory? source puts "[.] Scanning #{source} directory for .adoc files ..." Dir.glob(File.join(source, "/**/pages/*.adoc")) { |file| convert_document(file, options) } elsif source.end_with? ".adoc" convert_document(source, options) else puts "[error] No valid source detected." exit 1 end end
convert_document(file, options)
click to toggle source
# File lib/xantora/cli.rb, line 51 def convert_document(file, options) doc = Document.new(file) spinner = TTY::Spinner.new( "[:spinner] Converting #{File.basename(doc.path)} to #{destination(doc, options)} ... ", format: :bouncing_ball ) spinner.auto_spin capture_stderr { doc.convert_to_pdf(options) } spinner.success "(successful)" rescue StandardError => e spinner.error("(error: #{e.message})") end
destination(doc, options)
click to toggle source
# File lib/xantora/cli.rb, line 64 def destination(doc, options) options[:output]&.end_with?(".pdf") ? File.basename(options[:output]) : doc.pdf_name end
version()
click to toggle source
# File lib/xantora/cli.rb, line 18 def version puts "v#{Xantora::VERSION}" end