Class: Documinty::CLI
- Inherits:
-
Thor
- Object
- Thor
- Documinty::CLI
- Defined in:
- lib/documinty/cli.rb
Constant Summary collapse
- MAX_DESC_LENGTH =
80
Class Method Summary collapse
Instance Method Summary collapse
- #describe(path) ⇒ Object
- #doc(path) ⇒ Object
- #feat(name) ⇒ Object
- #features ⇒ Object
- #init ⇒ Object
- #involved_f(feature) ⇒ Object
- #methods(path) ⇒ Object
- #search_f(query) ⇒ Object
- #show(path) ⇒ Object
- #show_feature(feature) ⇒ Object
- #untag(path) ⇒ Object
- #update_description(path) ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
8 9 10 |
# File 'lib/documinty/cli.rb', line 8 def self.exit_on_failure? true end |
Instance Method Details
#describe(path) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'lib/documinty/cli.rb', line 256 def describe(path) entries = store.entries_for(path) # If a specific feature is requested, filter to those entries if [:feature] entries = entries.select { |e| Array(e['features'] || e['feature']).include?([:feature]) } end if entries.empty? if [:feature] say "❌ No description found for '#{path}' under feature '#{options[:feature]}'", :red else say "❌ No description found for '#{path}'", :red end exit(1) end entries.each do |e| desc_text = e['description'].to_s.strip if desc_text.empty? say "ℹ️ No description provided for '#{path}' under '#{e['feature']}'", :yellow else if [:feature] # Only one feature context say "📋 #{path}", :cyan else # Show which feature this description belongs to say( set_color("📋 #{path} ️", :cyan) + ": " + set_color("(FEATURE: #{e['feature']})", :magenta) ) end say "--→ #{desc_text}", :green end end end |
#doc(path) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/documinty/cli.rb', line 42 def doc(path) begin description = ask("Enter a brief description for this node⚙️:") methods_input = ask("Enter comma-separated methods for this node (or leave blank if none)🛠️:") method_syms = methods_input .split(",") .map(&:strip) .reject(&:empty?) .map(&:to_sym) entry = store.add_entry( path: path, node: [:node], feature: [:feature], methods: method_syms, timestamp: Time.now.iso8601, description: description, ) say "✅ Documented #{entry['path']} as #{entry['node']} under '#{entry['feature']}'", :green rescue Error => e say "❌ #{e.message}", :red exit(1) end end |
#feat(name) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/documinty/cli.rb', line 19 def feat(name) begin store.add_feature(name) say "✅ Created feature '#{name}'", :green rescue Error => e say "⚠️ #{e.message}", :red end end |
#features ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/documinty/cli.rb', line 29 def features fs = store.features if fs.empty? say "No features defined.", :yellow else say "Defined features:", :cyan fs.each { |f| say "• #{f}", :green } end end |
#init ⇒ Object
14 15 16 |
# File 'lib/documinty/cli.rb', line 14 def init store.init(codebase_name: [:codebase]) end |
#involved_f(feature) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/documinty/cli.rb', line 182 def involved_f(feature) begin entries = store.entries_for_feature(feature) rescue Error => e say "❌ #{e.message}", :red exit(1) end if entries.empty? say "No entries under '#{feature}'.", :yellow return end # Print the feature name in bold cyan say "🔖 #{feature}", :cyan # Group entries by their containing directory grouped = entries.group_by { |e| File.dirname(e['path']) } grouped.each do |dir, entries_in_dir| # Print each directory line with a folder emoji, in green say "📁 #{dir}", :green entries_in_dir.each do |e| # Print each filename line with a file emoji, indented, in green say " 📄 #{File.basename(e['path'])}", :green end end end |
#methods(path) ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/documinty/cli.rb', line 227 def methods(path) if [:action] != 'add' && [:action] != 'remove' say "❌ Action not supported must be 'add' OR 'remove'", :red exit(1) end methods_input = ask("Enter comma-separated methods to add to this node🛠️:") method_syms = methods_input .split(",") .map(&:strip) .reject(&:empty?) .map(&:to_sym) begin entry = store.methods( path: path, feature: [:feature], new_methods: method_syms, action: [:action].to_sym ) say "✅ Updated methods for #{entry['path']} under '#{entry['feature']}': #{Array(entry['methods']).join(', ')}", :green rescue Error => e say "❌ #{e.message}", :red exit(1) end end |
#search_f(query) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/documinty/cli.rb', line 214 def search_f(query) matches = store.features.select { |f| f.include?(query) } if matches.empty? say "❌ No features match '#{query}'", :red else say "Matching features:", :cyan matches.each { |f| say "• #{f}", :green } end end |
#show(path) ⇒ Object
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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/documinty/cli.rb', line 69 def show(path) entries = store.entries_for(path) # If a specific feature is requested, filter to those entries if [:feature] entries = entries.select { |e| Array(e['features'] || e['feature']).include?([:feature]) } end if entries.empty? if [:feature] say "❌ No documentation found for '#{path}' under feature '#{options[:feature]}'", :red else say "❌ No documentation found for '#{path}'", :red end exit(1) end entries.each do |e| label_color = :cyan value_color = :magenta # File say( set_color("File📄", label_color) + ": " + set_color(e['path'], value_color) ) # Node type say( set_color("Node type⚙️", label_color) + ": " + set_color(e['node'], value_color) ) # Features say( set_color("Features🏷️", label_color) + ": " + set_color(Array(e['features'] || e['feature']).join(", "), value_color) ) # Description (only if present) unless e['description'].to_s.empty? say( set_color("Description📝", label_color) + ": " + set_color(truncate(e['description']), value_color) ) end # Methods (only if present) if e['methods'] && !e['methods'].empty? say( set_color("Methods🛠️", label_color) + ": " + set_color(Array(e['methods']).join(", "), value_color) ) end # Timestamp say( set_color("Tagged at⏰", label_color) + ": " + set_color(e['timestamp'], value_color) ) say "-" * 40 end end |
#show_feature(feature) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/documinty/cli.rb', line 155 def show_feature(feature) begin entries = store.entries_for_feature(feature) rescue Error => e say "❌ #{e.message}", :red exit(1) end if entries.empty? say "No entries under '#{feature}'.", :red else say "Entries for '#{feature}':" label_color = :cyan value_color = :magenta entries.each do |e| # File say( set_color("📄#{e['path']} | ", label_color) + set_color("(#{e['node']}) – #{e['description']}", value_color) ) end end end |
#untag(path) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/documinty/cli.rb', line 142 def untag(path) begin removed = store.remove_entry(path: path, feature: [:feature]) removed.each do |e| say "🗑️ Removed #{e['path']} (#{e['node'] || e['node_type']}) from '#{options[:feature]}'", :green end rescue Error => e say "❌ #{e.message}", :red exit(1) end end |
#update_description(path) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/documinty/cli.rb', line 297 def update_description(path) begin new_desc = ask("Enter a new description for '#{path}' under '#{options[:feature]}':") entry = store.update_description( path: path, feature: [:feature], new_description: new_desc ) say "✅ Description updated for #{entry['path']} under '#{entry['feature']}':", :green say " #{entry['description']}", :green rescue Error => e say "❌ #{e.message}", :red exit(1) end end |