-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrbtcli.rb
More file actions
118 lines (103 loc) · 2.37 KB
/
rbtcli.rb
File metadata and controls
118 lines (103 loc) · 2.37 KB
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
# Copyright 2012-2013 Konstantin Lysenko
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# rbtcli.rb - client side
# usage: ruby rbtcli.rb --version
# rambutan 0.0.1 (c) 2012-2013 Konstantin Lysenko"
# usage: ruby rbtcli.rb --help
# user@host:~$ ruby rbtcli
# [00:00]> start 25:00
# Timer started at 00:00
# [00:01]>
# ...
# [03:12]> stop
# Timer stoped at 03:12
# [03:12]>
# ...
# [12:23]> check
# Timer is at 12:23
# [12:24]>
# ...
# [21:11]> reset
# Timer resetted to 00:00
# [00:00]>
# ...
# [25:00]> exit
# user@host:~$
# Temporary - need to be here till we transform rambutan app to gem
$LOAD_PATH << '.'
require "socket"
require "prompt"
require "mixlib/config"
require "mixlib/cli"
require "rambutan/version.rb"
extend Prompt::DSL
module Rambutan
class CLI
def run
end
def start
puts "Timer started at 00:00"
end
def stop
puts "Timer stopped at 25:00"
end
def check
puts "Timer is at 00:01"
end
def reset
puts "Timer reseted to 00:00"
end
def connect
host = "localhost"
print("Trying ", host, " ...")
STDOUT.flush
s = TCPSocket.open(host, 32768)
print(" done\n")
print("addr: ", s.addr.join(":"), "\n")
print("peer: ", s.peeraddr.join(":"), "\n")
while line = gets()
s.write(line)
print(s.readline)
end
s.close
end
end
# Module end
end
rcli = Rambutan::CLI.new
rcli.run
group "Timer"
param :timer_limit, "Time when to stop timer", %w(25:00)
desc "Start timer"
command "start" do |timer_limit|
rcli.start
end
desc "Stop timer"
command "stop" do
rcli.stop
end
desc "Reset timer"
command "reset" do
rcli.reset
end
desc "Check timer"
command "check" do
rcli.check
end
group "Service"
desc "Print version"
command "version" do
puts "rambutan #{Rambutan::VERSION} (c) 2012-2013 Konstantin Lysenko"
end
Prompt::Console.start