Class: Tck::Lambdas::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/tck/lambdas/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



10
11
12
# File 'lib/tck/lambdas/cli.rb', line 10

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#allObject



20
21
22
23
24
25
# File 'lib/tck/lambdas/cli.rb', line 20

def all
  puts "Available functions in tck-lambdas:"
  Dir["#{CLI.source_root}/*/source"].map do |dir|
    puts " - #{dir.match(/lambdas\/(.*)\/source/)[1]}"
  end
end

#rolesObject



62
63
64
65
66
# File 'lib/tck/lambdas/cli.rb', line 62

def roles
  cmd = 'aws iam list-roles --query "Roles[].[RoleName,Arn]"'
  puts cmd
  puts `#{cmd}`
end

#use(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/tck/lambdas/cli.rb', line 42

def use(name)
  puts "#{CLI.source_root}/#{name}"
  if File.directory?("#{CLI.source_root}/#{name}")
    @lambda = Tck::Lambdas::AwsFunction.new(name)

    copy_file "Rakefile"
    copy_file "Gemfile.example"
    template "templates/lambdas.yml.erb", ".lambdas.yml"
    template "templates/lambdas.rake.erb", "lib/tasks/lambdas.rake"
    template "templates/serverless.yml.erb", "serverless.yml"
    template "templates/handler.js.erb", "handler.js"
    copy_file "aws_function.rb", "lib/tck/lambdas/aws_function.rb"
    copy_file "test.rb", "lambdas/test.rb"
    directory name, "lambdas/#{name}"
  else
    raise "Sorry, '#{name}' is not a valid lambda name."
  end
end

#usedObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/tck/lambdas/cli.rb', line 28

def used
  yaml = Tck::Lambdas::AwsFunction.yaml
  if yaml.any?
    puts "Functions currently used by this project:"
    yaml.each do |lambda_name, properties|
      puts " - #{properties["function-name"]} (cloned from '#{lambda_name}')"
    end
  else
    puts "No lambdas found in this directory... :("
  end
end

#versionObject



15
16
17
# File 'lib/tck/lambdas/cli.rb', line 15

def version
  puts "tck-lambdas v" + Tck::Lambdas::VERSION
end