Class: DevSystem::ConvertCommand

Inherits:
SimpleCommand show all
Defined in:
lib/dev_system/sub/shell/commands/convert_command.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#env

Instance Method Summary collapse

Methods inherited from SimpleCommand

#call, #log_simple_remember, #simple_arg, #simple_arg_ask, #simple_arg_ask_snakecase, #simple_args, #simple_boolean, #simple_boolean_no, #simple_boolean_yes, #simple_color, #simple_controller_placement, #simple_string

Methods inherited from BaseCommand

call, #call, get_command_signatures

Methods inherited from Command

call, #call, get_command_signatures

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Instance Method Details

#call_defaultObject

liza convert FORMAT FILENAME

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dev_system/sub/shell/commands/convert_command.rb', line 5

def call_default
  args = env[:args]
  log :lower, "args = #{args.inspect}"

  raise ArgumentError, "args[0] must be present" unless args[0]

  format = args[0].to_sym
  raise ArgumentError, "converter #{format.inspect} not found" unless DevBox.convert? format

  fname = args[1]
  raise ArgumentError, "fname must be present" unless FileShell.file? fname

  content = TextShell.read fname

  to_format = DevBox.converters[format][:to]
  fname = "#{fname}.#{to_format}"
  content = DevBox.convert format, content

  TextShell.write fname, content
end