Class: RosettAi::Thor::Tasks::Project

Inherits:
Thor
  • Object
show all
Defined in:
lib/rosett_ai/thor/tasks/project.rb

Overview

CLI task for rai project — project lifecycle management.

Provides commands for template application, drift detection, upstream synchronization, and project health reporting.

Author:

  • hugo

  • claude

Instance Method Summary collapse

Instance Method Details

#apply_template(name = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/rosett_ai/thor/tasks/project.rb', line 81

def apply_template(name = nil)
  if options[:list]
    list_templates
    return
  end

  raise RosettAi::ProjectError, 'Template name required' unless name

  applier = RosettAi::Project::TemplateApplier.new(
    project_root: resolve_project_root,
    template_name: name,
    force: options[:force]
  )
  results = applier.apply

  render_apply_results(results)
  exit 1 if results[:errors].any?
end

#driftObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/rosett_ai/thor/tasks/project.rb', line 117

def drift
  root = resolve_project_root
  validate_project!(root)

  detector = RosettAi::Project::DriftDetector.new(project_root: root)
  results = detector.detect(type: options[:type])

  if options[:format] == 'json'
    puts JSON.pretty_generate(results)
  else
    render_drift_results(results)
  end

  total_drift = results.values.flatten.size
  exit 4 if total_drift.positive?
end

#infoObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rosett_ai/thor/tasks/project.rb', line 53

def info
  manager = RosettAi::Project::Manager.new(project_root: resolve_project_root)
  result = manager.info

  rows = result.map { |key, value| [key.to_s.tr('_', ' ').capitalize, value.to_s] }
  table = ::Terminal::Table.new(
    title: ::I18n.t('rosett_ai.project.info_title'),
    rows: rows
  )
  puts table
end

#statusObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/rosett_ai/thor/tasks/project.rb', line 33

def status
  manager = RosettAi::Project::Manager.new(project_root: resolve_project_root)
  result = manager.status

  if options[:format] == 'json'
    puts JSON.pretty_generate(result)
  else
    render_status(result)
  end
end

#syncObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/rosett_ai/thor/tasks/project.rb', line 152

def sync
  sync_mgr = RosettAi::Project::SyncManager.new(
    project_root: resolve_project_root,
    force: options[:force]
  )

  results = options[:simulate] ? sync_mgr.simulate : sync_mgr.sync
  render_sync_results(results, simulate: options[:simulate])

  if results[:error]
    warn Rainbow("  Error: #{results[:error]}").red
    exit 1
  end
  exit 5 if results[:conflicts].any?
end