kscript 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kscript/plugins/kk_sh_utils.rb +23 -42
- data/lib/kscript/version.rb +1 -1
- metadata +6 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c49db2c8133bbc61a27f182bd4aa2920a3f6ba44aa957e989c81ea1ebde95b
|
4
|
+
data.tar.gz: f5bb31a125f117daffa3b4613c694e09982d396810e9ca089772e562115d6b38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f1c01ad2eb82ed4dc323ed9e926a4fd89ac9e9ad2c204fec077938bde8f98d50698e2f68cc08bcc3210947feb2d11e8408b567eea2aee95c0c9d800eb5384a8
|
7
|
+
data.tar.gz: 9c1f9ac7c23b94611ee489304ec32ee5e77c8d2c643acc107bab41e0c8476760d17f0c3728a6ee6310cca7806989e6e7f0f8faf0a79a033171073e9abf6758f3
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# https://opensource.org/licenses/MIT
|
7
7
|
|
8
8
|
require 'kscript'
|
9
|
+
require 'httpx'
|
9
10
|
|
10
11
|
module Kscript
|
11
12
|
class KkShUtils < Base
|
@@ -17,12 +18,17 @@ module Kscript
|
|
17
18
|
# @param command [String] command to get help for
|
18
19
|
def initialize(*args, **opts)
|
19
20
|
super(*args, **opts)
|
20
|
-
@command = args.
|
21
|
+
@command = args.join(' ').strip
|
21
22
|
end
|
22
23
|
|
23
|
-
def run
|
24
|
+
def run(*args, **_opts)
|
25
|
+
command = args.join(' ').strip
|
24
26
|
with_error_handling do
|
25
|
-
|
27
|
+
if command.nil? || command.strip.empty?
|
28
|
+
logger.kwarn("Usage: #{self.class.usage}")
|
29
|
+
else
|
30
|
+
fetch_help(command)
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -36,10 +42,11 @@ module Kscript
|
|
36
42
|
end
|
37
43
|
|
38
44
|
# Fetch and display command documentation
|
39
|
-
def fetch_help
|
40
|
-
response = make_request
|
41
|
-
|
42
|
-
|
45
|
+
def fetch_help(command)
|
46
|
+
response = make_request(command)
|
47
|
+
response = response.is_a?(Array) ? response.first : response
|
48
|
+
puts response.body
|
49
|
+
rescue StandardError => e
|
43
50
|
display_error(e)
|
44
51
|
end
|
45
52
|
|
@@ -65,41 +72,15 @@ module Kscript
|
|
65
72
|
|
66
73
|
private
|
67
74
|
|
68
|
-
# Make HTTP request to
|
69
|
-
# @return [
|
70
|
-
def make_request
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if response.status.success?
|
78
|
-
text = extract_plain_text(response.body)
|
79
|
-
logger.kinfo(text)
|
80
|
-
else
|
81
|
-
logger.kerror("Failed to retrieve data: #{response.status}")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# 提取纯文本内容
|
86
|
-
def extract_plain_text(body)
|
87
|
-
body = body.to_s
|
88
|
-
begin
|
89
|
-
doc = Nokogiri::HTML(body)
|
90
|
-
doc.search('script,style').remove
|
91
|
-
text = doc.text.lines.map(&:strip)
|
92
|
-
# 过滤掉包含广告/社交/Follow等内容的行
|
93
|
-
text = text.reject { |line| line =~ /Follow @|twitter|github|sponsor|donate|chubin|^!function/ }
|
94
|
-
text.reject!(&:empty?)
|
95
|
-
# 去除顶部多余空白行,只保留正文
|
96
|
-
text = text.drop_while(&:empty?)
|
97
|
-
text.join("\n")
|
98
|
-
rescue StandardError
|
99
|
-
body.gsub(/\e\[[\d;]*m/, '').lines.reject do |line|
|
100
|
-
line =~ /Follow @|twitter|github|sponsor|donate|chubin|^!function/
|
101
|
-
end.drop_while { |line| line.strip.empty? }.join
|
102
|
-
end
|
75
|
+
# Make HTTP request to cheat.sh
|
76
|
+
# @return [HTTPX::Response] response from cheat.sh
|
77
|
+
def make_request(command)
|
78
|
+
HTTPX.with(
|
79
|
+
headers: {
|
80
|
+
'User-Agent' => 'curl/8.0.1',
|
81
|
+
'Accept' => 'text/plain'
|
82
|
+
}
|
83
|
+
).get("https://cheat.sh/#{URI.encode_www_form_component(command)}")
|
103
84
|
end
|
104
85
|
|
105
86
|
# Display error message
|
data/lib/kscript/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kscript
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kk
|
@@ -59,25 +59,19 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: httpx
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- - "
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '4.0'
|
68
|
-
- - "<"
|
65
|
+
- - "~>"
|
69
66
|
- !ruby/object:Gem::Version
|
70
|
-
version: '
|
67
|
+
version: '1.5'
|
71
68
|
type: :runtime
|
72
69
|
prerelease: false
|
73
70
|
version_requirements: !ruby/object:Gem::Requirement
|
74
71
|
requirements:
|
75
|
-
- - "
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '4.0'
|
78
|
-
- - "<"
|
72
|
+
- - "~>"
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
74
|
+
version: '1.5'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: nokogiri
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|