Class: Cureutils::CLI
- Inherits:
-
Thor
- Object
- Thor
- Cureutils::CLI
- Defined in:
- lib/cureutils/cli.rb
Overview
The class represents the cli interface
Class Method Summary collapse
Instance Method Summary collapse
-
#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.
- #echo ⇒ Object
- #girls ⇒ Object
- #grep(pat = '[:precure_name:]', filename = nil) ⇒ Object
- #humanize ⇒ Object
- #janken ⇒ Object
- #precures ⇒ Object
- #tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]') ⇒ Object
- #transform ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
22 23 24 |
# File 'lib/cureutils/cli.rb', line 22 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.
135 136 137 138 139 140 |
# File 'lib/cureutils/cli.rb', line 135 def date(fmt = '+%F %H:%M:%S @P') # -d, --date=STRING (YYYY-MM-DD or +-N days) print_time = create_time_obj([:date]) updated_fmt = update_fmt(print_time, fmt) puts print_time.strftime(updated_fmt) end |
#echo ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cureutils/cli.rb', line 111 def echo cure_name = [:precure] || 'echo' = EchoMode::TRANSFORM = EchoMode::TRANSFORM if [:transform] = EchoMode::ATTACK if [:attack] Rubicure::Girl.sleep_sec = 0 if [:quick] cure = Rubicure::Girl.config.find { |k, _v| k == cure_name.to_sym } unless cure $stderr.puts "No such precure #{cure_name}" exit(1) end if == EchoMode::TRANSFORM Cure.send(cure_name.to_sym).transform! elsif == EchoMode::ATTACK Cure.send(cure_name.to_sym).transform! Cure.send(cure_name.to_sym).attack! end end |
#girls ⇒ Object
38 39 40 41 42 |
# File 'lib/cureutils/cli.rb', line 38 def girls Rubicure::Girl.config.map { |_k, v| v[:human_name] }.uniq.each do |v| puts v end end |
#grep(pat = '[:precure_name:]', filename = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cureutils/cli.rb', line 54 def grep(pat = '[:precure_name:]', filename = nil) # Check whether the file is given or not @input = input_from(filename) extended_pat = ['extended-regexp'.to_sym] if extended_pat cure_pat = extended_pat else cure_pat = pregex2regex(pat) end # Check the file discriptor and check the pipe exists or not. pipe_flg = !$stdout.isatty if ['only-matching'.to_sym] if pipe_flg @input.each do |line| matched_strs = line.scan(/#{cure_pat}/) matched_strs.empty? || matched_strs.each do |str| puts str end end else @input.each do |line| matched_strs = line.scan(/#{cure_pat}/) matched_strs.empty? || matched_strs.each do |str| puts str.red end end end else if pipe_flg @input.each do |line| puts line.gsub(/#{cure_pat}/, '\0') if line =~ /#{cure_pat}/ end else @input.each do |line| puts line.gsub(/#{cure_pat}/, '\0'.red) if line =~ /#{cure_pat}/ end end end end |
#humanize ⇒ Object
33 34 35 |
# File 'lib/cureutils/cli.rb', line 33 def humanize print_converted_text($stdin, :precure_name, :human_name) end |
#janken ⇒ Object
143 144 145 146 |
# File 'lib/cureutils/cli.rb', line 143 def janken judge = JankenContoller.janken exit(judge.to_i) end |
#precures ⇒ Object
45 46 47 48 49 |
# File 'lib/cureutils/cli.rb', line 45 def precures Rubicure::Girl.config.map { |_k, v| v[:precure_name] }.uniq.each do |v| puts v end end |
#tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]') ⇒ Object
95 96 97 98 99 |
# File 'lib/cureutils/cli.rb', line 95 def tr(pat_from = '[:precure_name:]', pat_to = '[:human_name:]') pat_from = pregex2str(pat_from).to_sym pat_to = pregex2str(pat_to).to_sym print_converted_text($stdin, pat_from, pat_to) end |
#transform ⇒ Object
28 29 30 |
# File 'lib/cureutils/cli.rb', line 28 def transform print_converted_text($stdin, :human_name, :precure_name) end |