Class: Togglate::CLI

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

Instance Method Summary collapse

Instance Method Details

#append_code(file) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/togglate/cli.rb', line 27

def append_code(file)
  text = File.read(file)
  opts = symbolize_keys(options)
  method = opts.delete(:method)
  code = Togglate.append_code(method, opts)
  puts "#{text}\n#{code}"
rescue => e
  STDERR.puts "something go wrong. #{e}"
  exit
end

#commentout(file) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/togglate/cli.rb', line 41

def commentout(file)
  text = File.read(file)
  comments, remains = Togglate.commentout(text, tag:options['tag'])
  puts options['remains'] ? remains : comments
rescue => e
  STDERR.puts "something go wrong. #{e}"
  exit
end

#create(file) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/togglate/cli.rb', line 12

def create(file)
  text = File.read(file)
  opts = symbolize_keys(options)
  blocks = [/^```/, /^{%/]
  opts.update(wrap_exceptions:blocks) if opts[:code_block]
  opts.update(translate:nil) if opts[:translate].empty?
  puts Togglate.create(text, opts)
rescue => e
  STDERR.puts "something go wrong. #{e}"
  exit
end

#versionObject



51
52
53
# File 'lib/togglate/cli.rb', line 51

def version
  puts "Togglate #{Togglate::VERSION} (c) 2014 kyoendo"
end