Module: Aircana::CLI::Plugin

Defined in:
lib/aircana/cli/commands/plugin.rb

Overview

rubocop:disable Metrics/ModuleLength

Class Method Summary collapse

Class Method Details

.infoObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aircana/cli/commands/plugin.rb', line 11

def info # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  ensure_plugin_exists!

  manifest = PluginManifest.new(Aircana.configuration.plugin_root)
  data = manifest.read

  Aircana.human_logger.info("Plugin Information:")
  Aircana.human_logger.info("  Name: #{data["name"]}")
  Aircana.human_logger.info("  Version: #{data["version"]}")
  Aircana.human_logger.info("  Description: #{data["description"]}") if data["description"]

  # Display author information
  if data["author"]
    if data["author"].is_a?(Hash)
      Aircana.human_logger.info("  Author: #{data["author"]["name"]}")
      Aircana.human_logger.info("    Email: #{data["author"]["email"]}") if data["author"]["email"]
      Aircana.human_logger.info("    URL: #{data["author"]["url"]}") if data["author"]["url"]
    else
      Aircana.human_logger.info("  Author: #{data["author"]}")
    end
  end

  Aircana.human_logger.info("  License: #{data["license"]}") if data["license"]
  Aircana.human_logger.info("  Homepage: #{data["homepage"]}") if data["homepage"]
  Aircana.human_logger.info("  Repository: #{data["repository"]}") if data["repository"]

  Aircana.human_logger.info("  Keywords: #{data["keywords"].join(", ")}") if data["keywords"]&.any?

  Aircana.human_logger.info("\nManifest location: #{manifest.manifest_path}")
end

.updateObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
98
99
# File 'lib/aircana/cli/commands/plugin.rb', line 42

def update # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  ensure_plugin_exists!

  manifest = PluginManifest.new(Aircana.configuration.plugin_root)
  current_data = manifest.read

  prompt = TTY::Prompt.new

  # Build update hash with only fields that user wants to change
  updates = {}

  # Handle regular fields
  field_prompts = {
    "description" => "Description",
    "homepage" => "Homepage URL",
    "repository" => "Repository URL",
    "license" => "License"
  }

  field_prompts.each do |field, label|
    current = current_data[field]
    value = prompt.ask("#{label}:", default: current)
    updates[field] = value if value != current
  end

  # Handle author separately (object)
  if prompt.yes?("Update author information?", default: false)
    current_author = current_data["author"] || {}
    current_author = {} unless current_author.is_a?(Hash)

    author = {}
    author_name = prompt.ask("Author name:", default: current_author["name"])
    author["name"] = author_name if author_name && !author_name.empty?

    author_email = prompt.ask("Author email:", default: current_author["email"])
    author["email"] = author_email if author_email && !author_email.empty?

    author_url = prompt.ask("Author URL:", default: current_author["url"])
    author["url"] = author_url if author_url && !author_url.empty?

    updates["author"] = author unless author.empty?
  end

  # Handle keywords separately (array)
  if prompt.yes?("Update keywords?", default: false)
    current_keywords = (current_data["keywords"] || []).join(", ")
    keywords_input = prompt.ask("Keywords (comma-separated):", default: current_keywords)
    updates["keywords"] = keywords_input.split(",").map(&:strip) if keywords_input
  end

  if updates.empty?
    Aircana.human_logger.info("No changes made.")
    return
  end

  manifest.update(updates)
  Aircana.human_logger.success("Plugin manifest updated successfully!")
end

.validateObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



122
123
124
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
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/aircana/cli/commands/plugin.rb', line 122

def validate # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  Aircana.human_logger.info("Validating plugin structure...")

  errors = []

  # Check plugin manifest
  manifest = PluginManifest.new(Aircana.configuration.plugin_root)
  if manifest.exists?
    begin
      manifest.validate!
      Aircana.human_logger.success("✓ Plugin manifest is valid")
    rescue Aircana::Error => e
      errors << "Plugin manifest validation failed: #{e.message}"
    end
  else
    errors << "Plugin manifest not found at #{manifest.manifest_path}"
  end

  # Check directory structure
  %w[agents commands hooks].each do |dir|
    dir_path = File.join(Aircana.configuration.plugin_root, dir)
    if Dir.exist?(dir_path)
      Aircana.human_logger.success("✓ Directory exists: #{dir}/")
    else
      errors << "Missing directory: #{dir}/"
    end
  end

  # Check hooks manifest if hooks directory exists
  if Dir.exist?(Aircana.configuration.hooks_dir)
    hooks_manifest = HooksManifest.new(Aircana.configuration.plugin_root)
    if hooks_manifest.exists?
      begin
        hooks_manifest.validate!
        Aircana.human_logger.success("✓ Hooks manifest is valid")
      rescue Aircana::Error => e
        errors << "Hooks manifest validation failed: #{e.message}"
      end
    end
  end

  # Summary
  if errors.empty?
    Aircana.human_logger.success("\nPlugin validation passed! ✓")
  else
    Aircana.human_logger.error("\nValidation failed with #{errors.size} error(s):")
    errors.each { |error| Aircana.human_logger.error("  - #{error}") }
    exit 1
  end
end

.version(action = nil, bump_type = nil) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/aircana/cli/commands/plugin.rb', line 101

def version(action = nil, bump_type = nil) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  ensure_plugin_exists!

  manifest = PluginManifest.new(Aircana.configuration.plugin_root)

  case action
  when "bump"
    type = bump_type&.to_sym || :patch
    new_version = manifest.bump_version(type)
    Aircana.human_logger.success("Version bumped to #{new_version}")
  when "set"
    prompt = TTY::Prompt.new
    new_version = prompt.ask("New version:")
    manifest.update("version" => new_version)
    Aircana.human_logger.success("Version set to #{new_version}")
  else
    data = manifest.read
    Aircana.human_logger.info("Current version: #{data["version"]}")
  end
end