Custom names for services.

Services must be created as `[env/]custom_name` and be passed a `type=`
parameter when created.
This commit is contained in:
Luka Vandervelden 2019-11-07 18:08:57 +01:00
parent 6c3024c92f
commit 1c80a80158
2 changed files with 22 additions and 5 deletions

View File

@ -54,6 +54,7 @@ commands.push "add", "Adds a service to an environment." do |args|
end
environment, service = Service.parse_id args[0]
name = service
args.each_with_index do |arg, i|
next if i == 0
@ -67,7 +68,9 @@ commands.push "add", "Adds a service to an environment." do |args|
_, key, value = match
if key == "domain"
if key == "type"
service = value
elsif key == "domain"
domain = value
elsif match = key.match /^port:(.*)/
ports[match[1]] = value.to_i
@ -82,6 +85,10 @@ commands.push "add", "Adds a service to an environment." do |args|
service.domain = domain
end
if name != service
service.name = name
end
service.consumes.each do |token|
provider = providers[token.token]?

View File

@ -32,6 +32,7 @@ class Service
getter environment : Environment
getter providers = ProvidersList.new
setter name : String?
property domain : String?
getter ports = Hash(String, Int32).new
@ -66,7 +67,11 @@ class Service
def initialize(specs : SpecParser)
assignments = specs.assignments
@reference = ServiceDefinition.get assignments["name"].as_s
# Complicated because of compat with when services had no dedicated
# name and their types were their name.
type = assignments["type"]?.try &.as_s
@name = (assignments["name"]?.try(&.as_s) || type).not_nil!
@reference = ServiceDefinition.get type || @name
@domain = assignments["domain"]?.try &.as_s
@ -102,10 +107,14 @@ class Service
def to_spec
file = [
"name: #{@reference.name}",
"type: #{@reference.name}",
"environment: #{@environment.name}"
]
unless @name.nil?
file << "name: #{@name}"
end
if @ports.size > 0
ports_list = @ports.map do |name, number|
"#{name}=#{number}"
@ -144,10 +153,10 @@ class Service
# FIXME: At this point, macros would be both more readable and shorter.
def name
@reference.name
@name || @reference.name
end
def type
@reference.type
@reference.name
end
def command
@reference.command
@ -359,6 +368,7 @@ class Service
def summary
"%-16s #{name.colorize(:white).to_s}\n" % "Name:" +
"%-16s #{type.colorize(:white).to_s}\n" % "Type:" +
"%-16s #{environment.name.colorize(:white).to_s} (#{environment.type.to_s.downcase})\n" % "Environment:" +
(
if provides.size > 0