-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmake.rb
143 lines (116 loc) · 3.28 KB
/
make.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
44
45
46
47
48
49
50
51
52
53
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# encoding: utf-8
$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'claide'
# Loading this third-party gem will automatically cause CLAide to color some of
# its output.
require 'colored'
class BeverageMaker < CLAide::Command
self.abstract_command = true
self.description = 'Make delicious beverages from the comfort of your' \
'terminal.'
# This would normally default to `beverage-make`, based on the class’ name.
self.command = 'make'
def self.options
[
['--no-milk', 'Don’t add milk to the beverage'],
['--sweetener=[sugar|honey]', 'Use one of the available sweeteners'],
].concat(super)
end
def initialize(argv)
@add_milk = argv.flag?('milk', true)
@sweetener = argv.option('sweetener')
super
end
def validate!
super
if @sweetener && !%w(sugar honey).include?(@sweetener)
help! "`#{@sweetener}' is not a valid sweetener."
end
end
def run
puts '* Boiling water…'
sleep 1
if @add_milk
puts '* Adding milk…'
sleep 1
end
if @sweetener
puts "* Adding #{@sweetener}…"
sleep 1
end
end
# This command uses an argument for the extra parameter, instead of
# subcommands for each of the flavor.
class Tea < BeverageMaker
self.summary = 'Drink based on cured leaves'
self.description = <<-DESC
An aromatic beverage commonly prepared by pouring boiling hot
water over cured leaves of the Camellia sinensis plant.
The following flavors are available: black, green, oolong, and white.
DESC
self.arguments = [
CLAide::Argument.new(:FLAVOR, false),
]
def self.options
[['--iced', 'the ice-tea version']].concat(super)
end
def initialize(argv)
@flavor = argv.shift_argument
@iced = argv.flag?('iced')
super
end
def validate!
super
if @flavor.nil?
help! 'A flavor argument is required.'
end
unless %w(black green oolong white).include?(@flavor)
help! "`#{@flavor}' is not a valid flavor."
end
end
def run
super
puts "* Infuse #{@flavor} tea…"
sleep 1
if @iced
puts '* Cool off…'
sleep 1
end
puts '* Enjoy!'
end
end
# Unlike the Tea command, this command uses subcommands to specify the
# flavor.
#
# Which one makes more sense is up to you.
class Coffee < BeverageMaker
self.abstract_command = true
self.summary = 'Drink brewed from roasted coffee beans'
self.description = <<-DESC
Coffee is a brewed beverage with a distinct aroma and flavor
prepared from the roasted seeds of the Coffea plant.
DESC
def run
super
puts "* Grinding #{self.class.command} beans…"
sleep 1
puts '* Brewing coffee…'
sleep 1
puts '* Enjoy!'
end
class BlackEye < Coffee
self.summary = 'A Black Eye is dripped coffee with a double shot of ' \
'espresso'
end
class Affogato < Coffee
self.summary = 'A coffee-based beverage (Italian for "drowned")'
end
class CaPheSuaDa < Coffee
self.summary = 'A unique Vietnamese coffee recipe'
end
class RedTux < Coffee
self.summary = 'A Zebra Mocha combined with raspberry flavoring'
end
end
end
BeverageMaker.run(ARGV)