Class: Clacky::CliExtensionCommands
- Inherits:
-
Thor
- Object
- Thor
- Clacky::CliExtensionCommands
- Defined in:
- lib/clacky/extension/cli_commands.rb
Overview
clacky ext <subcommand> — manage extension containers (ext.yml).
Containers contribute panels (WebUI) and api (HTTP backends). This command group scaffolds, verifies, lists and hot-reloads them.
Class Method Summary collapse
Instance Method Summary collapse
- #install(source) ⇒ Object
- #list ⇒ Object
- #new(id) ⇒ Object
- #pack(id) ⇒ Object
- #publish(id) ⇒ Object
- #published ⇒ Object
- #search(query = nil) ⇒ Object
- #unpublish(id) ⇒ Object
- #verify ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
12 13 14 |
# File 'lib/clacky/extension/cli_commands.rb', line 12 def self.exit_on_failure? true end |
Instance Method Details
#install(source) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/clacky/extension/cli_commands.rb', line 112 def install(source) res = Clacky::ExtensionPackager.install(source, force: [:force]) puts "Installed #{res.ext_id} → #{res.path}" puts "Reload the WebUI page to see any panels. No restart needed." rescue Clacky::ExtensionPackager::Error => e warn "Error: #{e.}" exit 1 end |
#list ⇒ Object
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 |
# File 'lib/clacky/extension/cli_commands.rb', line 67 def list result = Clacky::ExtensionLoader.load_all if result.units.empty? puts "No extension units resolved." return end grouped = result.units.group_by(&:ext_id) grouped.each do |ext_id, units| layer = units.first.layer origin = units.first.origin puts "#{ext_id} (#{layer}, origin=#{origin})" units.each do |u| case u.kind when :panel attach = Array(u.spec["attach"]) suffix = attach.empty? ? "" : " attach=#{attach.inspect}" puts " panel #{u.id}#{suffix}" when :api puts " api → /api/ext/#{ext_id}/" else puts " #{u.kind.to_s.ljust(6)} #{u.id}" end end end result.errors.each do |e| puts "[ERR] #{e.ext_id} #{e.unit} — #{e.}" end end |
#new(id) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clacky/extension/cli_commands.rb', line 19 def new(id) path = Clacky::ExtensionScaffold.new_container(id, full: [:full]) puts "Created extension container: #{path}" if [:full] puts "It contributes panels/api/skills/agents/channels/patches/hooks. Read its README.md, run `clacky ext verify`, then reload the WebUI." else puts "Reload the WebUI page to see the panel. Edits to view.js and handler.rb take effect on the next request — no restart needed." end rescue ArgumentError => e warn "Error: #{e.}" exit 1 end |
#pack(id) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/clacky/extension/cli_commands.rb', line 101 def pack(id) out = [:out] || Dir.pwd res = Clacky::ExtensionPackager.pack(id, out_dir: out) puts "Packed #{res.ext_id} → #{res.path}" rescue Clacky::ExtensionPackager::Error => e warn "Error: #{e.}" exit 1 end |
#publish(id) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/clacky/extension/cli_commands.rb', line 125 def publish(id) unless Clacky::Identity.load.bound? warn "Error: this device is not bound to a platform account. Authorize it first to publish." exit 1 end brand = Clacky::BrandConfig.load Dir.mktmpdir("clacky-ext-publish") do |tmp| res = Clacky::ExtensionPackager.pack(id, out_dir: tmp) zip_data = File.binread(res.path) result = brand.upload_extension!( res.ext_id, zip_data, force: [:force], status: [:status], changelog: [:changelog] ) if result[:success] ext = result[:extension] || {} ver = (ext["latest_version"] || {})["version"] puts "Published #{res.ext_id}#{ver ? " v#{ver}" : ""} → status=#{ext["status"]}" elsif result[:already_exists] warn "Error: #{res.ext_id} already published. Re-run with --force to publish a new version." exit 1 else warn "Error: #{result[:error]}" exit 1 end end rescue Clacky::ExtensionPackager::Error => e warn "Error: #{e.}" exit 1 end |
#published ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/clacky/extension/cli_commands.rb', line 161 def published brand = Clacky::BrandConfig.load result = brand.fetch_my_extensions! unless result[:success] warn "Error: #{result[:error]}" exit 1 end extensions = result[:extensions] if extensions.empty? puts "You have not published any extensions yet." return end extensions.each do |ext| ver = (ext["latest_version"] || {})["version"] || ext["version"] units = (ext["units"] || {}).map { |k, v| "#{v} #{k}" }.join(", ") puts "#{ext["name"]} v#{ver} [#{ext["status"]}]#{units.empty? ? "" : " (#{units})"}" end end |
#search(query = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/clacky/extension/cli_commands.rb', line 199 def search(query = nil) brand = Clacky::BrandConfig.load result = brand.search_extensions!(query: query, sort: [:sort]) unless result[:success] warn "Error: #{result[:error]}" exit 1 end extensions = result[:extensions] if extensions.empty? puts query ? "No extensions found for #{query.inspect}." : "No extensions available yet." return end extensions.each do |ext| emoji = ext["emoji"] || "🧩" ver = ext["version"] units = (ext["units"] || {}).map { |k, v| "#{v} #{k}" }.join(", ") name = ext["name_zh"] || ext["name"] puts "#{emoji} #{name}#{ver ? " v#{ver}" : ""}#{units.empty? ? "" : " (#{units})"}" desc = ext["description_zh"] || ext["description"] puts " #{desc}" if desc && !desc.to_s.strip.empty? end end |
#unpublish(id) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/clacky/extension/cli_commands.rb', line 184 def unpublish(id) brand = Clacky::BrandConfig.load result = brand.delete_extension!(id) if result[:success] puts "Unpublished #{id}." else warn "Error: #{result[:error]}" exit 1 end end |
#verify ⇒ Object
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 |
# File 'lib/clacky/extension/cli_commands.rb', line 33 def verify result = Clacky::ExtensionLoader.load_all if result.units.empty? && result.errors.empty? puts "No extension containers found." return end result.units.each do |u| case u.kind when :panel attach = Array(u.spec["attach"]) suffix = attach.empty? ? "" : ", attach=#{attach.inspect}" puts "[OK] #{u.ext_id}/#{u.id} (panel#{suffix}, #{u.layer})" when :api puts "[OK] #{u.ext_id} (api → /api/ext/#{u.ext_id}/, #{u.layer})" else puts "[OK] #{u.ext_id}/#{u.id} (#{u.kind}, #{u.layer})" end end issues = Clacky::ExtensionVerifier.verify(result) issues.each do |issue| tag = issue.level == :error ? "[ERR]" : "[WARN]" unit = issue.unit ? " #{issue.unit}" : "" loc = issue.file ? " [#{issue.file}]" : "" hint = issue.hint ? "\n hint: #{issue.hint}" : "" puts "#{tag} #{issue.ext}#{unit} (#{issue.code}) — #{issue.}#{loc}#{hint}" end exit 1 if issues.any? { |i| i.level == :error } end |