Class: LambdaWhenever::CLI

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

Overview

The CLI class handles command-line interface interactions for the Lambda Whenever tool.

Constant Summary collapse

SUCCESS_EXIT_CODE =
0
ERROR_EXIT_CODE =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



11
12
13
14
# File 'lib/lambda_whenever/cli.rb', line 11

def initialize(args)
  @args = args
  @option = Option.new(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/lambda_whenever/cli.rb', line 9

def args
  @args
end

#optionObject (readonly)

Returns the value of attribute option.



9
10
11
# File 'lib/lambda_whenever/cli.rb', line 9

def option
  @option
end

Instance Method Details

#runObject



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
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lambda_whenever/cli.rb', line 16

def run
  case option.mode
  when Option::DRYRUN_MODE
    option.validate!
    print_tasks
    Logger.instance.message("Above is your schedule file converted to scheduled tasks; your scheduled tasks was not updated.")
    Logger.instance.message("Run `lambda_whenever --help' for more options.")
  when Option::UPDATE_MODE
    option.validate!
    with_concurrent_modification_handling do
      update_eb_schedules
    end
    Logger.instance.log("write", "scheduled tasks updated")
  when Option::CLEAR_MODE
    with_concurrent_modification_handling do
      clear_tasks
    end
    Logger.instance.log("write", "scheduled tasks cleared")
  when Option::LIST_MODE
    list_tasks
    Logger.instance.message("Above is your scheduled tasks.")
  when Option::PRINT_VERSION_MODE
    print_version
  end

  SUCCESS_EXIT_CODE
rescue Aws::Errors::MissingRegionError
  Logger.instance.fail("missing region error occurred; please use `--region` option or export `AWS_REGION` environment variable.")
  ERROR_EXIT_CODE
rescue Aws::Errors::MissingCredentialsError
  Logger.instance.fail("missing credential error occurred; please specify it with arguments, use shared credentials, or export `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variable")
  ERROR_EXIT_CODE
rescue OptionParser::MissingArgument,
       Option::InvalidOptionException => e

  Logger.instance.fail(e.message)
  ERROR_EXIT_CODE
end