kscript 0.1.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa60e97dd2e5ebd0282945488335f81226666cc547f74608eb5b6d04370eec69
4
- data.tar.gz: 628577d54846ee750cf65e648bb13bce7c286182b49ef52813edb551b182a6f2
3
+ metadata.gz: a72c639d7028f3032a3ab8d6508308cd174a1174f698d5099f86356b1bef9f31
4
+ data.tar.gz: 898a2845e93a58bb1760a92850b091b84fcd374d92b138c13022e85dc6868877
5
5
  SHA512:
6
- metadata.gz: 79c677939e03109beac01c935773433218d95b663f7a4fea56980d3e6dbfc652eaadec7ed37ce1da38e77089cd6ff7524631e46a7dda71744e3868d8badf1734
7
- data.tar.gz: f29744a4e376a0476f91ee3a5788cd713f7a5c333114a3e4ef3616f5b3cb45783cceaca02b5798b2bf88c3038a28c50fe168d9e08c4700c31a5c3fd48376687c
6
+ metadata.gz: 869a3dfa24680f0c6e95cbdb82f0d8e6f981f5868d5f5c30b0183b7d2490b64ee2ce670e08190f095eea1291f26c31293e215759ee9545eab2a1d602b36a9bba
7
+ data.tar.gz: 5d24ef70c21851e42b337fd8e0222d50bb9f0def1e61a0121e2edaac8eb5fd16d4233adb8560e428eada8ee5e312a2c717f5ce30826c93891988861a38ee6260
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # kscript
2
+
2
3
  ```
3
4
  ______ _____ _____
4
5
  ___ /________________________(_)_________ /_
@@ -8,20 +9,32 @@ _ ,< _(__ )/ /__ _ / _ / __ /_/ / /_
8
9
  /_/
9
10
  ```
10
11
 
11
- A collection of Ruby utility scripts for various system administration and development tasks.
12
+ [![Gem Version](https://img.shields.io/gem/v/kscript?style=flat-square)](https://rubygems.org/gems/kscript)
13
+ [![CI Status](https://github.com/kevin197011/kscript/actions/workflows/gem-push.yml/badge.svg?branch=main)](https://github.com/kevin197011/kscript/actions/workflows/gem-push.yml)
14
+
15
+ > Ruby CLI 工具集,专为系统运维、开发自动化、网络与项目管理场景设计。支持插件化、极致美化输出、自动补全、结构化日志、CI/CD 自动发布等现代特性。
16
+
17
+ ---
12
18
 
13
- [![Gem Version](https://img.shields.io/gem/v/kscript)](https://rubygems.org/gems/kscript)
14
- [![Ruby](https://github.com/kevin197011/kscript/actions/workflows/gem-push.yml/badge.svg)](https://github.com/kevin197011/kscript/actions/workflows/gem-push.yml)
19
+ ## ✨ 特性亮点
20
+ - **统一 CLI 框架**:所有命令一键调用,美化输出
21
+ - **插件化架构**:业务命令即插件,易扩展、易维护
22
+ - **极致美化**:ASCII banner、彩色分组、对齐、分隔线,极客体验
23
+ - **人性化/结构化日志双模式**:`--log`/`--log-level` 切换,支持 JSON/终端友好输出
24
+ - **自动补全**:zsh/bash 补全脚本自动部署,命令一键补全
25
+ - **参数健壮**:所有插件兼容多余参数,支持全局参数过滤
26
+ - **CI/CD 自动发布**:GitHub Actions 自动构建并推送 RubyGem
27
+ - **多平台支持**:macOS、Linux、Windows(部分工具)
15
28
 
16
- ## Installation
29
+ ---
17
30
 
18
- ### Gem install (recommended)
31
+ ## 🚀 安装
19
32
 
20
33
  ```bash
21
34
  gem install kscript
22
35
  ```
23
36
 
24
- Or from local source:
37
+ 或源码安装:
25
38
 
26
39
  ```bash
27
40
  git clone https://github.com/kevin197011/kscript.git
@@ -30,140 +43,130 @@ gem build kscript.gemspec
30
43
  gem install ./kscript-*.gem
31
44
  ```
32
45
 
33
- ### Bundler (for development)
34
-
35
- ```bash
36
- git clone https://github.com/kevin197011/kscript.git
37
- cd kscript
38
- bundle install
39
- ```
40
-
41
- ## Usage
46
+ ---
42
47
 
43
- Most scripts can be executed directly via command line after gem install:
48
+ ## 🛠️ 快速上手
44
49
 
50
+ ### 查看所有命令
45
51
  ```bash
46
- kscript SCRIPT_NAME [args]
52
+ kscript list
47
53
  ```
48
54
 
49
- Or, for legacy usage via curl:
50
-
55
+ ### 查看主命令帮助
51
56
  ```bash
52
- curl -sSL https://raw.githubusercontent.com/kevin197011/kscript/main/bin/SCRIPT_NAME.rb | ruby
57
+ kscript help
53
58
  ```
54
59
 
55
- ## Available Scripts
56
-
57
- ### System Tools
58
- - `mac-top-usage.rb` - Display top CPU and memory usage processes on macOS
59
- - `port-scanner.rb` - Multi-threaded port scanner
60
- - `mouse-simulator.rb` - Simulate mouse movement to prevent system idle
61
- - `source-cleaner.rb` - Clean up old source code versions
62
- - `ffmpeg-installer.rb` - FFmpeg installation script for Linux systems
63
-
64
- ### Network Tools
65
- - `ip-api.rb` - Query IP geolocation information (supports auto-detecting public IP)
66
- - `apnic-ip-range.rb` - Fetch IP ranges from APNIC database
67
- - `wireguard-acl.rb` - Configure WireGuard firewall access control
68
- - `wireguard-password.rb` - Generate WireGuard password hashes
69
-
70
- ### Development Tools
71
- - `shell-helper.rb` - Quick shell command reference tool
72
- - `rename.rb` - Batch rename files using regular expressions
73
- - `jenkins-job-manager.rb` - Manage Jenkins jobs (export/import)
74
- - `kibana-utils.rb` - Kibana management utilities
75
-
76
- ### Windows Specific
77
- - `windows-font-enhancer.rb` - Enhance Windows font rendering (macOS-like)
78
-
79
- ### Infrastructure Tools
80
- - `elastic-cert-fingerprint.rb` - Generate Elasticsearch certificate fingerprints
81
- - `lvm-mounter.rb` - LVM volume creation and mounting utility
82
-
83
- ## Examples
84
-
85
- 1. Query IP geolocation:
60
+ ### 查看版本
86
61
  ```bash
87
- # Query specific IP
88
- curl -sSL https://raw.githubusercontent.com/kevin197011/kscript/main/bin/ip-api.rb | ruby 8.8.8.8
89
-
90
- # Query your public IP
91
- curl -sSL https://raw.githubusercontent.com/kevin197011/kscript/main/bin/ip-api.rb | ruby
62
+ kscript version
92
63
  ```
93
64
 
94
- 2. View system resource usage:
65
+ ### 执行插件命令
95
66
  ```bash
96
- curl -sSL https://raw.githubusercontent.com/kevin197011/kscript/main/bin/mac-top-usage.rb | ruby
67
+ kscript <command> [args...]
68
+ # 例如
69
+ kscript apnic CN
70
+ kscript portscan 192.168.1.1
71
+ kscript sh 'ls -l'
72
+ kscript projscan ~/projects
97
73
  ```
98
74
 
99
- 3. Scan ports:
75
+ ### 结构化日志模式
100
76
  ```bash
101
- curl -sSL https://raw.githubusercontent.com/kevin197011/kscript/main/bin/port-scanner.rb | ruby
77
+ kscript apnic CN --log
78
+ kscript portscan 192.168.1.1 --log-level=debug
102
79
  ```
103
80
 
104
- ## Dependencies
81
+ ---
82
+
83
+ ## 🧩 插件与命令一览
84
+
85
+ > 运行 `kscript list` 可分组美化展示所有插件命令
86
+
87
+ - **network**
88
+ - `apnic`:获取国家 IPv4 段
89
+ - `portscan`:端口扫描
90
+ - `ip`:IP 工具
91
+ - `wg_acl`:WireGuard 防火墙 ACL
92
+ - `wg_pass`:WireGuard 密码工具
93
+ - **project**
94
+ - `projscan`:扫描目录下所有 git 项目
95
+ - `cleaner`:源码多版本清理
96
+ - `rename`:批量重命名文件
97
+ - **system/macos**
98
+ - `syscheck`:macOS 系统健康检查
99
+ - `top`:macOS 资源占用排行
100
+ - `optimize`:macOS 性能优化
101
+ - `sh`:命令行速查/cheatsheet
102
+ - **media**
103
+ - `ffmpeg`:FFmpeg 安装与检测
104
+ - **elastic**
105
+ - `es_fingerprint`:Elasticsearch 证书指纹
106
+ - `kibana`:Kibana 空间/索引/用户/角色自动化
107
+ - **ci**
108
+ - `jenkins`:Jenkins Job 导入导出
109
+ - **其它**
110
+ - `usd`:美元汇率工具
111
+ - `lvm`:LVM 卷管理
112
+ - `windows_font_enhancer`:Windows 字体增强
113
+
114
+ ---
115
+
116
+ ## ⚡ Shell 自动补全
117
+
118
+ - **首次运行自动为 zsh/bash 部署补全脚本**,无需手动操作
119
+ - 补全脚本路径:
120
+ - zsh: `~/.zsh/completions/_kscript`
121
+ - bash: `~/.bash_completion.d/kscript`
122
+ - 手动生成:
123
+ ```bash
124
+ kscript completion zsh > ~/.zsh/completions/_kscript
125
+ kscript completion bash > ~/.bash_completion.d/kscript
126
+ ```
127
+
128
+ ---
129
+
130
+ ## ⚙️ 全局配置
131
+
132
+ 在 `~/.kscriptrc` (YAML) 配置全局参数:
105
133
 
106
- Required gems:
107
- ```ruby
108
- gem 'http'
109
- gem 'rubocop'
134
+ ```yaml
135
+ log_level: debug
110
136
  ```
111
137
 
112
- ## License
138
+ ---
113
139
 
114
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
140
+ ## 🧑‍💻 插件开发规范
141
+ - 插件文件统一放在 `lib/kscript/plugins/kk_xxx_utils.rb`
142
+ - 类名如 `KkApnicUtils`,自动注册为 `apnic` 命令
143
+ - 支持 `self.description`、`self.usage`、`self.arguments`、`self.group`、`self.author`
144
+ - 输出统一用 `logger.kinfo`/`logger.kerror`,支持结构化日志
145
+ - 兼容多余参数,避免 ArgumentError
115
146
 
116
- ## Contributing
147
+ ---
117
148
 
118
- 1. Fork it
119
- 2. Create your feature branch (`git checkout -b feature/my-new-feature`)
120
- 3. Commit your changes (`git commit -am 'Add some feature'`)
121
- 4. Push to the branch (`git push origin feature/my-new-feature`)
122
- 5. Create new Pull Request
149
+ ## 🚚 CI/CD 自动发布
123
150
 
124
- ## Unified CLI Usage
151
+ - `.github/workflows/gem-push.yml`:main 分支和 PR 自动构建、tag push 自动发布到 RubyGems
152
+ - 需在 GitHub secrets 配置 `RUBYGEMS_API_KEY`
153
+ - [CI 状态与历史](https://github.com/kevin197011/kscript/actions/workflows/gem-push.yml)
125
154
 
126
- After gem install, you can use the unified kk command:
155
+ ---
127
156
 
128
- ```bash
129
- kk <command> [args...]
157
+ ## 📄 许可证
130
158
 
131
- # List all available tools
132
- kk --help
159
+ MIT License. 详见 [LICENSE](LICENSE)。
133
160
 
134
- # Example: scan ports
135
- kk port-scanner 192.168.1.1
136
-
137
- # Example: check macOS system
138
- kk mac-sys-check
139
- ```
161
+ ---
140
162
 
141
- Each subcommand supports --help for its own usage.
163
+ ## 🤝 贡献
142
164
 
143
- ## Global Configuration
165
+ 1. Fork & PR
166
+ 2. 遵循输出与插件开发规范
167
+ 3. 保持文档与代码同步
144
168
 
145
- You can set global options for all kk tools in `~/.kscriptrc` (YAML format):
146
-
147
- ```yaml
148
- log_level: debug
149
- trace_id: my-global-trace
150
- ```
151
-
152
- - These settings will be used by default for all commands unless overridden by CLI options or environment variables.
153
-
154
- ## Shell Completion 自动补全
155
-
156
- kscript 现已支持 zsh 和 bash 的命令自动补全,且**安装后首次运行会自动为你部署补全脚本**,无需手动操作。
157
-
158
- - **zsh 补全脚本路径**:`~/.zsh/completions/_kscript`
159
- - **bash 补全脚本路径**:`~/.bash_completion.d/kscript`
160
-
161
- 如需手动重新生成补全脚本,可运行:
162
-
163
- ```bash
164
- kscript completion zsh > ~/.zsh/completions/_kscript
165
- kscript completion bash > ~/.bash_completion.d/kscript
166
- ```
169
+ ---
167
170
 
168
- > 每次升级或新增命令后,补全脚本也会自动更新。
171
+ 如需更多示例、插件开发指导或遇到问题,欢迎提 issue 或 PR!
169
172
 
data/Rakefile CHANGED
@@ -33,3 +33,10 @@ task :dev do
33
33
  kscript version
34
34
  SHELL
35
35
  end
36
+
37
+ task :install do
38
+ sh <<-SHELL
39
+ gem uninstall kscript -aIx
40
+ gem install kscript
41
+ SHELL
42
+ end
data/kscript.gemspec CHANGED
@@ -27,7 +27,9 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ['lib']
28
28
 
29
29
  # Runtime dependencies
30
+ spec.add_dependency 'bcrypt', '>= 3.1', '< 4.0'
30
31
  spec.add_dependency 'http', '>= 4.0', '< 6.0'
32
+ spec.add_dependency 'nokogiri', '>= 1.13', '< 2.0'
31
33
  spec.add_dependency 'thor', '1.3.2'
32
34
 
33
35
  # Development dependencies
@@ -35,11 +37,4 @@ Gem::Specification.new do |spec|
35
37
  spec.metadata['rubygems_mfa_required'] = 'true'
36
38
 
37
39
  # spec.extensions = ['ext/install.rb'] # 已移除,防止 native extension build 错误
38
-
39
- spec.post_install_message = <<~MSG
40
- [kscript] Shell completion is available!
41
- To enable shell completion for your shell, please run:
42
- ruby ext/install.rb
43
- Or see README for more details.
44
- MSG
45
40
  end
data/lib/kscript/base.rb CHANGED
@@ -7,11 +7,9 @@ module Kscript
7
7
  class Base
8
8
  attr_reader :logger
9
9
 
10
- def initialize(service: nil, log_level: nil, trace_id: nil)
10
+ def initialize(service: nil, log_level: nil)
11
11
  config = defined?(Kscript::Utils::Config) ? Kscript::Utils::Config.load : nil
12
12
  log_level ||= config&.log_level || ENV['KSCRIPT_LOG_LEVEL'] || :info
13
- trace_id ||= config&.trace_id || ENV['KSCRIPT_TRACE_ID']
14
- @trace_id = trace_id
15
13
  @logger = Kscript::Logger.new(service: service || self.class.name, level: log_level)
16
14
  @logger.set_human_output(human_output?)
17
15
  end
@@ -24,12 +22,6 @@ module Kscript
24
22
  exit(1)
25
23
  end
26
24
 
27
- # 提供 trace_id 给 logger
28
- def logger
29
- @logger.define_singleton_method(:default_trace_id) { @trace_id } if @trace_id
30
- @logger
31
- end
32
-
33
25
  # 自动注册所有 Kscript::Base 的子类为插件
34
26
  def self.inherited(subclass)
35
27
  name = subclass.name.split('::').last
@@ -45,14 +45,12 @@ module Kscript
45
45
  end
46
46
 
47
47
  def log(level, message, context = {})
48
- trace_id = context[:trace_id] || (respond_to?(:default_trace_id) ? default_trace_id : nil) || SecureRandom.hex(8)
49
48
  entry = {
50
49
  timestamp: Time.now.utc.iso8601,
51
50
  level: level.to_s.upcase,
52
51
  service: @service,
53
52
  message: message,
54
- trace_id: trace_id,
55
- context: context.reject { |k, _| k == :trace_id }
53
+ context: context
56
54
  }
57
55
  @logger.send(level, entry.to_json)
58
56
  end
@@ -67,7 +65,7 @@ module Kscript
67
65
  svc = @service || 'kscript'
68
66
  trace = context[:trace_id] || (respond_to?(:default_trace_id) ? default_trace_id : nil) || '-'
69
67
  color = COLORS[level] || COLORS[:info]
70
- ctx_str = context.reject { |k, _| k == :trace_id }.map { |k, v| "#{k}=#{v}" }.join(' ')
68
+ ctx_str = context.map { |k, v| "#{k}=#{v}" }.join(' ')
71
69
  line = "[#{ts}] [#{lvl}] [#{svc}] [#{trace}] #{message}"
72
70
  line += " | #{ctx_str}" unless ctx_str.empty?
73
71
  $stdout.puts "#{color}#{line}#{COLORS[:reset]}"
data/lib/kscript/utils.rb CHANGED
@@ -24,10 +24,6 @@ module Kscript
24
24
  self['log_level']
25
25
  end
26
26
 
27
- def trace_id
28
- self['trace_id']
29
- end
30
-
31
27
  # 自动检测并安装 shell 补全脚本
32
28
  def self.ensure_completion_installed(shell = nil)
33
29
  shell ||= ENV['SHELL']
@@ -6,5 +6,5 @@
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
8
  module Kscript
9
- VERSION = '0.1.0'
9
+ VERSION = '1.0.1'
10
10
  end
data/lib/kscript.rb CHANGED
@@ -5,9 +5,26 @@
5
5
  # This software is released under the MIT License.
6
6
  # https://opensource.org/licenses/MIT
7
7
 
8
+ # Ruby 标准库
8
9
  require 'json'
9
10
  require 'logger'
10
11
  require 'securerandom'
12
+ require 'yaml'
13
+ require 'fileutils'
14
+ require 'base64'
15
+ require 'rexml/document'
16
+ require 'net/http'
17
+ require 'timeout'
18
+ require 'socket'
19
+ require 'open3'
20
+ require 'openssl'
21
+
22
+ # 第三方 gem
23
+ require 'http'
24
+ require 'bcrypt'
25
+ require 'nokogiri'
26
+ require 'thor'
27
+
11
28
  require 'kscript/plugins'
12
29
  require 'kscript/base'
13
30
  require 'kscript/logger'
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: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kk
@@ -10,6 +10,26 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2025-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4.0'
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: http
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -30,6 +50,26 @@ dependencies:
30
50
  - - "<"
31
51
  - !ruby/object:Gem::Version
32
52
  version: '6.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: nokogiri
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '1.13'
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '1.13'
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '2.0'
33
73
  - !ruby/object:Gem::Dependency
34
74
  name: thor
35
75
  requirement: !ruby/object:Gem::Requirement
@@ -104,11 +144,7 @@ licenses:
104
144
  - MIT
105
145
  metadata:
106
146
  rubygems_mfa_required: 'true'
107
- post_install_message: |
108
- [kscript] Shell completion is available!
109
- To enable shell completion for your shell, please run:
110
- ruby ext/install.rb
111
- Or see README for more details.
147
+ post_install_message:
112
148
  rdoc_options: []
113
149
  require_paths:
114
150
  - lib