Class: Anima::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/anima/cli.rb,
lib/anima/cli/mcp.rb,
lib/anima/cli/mcp/secrets.rb

Defined Under Namespace

Classes: Mcp

Constant Summary collapse

VALID_ENVIRONMENTS =
%w[development test production].freeze
DEFAULT_PORT =
42134
DEFAULT_HOST =
"localhost:#{DEFAULT_PORT}"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/anima/cli.rb', line 13

def self.exit_on_failure?
  true
end

Instance Method Details

#installObject



18
19
20
21
# File 'lib/anima/cli.rb', line 18

def install
  require_relative "installer"
  Installer.new.run
end

#startObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/anima/cli.rb', line 66

def start
  env = options[:environment] || ENV.fetch("RAILS_ENV", "development")
  unless VALID_ENVIRONMENTS.include?(env)
    say "Invalid environment: #{env}. Must be one of: #{VALID_ENVIRONMENTS.join(", ")}", :red
    exit 1
  end

  ENV["RAILS_ENV"] = env

  unless File.directory?(File.expand_path("~/.anima"))
    say "Anima is not installed. Run 'anima install' first.", :red
    exit 1
  end

  gem_root = Anima.gem_root
  system(gem_root.join("bin/rails").to_s, "db:prepare", chdir: gem_root.to_s) || abort("db:prepare failed")
  exec("foreman", "start", "-f", gem_root.join("Procfile").to_s, "-p", DEFAULT_PORT.to_s, chdir: gem_root.to_s)
end

#tuiObject



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/anima/cli.rb', line 88

def tui
  require "ratatui_ruby"
  require_relative "../tui/app"

  host = options[:host] || DEFAULT_HOST

  say "Connecting to brain at #{host}...", :cyan

  cable_client = TUI::CableClient.new(host: host)
  cable_client.connect

  TUI::App.new(cable_client: cable_client, debug: options[:debug]).run
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/anima/cli.rb', line 25

def update
  require_relative "spinner"

  unless options[:migrate_only]
    success = Spinner.run("Upgrading anima-core gem...") do
      system("gem", "update", "anima-core", out: File::NULL, err: File::NULL)
    end
    unless success
      say "Run manually for details: gem update anima-core", :red
      exit 1
    end

    # Re-exec with the updated gem so migration uses the new template.
    exec(File.join(Gem.bindir, "anima"), "update", "--migrate-only")
  end

  require_relative "config_migrator"
  result = Spinner.run("Migrating configuration...") do
    Anima::ConfigMigrator.new.run
  end

  case result.status
  when :not_found
    say "Config file not found. Run 'anima install' first.", :red
    exit 1
  when :up_to_date
    say "  Config is already up to date."
  when :updated
    result.additions.each do |addition|
      say "  added [#{addition.section}] #{addition.key} = #{addition.value.inspect}"
    end
  end

  restart_service_if_active
end

#versionObject



104
105
106
107
# File 'lib/anima/cli.rb', line 104

def version
  require_relative "version"
  say "anima #{Anima::VERSION}"
end