xcurl 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/add_part_command.rb +7 -0
- data/lib/command.rb +2 -0
- data/lib/delete_part_command.rb +7 -0
- data/lib/execute_command.rb +24 -0
- data/lib/load_command.rb +6 -0
- data/lib/log.rb +13 -15
- data/lib/save_command.rb +6 -0
- data/lib/sessions.rb +35 -0
- data/lib/set_url_command.rb +7 -0
- data/lib/show_command.rb +6 -0
- data/lib/xcurl.rb +22 -74
- data/xcurl.gemspec +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98cc4b306bc2f9a3adabed89c1b02ddb30fc8dede6014bd3b4954225a117f10a
|
4
|
+
data.tar.gz: fce824351babef049d78e2c01f6195afc0806caabfdd45c509b09c685074d85b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55a36d198d603eb23bc8586b1522b92ce0eef07292527e0c56e1da099f20bac3ea6ebb1fa3380b8417a3568c44dfc9c6137875b13a23856a8ee91eabd8adcc7b
|
7
|
+
data.tar.gz: b49335f6021f537c6e14f11ab59083e74b89b73b14b727f6f1748fe0b3b139717434e9e0f1a81f9e2a8563fc4e8586666b2cdd395798d08b74ec55a38514cac3
|
data/Gemfile.lock
CHANGED
data/lib/command.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class ExecuteCommand < Command
|
2
|
+
def execute(session, cmd, log)
|
3
|
+
path = cmd.scan(/curl (.*)/).flatten.first
|
4
|
+
|
5
|
+
curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
|
6
|
+
|
7
|
+
out, err, status = Open3.capture3(curl_cmd)
|
8
|
+
|
9
|
+
log.log_cmd(curl_cmd)
|
10
|
+
|
11
|
+
if status.success?
|
12
|
+
data =
|
13
|
+
begin
|
14
|
+
JSON.pretty_generate(JSON.parse(out))
|
15
|
+
rescue JSON::ParserError => e
|
16
|
+
out
|
17
|
+
end
|
18
|
+
|
19
|
+
log.log_data_success(data)
|
20
|
+
else
|
21
|
+
log.log_data_error(err)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/load_command.rb
ADDED
data/lib/log.rb
CHANGED
@@ -5,35 +5,33 @@ class Log
|
|
5
5
|
@p = Pastel.new
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
puts @p.green("
|
8
|
+
def cmd_success(label, value)
|
9
|
+
puts @p.green("#{label} #{@p.yellow(value)}")
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
puts @p.green("
|
12
|
+
def log_key_value(key, value)
|
13
|
+
puts @p.green.bold("#{key}: #{@p.yellow(value)}")
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
puts @p.green
|
18
|
-
end
|
16
|
+
def log_key_values(key, values)
|
17
|
+
puts @p.green.bold(key)
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
puts @p.green.bold("Parts:")
|
23
|
-
session['parts'].each_with_index do |part, index|
|
24
|
-
puts " #{@p.blue(index)} - #{@p.yellow(part)}"
|
19
|
+
values.each_with_index do |value, index|
|
20
|
+
puts " #{@p.blue(index)} - #{@p.yellow(value)}"
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
|
-
def
|
24
|
+
def log_cmd(cmd)
|
29
25
|
puts @p.cyan("==> #{cmd}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def log_data_success(data)
|
30
29
|
puts ''
|
31
30
|
puts @p.green(data)
|
32
31
|
puts ''
|
33
32
|
end
|
34
33
|
|
35
|
-
def
|
36
|
-
puts @p.cyan("==> #{cmd}")
|
34
|
+
def log_data_error(data)
|
37
35
|
puts ''
|
38
36
|
puts @p.red(data)
|
39
37
|
puts ''
|
data/lib/save_command.rb
ADDED
data/lib/sessions.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'pastel'
|
2
|
+
|
3
|
+
class Sessions
|
4
|
+
def load_session(id)
|
5
|
+
ensure_home
|
6
|
+
|
7
|
+
if File.exist?("#{dir}/#{id}")
|
8
|
+
JSON.parse(File.read("#{dir}/#{id}"))
|
9
|
+
else
|
10
|
+
{
|
11
|
+
'id' => 'untitled',
|
12
|
+
'url' => nil,
|
13
|
+
'parts' => []
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_session(id, session)
|
19
|
+
ensure_home
|
20
|
+
|
21
|
+
session['id'] = id
|
22
|
+
|
23
|
+
File.write("#{dir}/#{id}", JSON.pretty_generate(session))
|
24
|
+
|
25
|
+
session
|
26
|
+
end
|
27
|
+
|
28
|
+
def dir
|
29
|
+
"#{ENV['HOME']}/.xcurl"
|
30
|
+
end
|
31
|
+
|
32
|
+
def ensure_home
|
33
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
34
|
+
end
|
35
|
+
end
|
data/lib/show_command.rb
ADDED
data/lib/xcurl.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'ostruct'
|
4
3
|
require 'open3'
|
5
4
|
require 'json'
|
6
5
|
require_relative './log'
|
6
|
+
require_relative './sessions'
|
7
|
+
require_relative './command'
|
8
|
+
require_relative './save_command'
|
9
|
+
require_relative './load_command'
|
10
|
+
require_relative './show_command'
|
11
|
+
require_relative './delete_part_command'
|
12
|
+
require_relative './add_part_command'
|
13
|
+
require_relative './set_url_command'
|
14
|
+
require_relative './execute_command'
|
7
15
|
|
8
16
|
class Xcurl
|
9
17
|
def self.start(session_id = nil)
|
10
18
|
puts "// loading '#{session_id}'" if session_id
|
11
19
|
|
12
20
|
log = Log.new
|
13
|
-
|
21
|
+
sessions = Sessions.new
|
22
|
+
|
23
|
+
session = sessions.load_session(session_id || 'untitled')
|
14
24
|
|
15
25
|
while true
|
16
26
|
print "[#{session['id']}] "
|
@@ -18,95 +28,33 @@ class Xcurl
|
|
18
28
|
cmd = gets.chomp
|
19
29
|
|
20
30
|
case cmd
|
31
|
+
when 'exit'
|
32
|
+
break
|
33
|
+
|
21
34
|
when 'quit'
|
22
35
|
break
|
23
36
|
|
24
37
|
when /save /
|
25
|
-
|
26
|
-
|
27
|
-
session = save_session(new_id, session)
|
38
|
+
session = SaveCommand.new.execute(sessions, session, cmd)
|
28
39
|
|
29
40
|
when /load /
|
30
|
-
|
31
|
-
|
32
|
-
session = load_session(id)
|
41
|
+
session = LoadCommand.new.execute(sessions, cmd)
|
33
42
|
|
34
43
|
when 'show'
|
35
|
-
|
44
|
+
ShowCommand.new.execute(session, log)
|
36
45
|
|
37
46
|
when /^delete /
|
38
|
-
|
39
|
-
|
40
|
-
deleted = session['parts'].delete_at(index_part)
|
41
|
-
|
42
|
-
log.deleted(deleted)
|
47
|
+
DeletePartCommand.new.execute(session, cmd, log)
|
43
48
|
|
44
49
|
when /^url /
|
45
|
-
|
46
|
-
|
47
|
-
session['url'] = url
|
48
|
-
|
49
|
-
log.url_set(url)
|
50
|
+
SetUrlCommand.new.execute(session, cmd, log)
|
50
51
|
|
51
52
|
when /^add /
|
52
|
-
|
53
|
-
|
54
|
-
session['parts'] << part
|
55
|
-
|
56
|
-
log.added(part)
|
53
|
+
AddPartCommand.new.execute(session, cmd, log)
|
57
54
|
|
58
55
|
when /^curl /
|
59
|
-
|
60
|
-
|
61
|
-
curl_cmd = "curl #{session['url']}/#{path} #{session['parts'].join(' ')}"
|
62
|
-
|
63
|
-
out, err, status = Open3.capture3(curl_cmd)
|
64
|
-
|
65
|
-
if status.success?
|
66
|
-
data =
|
67
|
-
begin
|
68
|
-
JSON.pretty_generate(JSON.parse(out))
|
69
|
-
rescue JSON::ParserError => e
|
70
|
-
out
|
71
|
-
end
|
72
|
-
|
73
|
-
log.result(curl_cmd, data)
|
74
|
-
else
|
75
|
-
log.error(curl_cmd, data)
|
76
|
-
end
|
56
|
+
ExecuteCommand.new.execute(session, cmd, log)
|
77
57
|
end
|
78
58
|
end
|
79
59
|
end
|
80
|
-
|
81
|
-
def self.load_session(id)
|
82
|
-
ensure_home
|
83
|
-
|
84
|
-
if File.exist?("#{dir}/#{id}")
|
85
|
-
JSON.parse(File.read("#{dir}/#{id}"))
|
86
|
-
else
|
87
|
-
{
|
88
|
-
'id' => 'untitled',
|
89
|
-
'url' => nil,
|
90
|
-
'parts' => []
|
91
|
-
}
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.save_session(id, session)
|
96
|
-
ensure_home
|
97
|
-
|
98
|
-
session['id'] = id
|
99
|
-
|
100
|
-
File.write("#{dir}/#{id}", JSON.pretty_generate(session))
|
101
|
-
|
102
|
-
session
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.dir
|
106
|
-
"#{ENV['HOME']}/.xcurl"
|
107
|
-
end
|
108
|
-
|
109
|
-
def self.ensure_home
|
110
|
-
Dir.mkdir(dir) unless Dir.exist?(dir)
|
111
|
-
end
|
112
60
|
end
|
data/xcurl.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew S Aguiar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -45,7 +45,16 @@ files:
|
|
45
45
|
- bin/setup
|
46
46
|
- bin/xcurl
|
47
47
|
- generate-gem
|
48
|
+
- lib/add_part_command.rb
|
49
|
+
- lib/command.rb
|
50
|
+
- lib/delete_part_command.rb
|
51
|
+
- lib/execute_command.rb
|
52
|
+
- lib/load_command.rb
|
48
53
|
- lib/log.rb
|
54
|
+
- lib/save_command.rb
|
55
|
+
- lib/sessions.rb
|
56
|
+
- lib/set_url_command.rb
|
57
|
+
- lib/show_command.rb
|
49
58
|
- lib/xcurl.rb
|
50
59
|
- xcurl.gemspec
|
51
60
|
homepage: https://github.com/andrewaguiar/xcurl
|