-
Notifications
You must be signed in to change notification settings - Fork 1
/
workspace
executable file
·45 lines (37 loc) · 1.25 KB
/
workspace
1
2
3
4
5
6
7
8
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
43
44
45
#!/usr/bin/env ruby
require 'thor'
require 'json'
require File.expand_path('lib/workspace', __dir__)
module Workspace
class CLI < Thor
include Thor::Actions
include Workspace::Docker
# If the command fails, it will also exit with a code other than zero (0).
def self.exit_on_failure?
true
end
# Gives the Thor commands a root directory to operate from.
def self.source_root
File.dirname(__FILE__)
end
desc 'network NAME', 'Create, destroy or clean docker networks'
option :create, type: :boolean
option :destroy, type: :boolean
option :clean, type: :boolean
def network
name = Workspace.configuration.network
if options[:create]
docker("network create #{name}")
copy_file('environments/.network.sample.env', 'environments/.network.env') unless File.exists?('environments/.network.env')
gsub_file('environments/.network.env', /^(NETWORK_NAME=)(.*)$/i, "\\1#{name}", verbose: true)
elsif options[:destroy]
docker("network rm #{name}")
elsif options[:clean]
docker("network prune --force")
end
end
desc 'service', 'Manage service containers'
subcommand "service", Workspace::Commands::Service
end
end
Workspace::CLI.start