Class: Sxn::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/sxn/CLI.rb

Overview

Main CLI class using Thor framework

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV, local_options = {}, config = {}) ⇒ CLI

Returns a new instance of CLI.



15
16
17
18
19
# File 'lib/sxn/CLI.rb', line 15

def initialize(args = ARGV, local_options = {}, config = {})
  super
  @ui = Sxn::UI::Output.new
  setup_environment
end

Class Method Details

.exit_on_failure?Boolean

Returns:



11
12
13
# File 'lib/sxn/CLI.rb', line 11

def self.exit_on_failure?
  true
end

Instance Method Details

#activate(session_name = nil) ⇒ Object



187
188
189
190
191
# File 'lib/sxn/CLI.rb', line 187

def activate(session_name = nil)
  Commands::Sessions.new.activate(session_name)
rescue Sxn::Error => e
  handle_error(e)
end

#add(session_name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/sxn/CLI.rb', line 46

def add(session_name)
  cmd = Commands::Sessions.new
  cmd.options = options
  cmd.add(session_name)
rescue Sxn::Error => e
  handle_error(e)
end

#archive(session_name = nil) ⇒ Object



180
181
182
183
184
# File 'lib/sxn/CLI.rb', line 180

def archive(session_name = nil)
  Commands::Sessions.new.archive(session_name)
rescue Sxn::Error => e
  handle_error(e)
end

#configObject



244
245
246
247
248
# File 'lib/sxn/CLI.rb', line 244

def config
  show_config
rescue Sxn::Error => e
  handle_error(e)
end

#current(subcommand = nil) ⇒ Object



72
73
74
75
76
# File 'lib/sxn/CLI.rb', line 72

def current(subcommand = nil)
  Commands::Sessions.new.current(subcommand)
rescue Sxn::Error => e
  handle_error(e)
end

#enterObject



91
92
93
94
95
# File 'lib/sxn/CLI.rb', line 91

def enter
  Commands::Sessions.new.enter
rescue Sxn::Error => e
  handle_error(e)
end

#init(folder = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/sxn/CLI.rb', line 31

def init(folder = nil)
  # steep:ignore:start - Thor dynamic argument validation handled at runtime
  # Thor framework uses metaprogramming for argument parsing that can't be statically typed.
  # Runtime validation ensures type safety through Thor's built-in validation.
  Commands::Init.new.init(folder)
  # steep:ignore:end
rescue Sxn::Error => e
  handle_error(e)
end

#install_shell_wrapperObject



163
164
165
166
167
# File 'lib/sxn/CLI.rb', line 163

def install_shell_wrapper
  Commands::Init.new.invoke(:install_shell, [], options)
rescue Sxn::Error => e
  handle_error(e)
end

#listObject



63
64
65
66
67
# File 'lib/sxn/CLI.rb', line 63

def list
  Commands::Sessions.new.list
rescue Sxn::Error => e
  handle_error(e)
end

#mcp(subcommand = nil, *args) ⇒ Object



229
230
231
232
233
# File 'lib/sxn/CLI.rb', line 229

def mcp(subcommand = nil, *args)
  Commands::MCP.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end

#projects(subcommand = nil, *args) ⇒ Object



194
195
196
197
198
# File 'lib/sxn/CLI.rb', line 194

def projects(subcommand = nil, *args)
  Commands::Projects.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end

#remove(session_name = nil) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/sxn/CLI.rb', line 171

def remove(session_name = nil)
  cmd = Commands::Sessions.new
  cmd.options = options
  cmd.remove(session_name)
rescue Sxn::Error => e
  handle_error(e)
end

#rules(subcommand = nil, *args) ⇒ Object



215
216
217
218
219
# File 'lib/sxn/CLI.rb', line 215

def rules(subcommand = nil, *args)
  Commands::Rules.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end

#sessions(subcommand = nil, *args) ⇒ Object



201
202
203
204
205
# File 'lib/sxn/CLI.rb', line 201

def sessions(subcommand = nil, *args)
  Commands::Sessions.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end

#statusObject



236
237
238
239
240
# File 'lib/sxn/CLI.rb', line 236

def status
  show_status
rescue Sxn::Error => e
  handle_error(e)
end

#templates(subcommand = nil, *args) ⇒ Object



222
223
224
225
226
# File 'lib/sxn/CLI.rb', line 222

def templates(subcommand = nil, *args)
  Commands::Templates.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end

#upObject



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
# File 'lib/sxn/CLI.rb', line 113

def up
  require "shellwords"

  session_config = Sxn::Core::SessionConfig.find_from_path(Dir.pwd)

  unless session_config
    warn "Not in a session directory."
    warn ""
    warn "This command works when run from within a session folder."
    warn "Session folders contain a .sxnrc file that points back to the project."
    warn ""
    warn "Tip: Add this function to your shell profile for easier navigation:"
    warn ""
    warn "  sxn-up() { eval \"$(sxn up 2>/dev/null)\" || sxn up; }"
    exit(1)
  end

  project_root = session_config.project_root

  unless project_root && File.directory?(project_root)
    warn "Could not determine project root from .sxnrc"
    warn "parent_sxn_path: #{session_config.parent_sxn_path || "nil"}"
    exit(1)
  end

  # Output the cd command for shell integration
  puts "cd #{Shellwords.escape(project_root)}"
rescue Sxn::Error => e
  handle_error(e)
end

#use(session_name) ⇒ Object



55
56
57
58
59
# File 'lib/sxn/CLI.rb', line 55

def use(session_name)
  Commands::Sessions.new.use(session_name)
rescue Sxn::Error => e
  handle_error(e)
end

#versionObject



22
23
24
25
# File 'lib/sxn/CLI.rb', line 22

def version
  puts "sxn #{Sxn::VERSION}"
  puts "Session management for multi-repository development"
end

#worktree(subcommand = nil, *args) ⇒ Object



208
209
210
211
212
# File 'lib/sxn/CLI.rb', line 208

def worktree(subcommand = nil, *args)
  Commands::Worktrees.start([subcommand, *args].compact)
rescue Sxn::Error => e
  handle_error(e)
end