Class: Sawarineko::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sawarineko/cli.rb

Overview

Handle command line interfaces logic.

Instance Method Summary collapse

Constructor Details

#initializeCLI

Initialize a CLi.



7
8
9
# File 'lib/sawarineko/cli.rb', line 7

def initialize
  @options = {}
end

Instance Method Details

#run(args = ARGV) ⇒ Object

Entry point for the application logic. Process command line arguments and run the Sawarineko.

args - An Array of Strings user passed.

Returns an Integer UNIX exit code.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sawarineko/cli.rb', line 17

def run(args = ARGV)
  @options, paths = Option.new.parse(args)
  source = if paths.empty?
             $stdin.read
           else
             IO.read(paths[0], encoding: @options[:encoding])
           end
  converter = Converter.new(@options[:encoding])
  puts converter.convert(source)
  0
end