Class: Laws::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/laws/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



3
4
5
6
7
# File 'lib/laws/cli.rb', line 3

def initialize
  @prompt = TTY::Prompt.new
  @ecs = Commands::ECS.new(@prompt)
  @secretsmanager = Commands::SecretsManager.new(@prompt)
end

Instance Method Details

#parse_optionsObject



9
10
11
12
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
42
# File 'lib/laws/cli.rb', line 9

def parse_options
  OptionParser.new do |opts|
    opts.banner = 'Usage: laws [command]'

    opts.on('-h', '--help', 'Display this help message') do
      puts opts
      exit
    end

    opts.separator "\nCommands:"
    opts.separator '  ecs execute-command    Run interactive ECS execute-command'
    opts.separator '  secretsmanager get-secret-value  Get and display secret value'
  end.parse!

  # Handle commands
  command = ARGV.join(' ') # Join arguments to handle multi-word commands
  begin
    case command
    when 'ecs execute-command'
      @ecs.execute_command
    when 'secretsmanager get-secret-value'
      @secretsmanager.get_secret_value
    when nil, ''
      puts 'No command specified. Use --help for usage information.'
      exit 1
    else
      puts "Unknown command: #{command}"
      exit 1
    end
  rescue TTY::Reader::InputInterrupt
    puts "\nOperation cancelled."
    exit 1
  end
end