Class: GitFit::ExportCLI

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

Instance Method Summary collapse

Instance Method Details

#aiObject



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
# File 'lib/git_fit/cli/export.rb', line 87

def ai
  config = git_fit_config
  unless config.ai_config['enabled']
    say_status :warn, 'AI: ai.enabled is false, skipping (Fix: set ai.enabled: true or GIT_FIT_AI_ENABLED=true)',
               :yellow
    return
  end
  client = GitFit::LLM::Client.from_config(config)
  return if client.nil? # unreachable: disabled handled above

  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  path = options[:output] || config.export_config.dig('ai', 'path') || 'site/insights.json'
  doc = Export::AI.new(db: conn.db, config: config, client: client, output: path,
                       period: options[:period], language: options[:lang]).call
  if doc
    sections = %w[summary_markdown insights coaching].count { |k| doc[k] }
    say_status :done, "Exported AI insights to #{path} (#{sections}/3 sections)", :green
  else
    say_status :warn, 'AI: nothing to do (empty db or insights unchanged)', :yellow
  end
rescue GitFit::LLM::Error => e
  # AI failures are non-fatal by contract — CI deploys must not break.
  say_status :warn, e.message, :yellow
end

#csvObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/git_fit/cli/export.rb', line 35

def csv
  config = git_fit_config
  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  db = conn.db
  path = options[:output] || config.export_config.dig('csv', 'path') || 'site/workouts.csv'
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
  count = Export::CSV.new(db: db, output: path, activity_filter: filter).call
  say_status :done, "Exported #{count} activities to #{path}", :green
rescue StandardError => e
  say_status :error, "CSV export failed: #{e.message}", :red
end

#gpxObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/git_fit/cli/export.rb', line 52

def gpx
  config = git_fit_config
  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  db = conn.db
  path = options[:output] || config.export_config.dig('gpx', 'path') || 'site/gpx_out'
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
  count = Export::GPX.new(db: db, output: path, activity_filter: filter).call
  say_status :done, "Exported #{count} GPX files to #{path}/", :green
rescue StandardError => e
  say_status :error, "GPX export failed: #{e.message}", :red
end

#jsonObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/git_fit/cli/export.rb', line 17

def json
  config = git_fit_config
  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  db = conn.db
  path = options[:output] || config.export_config.dig('json', 'path') || 'site/activities.json'
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
  count = Export::JSON.new(db: db, output: path, activity_filter: filter,
                           tracks_output: options[:tracks_output]).call
  say_status :done, "Exported #{count} activities to #{path}", :green
rescue StandardError => e
  say_status :error, "JSON export failed: #{e.message}", :red
end

#statsObject



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/git_fit/cli/export.rb', line 69

def stats
  config = git_fit_config
  conn = GitFit::DB::Connection.new(config.db_path)
  conn.migrate!
  db = conn.db
  path = options[:output] || config.export_config.dig('stats', 'path') || 'site/stats.json'
  filter = options[:activity]&.map(&:strip)&.map(&:downcase)
  count = Export::Stats.new(db: db, output: path, activity_filter: filter).call
  say_status :done, "Exported stats for #{count} activities to #{path}", :green
rescue StandardError => e
  say_status :error, "Stats export failed: #{e.message}", :red
end