rest-terminal 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rest/terminal/commands.rb +9 -8
- data/lib/rest/terminal/persistent.rb +2 -0
- data/lib/rest/terminal.rb +16 -7
- data/lib/rest/version.rb +1 -1
- data/lib/service_base.rb +8 -3
- metadata +1 -1
@@ -49,7 +49,7 @@ module Rest
|
|
49
49
|
def _cd
|
50
50
|
fp = full_path(@prm[0])
|
51
51
|
if File.directory?("services#{fp}")
|
52
|
-
@pwd = fp
|
52
|
+
@cpath = @pwd = fp
|
53
53
|
else
|
54
54
|
fp = "Service not exists! #{fp}".red
|
55
55
|
end
|
@@ -76,7 +76,7 @@ module Rest
|
|
76
76
|
def _ls
|
77
77
|
path = Dir["#{current_path}*/"]
|
78
78
|
path.collect do |x|
|
79
|
-
puts x.sub(current_path,'
|
79
|
+
puts x.sub(current_path,'').sub(/\/$/,'')
|
80
80
|
end
|
81
81
|
@_status = "#{path.length} services"
|
82
82
|
# p "lolllll >>#{@serv}<< ."
|
@@ -89,32 +89,33 @@ module Rest
|
|
89
89
|
def _info
|
90
90
|
multi_exec(:_info)
|
91
91
|
@_status = ""
|
92
|
-
# @_status = @services[@
|
92
|
+
# @_status = @services[@cpath]._info(@prm)
|
93
93
|
end
|
94
94
|
|
95
95
|
def _response
|
96
|
-
@_status = @services[@
|
96
|
+
@_status = @services[@capth]._response(@prm)
|
97
97
|
end
|
98
98
|
|
99
99
|
def _headers
|
100
|
-
@_status = @services[@
|
100
|
+
@_status = @services[@cpath]._headers(@prm)
|
101
101
|
end
|
102
102
|
|
103
103
|
def _body
|
104
|
-
@_status = @services[@
|
104
|
+
@_status = @services[@cpath]._body(@prm)
|
105
105
|
end
|
106
106
|
|
107
107
|
def _vars
|
108
|
+
# p "CPATH: >>#{@cpath}<<"
|
108
109
|
if @prm.length>1 && !@prm[/\=/]
|
109
110
|
pth = @prm.shift
|
110
111
|
@_status = @services[pth]._vars(@prm)
|
111
112
|
else
|
112
|
-
@_status = @services[@
|
113
|
+
@_status = @services[@cpath]._vars(@prm)
|
113
114
|
end
|
114
115
|
end
|
115
116
|
|
116
117
|
def _reset
|
117
|
-
@_status = @services[@
|
118
|
+
@_status = @services[@cpath]._reset(@prm)
|
118
119
|
end
|
119
120
|
|
120
121
|
def _send
|
@@ -15,8 +15,10 @@ module Rest
|
|
15
15
|
end
|
16
16
|
pr = @services[@pwd]
|
17
17
|
path = Dir["#{current_path}*/"]
|
18
|
+
# p "CHILDPATH #{path.inspect} >>#{current_path}*/<<"
|
18
19
|
path.collect do |px|
|
19
20
|
p2 = px[/\/.*/]
|
21
|
+
# p "CHILD #{p2}"
|
20
22
|
@services[p2] = ServiceBase.new(pr,p2)
|
21
23
|
end
|
22
24
|
end
|
data/lib/rest/terminal.rb
CHANGED
@@ -23,6 +23,7 @@ module Rest
|
|
23
23
|
@prm = [ ]
|
24
24
|
@pwd = '/'
|
25
25
|
@cmd = ''
|
26
|
+
@cpath = ''
|
26
27
|
@_status = ''
|
27
28
|
end
|
28
29
|
|
@@ -53,16 +54,23 @@ module Rest
|
|
53
54
|
def load_state
|
54
55
|
if File.exists?('./.rest-terminal/persistent_rc.rb')
|
55
56
|
require './.rest-terminal/persistent_rc'
|
56
|
-
load_vars
|
57
|
+
load_vars
|
58
|
+
@cpath = @capth ? "#{@pwd}#{@cpath}/" : @pwd
|
57
59
|
load_services
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
63
|
+
# sometime command can include the child service
|
64
|
+
# Ex: rest vars@child
|
65
|
+
# old code for this action use @pwd as current service path
|
66
|
+
# new code for this action introduce @cpath as current path
|
61
67
|
def is_cmd_in_commands?
|
62
68
|
puts ARGV.inspect.red
|
63
|
-
|
64
|
-
parm
|
65
|
-
@
|
69
|
+
cmdp = ARGV[0].to_s.split('@')
|
70
|
+
parm = ARGV[1,99]
|
71
|
+
@cmd = cmdp[0]
|
72
|
+
@cpath = cmdp[1]
|
73
|
+
@prm = parm ? parm : [ ] #.join(' ') : ''
|
66
74
|
commands.index(@cmd) ? @cmd : nil
|
67
75
|
# if singleton_class.private_instance_methods(false).index(@@cmd.to_sym)
|
68
76
|
end
|
@@ -94,11 +102,11 @@ module Rest
|
|
94
102
|
end
|
95
103
|
|
96
104
|
def space_path(spc)
|
97
|
-
(spc[0] == '/') ? spc : "#{@
|
105
|
+
(spc[0] == '/') ? spc : "#{@cpath}#{spc}"
|
98
106
|
end
|
99
107
|
|
100
108
|
def full_path(spc)
|
101
|
-
x = "#{@
|
109
|
+
x = "#{@cpath} "
|
102
110
|
l = x.count('/')+1
|
103
111
|
dots = spc[/\.+/]
|
104
112
|
if dots &&
|
@@ -114,9 +122,10 @@ module Rest
|
|
114
122
|
def multi_exec(cmd)
|
115
123
|
@prm = ['.'] if @prm==[]
|
116
124
|
@prm.each do |prm|
|
117
|
-
prm = @
|
125
|
+
prm = @cpath if prm=='.'
|
118
126
|
pth = full_path(prm)
|
119
127
|
puts "Service: #{pth}".yellow
|
128
|
+
# puts @services.keys.inspect
|
120
129
|
@_status = @services[pth].send(cmd,prm)
|
121
130
|
end
|
122
131
|
end
|
data/lib/rest/version.rb
CHANGED
data/lib/service_base.rb
CHANGED
@@ -155,9 +155,14 @@ class ServiceBase
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def body_join
|
158
|
-
|
159
|
-
|
160
|
-
|
158
|
+
if headers[:"content-type"]=='application/json'
|
159
|
+
body = bodies.to_json
|
160
|
+
else
|
161
|
+
body = bodies.collect do |k,v|
|
162
|
+
"#{k}=#{v}"
|
163
|
+
end.join("&")
|
164
|
+
end
|
165
|
+
body
|
161
166
|
end
|
162
167
|
|
163
168
|
def set_value(key,prm)
|