Class: MarshalParser::CLI::Commands::Tokens

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/marshal-parser/cli/commands.rb

Instance Method Summary collapse

Instance Method Details

#call(**options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/marshal-parser/cli/commands.rb', line 18

def call(**options)
  if options[:require]
    require options[:require]
  end

  dump = \
    if options[:file]
      File.read(options[:file])
    elsif options[:evaluate]
      Marshal.dump(eval(options[:evaluate]))
    else
      $stdin.read
    end

  lexer = MarshalParser::Lexer.new(dump)
  lexer.run

  formatter = \
    if options[:annotate]
      MarshalParser::Formatters::Tokens::WithDescription.new(lexer.tokens, dump, hex: options[:hex])
    else
      MarshalParser::Formatters::Tokens::OneLine.new(lexer.tokens, dump, hex: options[:hex])
    end

  puts formatter.string
end