Class: Nvoi::Cli::Exec::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/cli/exec/command.rb

Overview

Command handles remote command execution on servers

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Command

Returns a new instance of Command.



8
9
10
11
# File 'lib/nvoi/cli/exec/command.rb', line 8

def initialize(options)
  @options = options
  @log = Nvoi.logger
end

Instance Method Details

#run(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nvoi/cli/exec/command.rb', line 13

def run(args)
  @log.info "Exec CLI %s", VERSION

  # Load configuration
  config_path = resolve_config_path
  @config = Utils::ConfigLoader.load(config_path)

  # Apply branch override if specified
  apply_branch_override if @options[:branch]

  # Initialize cloud provider
  @provider = External::Cloud.for(@config)

  if @options[:interactive]
    @log.warning "Ignoring command arguments in interactive mode" unless args.empty?
    @log.warning "Ignoring --all flag in interactive mode" if @options[:all]
    open_shell(@options[:server])
  else
    raise ArgumentError, "command required (use --interactive/-i for shell)" if args.empty?

    command = args.join(" ")

    if @options[:all]
      run_all(command)
    else
      run_on_server(command, @options[:server])
    end
  end
end