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)


7
8
9
# File 'lib/archsight/cli.rb', line 7

def self.exit_on_failure?
  true
end

Instance Method Details

#analyzeObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/archsight/cli.rb', line 154

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



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/archsight/cli.rb', line 84

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



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
139
140
141
142
143
144
145
146
147
148
# File 'lib/archsight/cli.rb', line 101

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



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

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



72
73
74
75
76
77
78
79
80
81
# File 'lib/archsight/cli.rb', line 72

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

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

#versionObject



171
172
173
# File 'lib/archsight/cli.rb', line 171

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

#webObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/archsight/cli.rb', line 27

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]
  Archsight::Web::Application.set :restart_enabled, options[:enable_restart]
  Archsight::Web::Application.set :restart_token, options[: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