Class: Archsight::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/archsight/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/archsight/cli.rb', line 71

def self.exit_on_failure?
  true
end

Instance Method Details

#analyzeObject



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/archsight/cli.rb', line 221

def analyze
  configure_resources
  require "archsight/database"
  require "archsight/analysis"

  db = load_database_for_analysis
  analyses = filter_analyses(db)

  return puts("No analyses found#{" matching '#{options[:filter]}'" if options[:filter]}.") if analyses.empty?
  return print_analysis_dry_run(analyses) if options[:dry_run]

  results = execute_analyses(db, analyses)
  print_analysis_results(results)
  exit 1 if results.any?(&:failed?)
end

#consoleObject



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/archsight/cli.rb', line 151

def console
  configure_resources
  require "archsight/database"
  require "irb"

  db = Archsight::Database.new(Archsight.resources_dir, verbose: true)
  db.reload!

  puts "Database loaded. Available: db"
  binding.irb
end

#importObject



168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
211
212
213
214
215
# File 'lib/archsight/cli.rb', line 168

def import
  configure_resources
  require "archsight/database"
  require "archsight/import/executor"

  resources_dir = Archsight.resources_dir

  # Load all handlers
  require_import_handlers

  # Create database that loads from resources directory
  # Only load Import resources to avoid validation errors on incomplete resources
  db = Archsight::Database.new(resources_dir, verbose: options[:verbose], only_kinds: %w[Import BusinessActor], verify: false)

  if options[:dry_run]
    puts "Execution Plan:"
    executor = Archsight::Import::Executor.new(
      database: db,
      resources_dir: resources_dir,
      verbose: true,
      filter: options[:filter],
      force: options[:force]
    )
    executor.execution_plan
  else
    executor = Archsight::Import::Executor.new(
      database: db,
      resources_dir: resources_dir,
      verbose: options[:verbose],
      filter: options[:filter],
      force: options[:force]
    )
    executor.run!
    puts "All imports completed successfully."
  end
rescue Archsight::Import::InterruptedError
  # Graceful shutdown already handled by executor
  exit 130
rescue Archsight::Import::DeadlockError => e
  puts "Error: #{e.message}"
  exit 1
rescue Archsight::Import::ImportError => e
  puts "Error: #{e.message}"
  exit 1
rescue Archsight::ResourceError => e
  display_error_with_context(e.to_s)
  exit 1
end

#lintObject



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
# File 'lib/archsight/cli.rb', line 112

def lint
  configure_resources
  require "archsight/database"
  require "archsight/linter"
  require "archsight/helpers"

  db = Archsight::Database.new(Archsight.resources_dir, compute_annotations: false, verbose: true)
  begin
    db.reload!
  rescue Archsight::ResourceError => e
    display_error_with_context(e.to_s)
    exit 1
  end

  linter = Archsight::Linter.new(db)
  errors = linter.validate

  if errors.any?
    puts "Validation Errors (#{errors.count}):"
    errors.each { |error| display_error_with_context(error) }
    exit 1
  end

  puts "All validations passed!"
end

#template(kind = nil) ⇒ Object



139
140
141
142
143
144
145
146
147
148
# File 'lib/archsight/cli.rb', line 139

def template(kind = nil)
  require "archsight/template"
  require "archsight/resources"

  if kind.nil?
    list_kinds
  else
    puts Archsight::Template.generate(kind)
  end
end

#versionObject



238
239
240
# File 'lib/archsight/cli.rb', line 238

def version
  puts "archsight #{Archsight::VERSION}"
end

#webObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/archsight/cli.rb', line 91

def web
  configure_resources
  require "archsight/web/application"

  env = options[:production] ? :production : :development
  Archsight::Web::Application.configure_environment!(env, logging: options[:enable_logging])
  Archsight::Web::Application.set :reload_enabled, !options[:disable_reload]
  Archsight::Web::Application.set :inline_edit_enabled, options[:inline_edit]

  restart_enabled = options[:enable_restart] || ENV["ARCHSIGHT_RESTART_ENABLED"] == "true"
  restart_token = options[:restart_token] || ENV.fetch("ARCHSIGHT_RESTART_TOKEN", nil)
  Archsight::Web::Application.set :restart_enabled, restart_enabled
  Archsight::Web::Application.set :restart_token, restart_token
  Archsight::Web::Application.setup_mcp!
  Archsight::Web::Application.run!(port: options[:port], bind: options[:host])
rescue Archsight::ResourceError => e
  display_error_with_context(e.to_s)
  exit 1
end