Class: Envirobly::Cli::Main

Inherits:
Base show all
Defined in:
lib/envirobly/cli/main.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Instance Method Details

#deploy(environ_name = Envirobly::Git.new.current_branch) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/envirobly/cli/main.rb', line 45

def deploy(environ_name = Envirobly::Git.new.current_branch)
  deployment = Envirobly::Deployment.new(
    environ_name:,
    commit_ref: options.commit,
    account_id: options.,
    project_name: options.project_name,
    project_region: options.project_region
  )
  deployment.perform(dry_run: options.dry_run)
end

#measureObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/envirobly/cli/main.rb', line 94

def measure
  Envirobly::Duration.measure do
    print "Doing something for 2s"
    sleep 2
  end

  Envirobly::Duration.measure do
    print "Doing something else for 100ms"
    sleep 0.1
  end

  Envirobly::Duration.measure("Custom message, took %s") do
    puts "Sleeping 2.5s with custom message"
    sleep 2.5
  end

  puts "Done."
end

#object_treeObject



86
87
88
89
90
91
# File 'lib/envirobly/cli/main.rb', line 86

def object_tree
  commit = Envirobly::Git::Commit.new options.commit
  puts "Commit: #{commit.ref}"
  pp commit.object_tree
  puts "SHA256: #{commit.object_tree_checksum}"
end

#pull(region, bucket, ref, path) ⇒ Object



77
78
79
80
81
82
# File 'lib/envirobly/cli/main.rb', line 77

def pull(region, bucket, ref, path)
  Envirobly::Duration.measure("Build context download took %s") do
    s3 = Envirobly::Aws::S3.new(region:, bucket:)
    s3.pull ref, path
  end
end

#push(region, bucket, ref = "HEAD") ⇒ Object



70
71
72
73
74
# File 'lib/envirobly/cli/main.rb', line 70

def push(region, bucket, ref = "HEAD")
  commit = Envirobly::Git::Commit.new ref
  s3 = Envirobly::Aws::S3.new(region:, bucket:)
  s3.push commit
end

#set_access_tokenObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/envirobly/cli/main.rb', line 57

def set_access_token
  token = ask("Access Token:", echo: false).strip

  if token.blank?
    $stderr.puts
    $stderr.puts "Token can't be empty."
    exit 1
  end

  Envirobly::AccessToken.new(token).save
end

#validateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/envirobly/cli/main.rb', line 13

def validate
  configs = Envirobly::Configs.new
  api = Envirobly::Api.new

  params = { validation: configs.to_params }
  response = api.validate_shape params

  if response.object.fetch("valid")
    puts "All checks pass."
  else
    response.object.fetch("errors").each do |config_path, messages|
      puts "#{config_path}:"
      puts
      messages.each_with_index do |message, index|
        puts "    #{message}"
        puts
      end
    end

    exit 1
  end
end

#versionObject



4
5
6
7
8
9
10
# File 'lib/envirobly/cli/main.rb', line 4

def version
  if options.pure
    puts Envirobly::VERSION
  else
    puts "envirobly CLI v#{Envirobly::VERSION}"
  end
end