Class: Cureutils::CLI

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

Overview

The class represents the cli interface

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/cureutils/cli.rb', line 23

def exit_on_failure?
  true
end

Instance Method Details

#date(fmt = '+%F %H:%M:%S @P') ⇒ Object

Original date command’s default is ‘+%a %b %e %H:%M:%S %Z %Y @P’ However, I would like to adopt this setting.



145
146
147
148
149
150
151
# File 'lib/cureutils/cli.rb', line 145

def date(fmt = '+%F %H:%M:%S @P')
  logic = DateLogic.new
  logic.opt_date(options[:date])
  logic.opt_file(options[:file])
  logic.format = fmt
  exit(logic.print_results)
end

#echoObject

rubocop:disable Metrics/AbcSize



126
127
128
129
130
131
132
133
# File 'lib/cureutils/cli.rb', line 126

def echo # rubocop:disable Metrics/AbcSize
  logic = EchoLogic.new
  logic.precure(options[:precure])
  logic.msg_attack(options[:attack])
  logic.nosleep(options[:quick])
  logic.style(options[:style])
  exit(logic.print_results)
end

#girlsObject

rubocop:disable Metrics/MethodLength



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cureutils/cli.rb', line 57

def girls # rubocop:disable Metrics/MethodLength
  girls = Precure.all_girls
  girls.delete(Cure.echo) unless options[:movie]
  if options['full-name'.to_sym]
    girls.each do |v|
      puts v.full_name
    end
  else
    girls.each do |v|
      puts v.human_name
    end
  end
end

#grep(default_pat = '[:precure_name:]', filename = nil) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/LineLength



91
92
93
94
95
96
97
98
99
100
# File 'lib/cureutils/cli.rb', line 91

def grep(default_pat = '[:precure_name:]', filename = nil) # rubocop:disable Metrics/AbcSize, Metrics/LineLength
  logic = GrepLogic.new
  logic.source_input(filename)
  logic.pattern(default_pat.clone, options['extended-regexp'.to_sym])
  # Check the file discriptor to check the pipe exists or not.
  logic.option_colorize($stdout.isatty)
  logic.option_only(options['only-matching'.to_sym])
  # Print matched lines.
  exit(logic.print_results)
end

#humanizeObject



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

def humanize
  logic = TranslateLogic.new
  logic.translate_from_to('[:precure_name:]', '[:human_name:]')
  logic.in = $stdin
  exit(logic.print_results)
end

#jankenObject



154
155
156
157
# File 'lib/cureutils/cli.rb', line 154

def janken
  logic = JankenLogic.new
  exit(logic.janken.to_i)
end

#precuresObject



75
76
77
78
79
80
81
82
# File 'lib/cureutils/cli.rb', line 75

def precures
  cures = Precure.all_girls
  cures.delete(Cure.echo) unless options[:movie]
  cures.map!(&:precure_name)
  cures.each do |v|
    puts v
  end
end

#tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]') ⇒ Object



103
104
105
106
107
108
# File 'lib/cureutils/cli.rb', line 103

def tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]')
  logic = TranslateLogic.new
  logic.in = $stdin
  logic.translate_from_to(pat_from, pat_to)
  exit(logic.print_results)
end

#transformObject



34
35
36
37
38
39
# File 'lib/cureutils/cli.rb', line 34

def transform
  logic = TranslateLogic.new
  logic.translate_from_to('[:human_name:]', '[:precure_name:]')
  logic.in = $stdin
  exit(logic.print_results)
end

#versionObject



29
30
31
# File 'lib/cureutils/cli.rb', line 29

def version
  puts "#{Cureutils.name} #{Cureutils::Version}"
end