WIP support for .spec service files.
parent
2e57922ffd
commit
3769303ad5
|
@ -13,4 +13,8 @@ targets:
|
||||||
status:
|
status:
|
||||||
main: src/status.cr
|
main: src/status.cr
|
||||||
|
|
||||||
|
dependencies:
|
||||||
|
spec:
|
||||||
|
git: https://git.karchnu.fr/JunkOS/recipes-parser
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
require "yaml"
|
require "yaml"
|
||||||
|
require "spec"
|
||||||
|
|
||||||
class ServiceDefinition
|
class ServiceDefinition
|
||||||
struct Consumes
|
struct Consumes
|
||||||
|
def initialize(@token : String)
|
||||||
|
@optional = false
|
||||||
|
|
||||||
|
if @token.match /\?$/
|
||||||
|
@token = @token.gsub /\?$/, ""
|
||||||
|
@optional = true
|
||||||
|
end
|
||||||
|
end
|
||||||
YAML.mapping({
|
YAML.mapping({
|
||||||
token: String,
|
token: String,
|
||||||
optional: {
|
optional: {
|
||||||
|
@ -11,11 +20,19 @@ class ServiceDefinition
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
struct Provides
|
struct Provides
|
||||||
|
def initialize(@token : String)
|
||||||
|
end
|
||||||
YAML.mapping({
|
YAML.mapping({
|
||||||
token: String
|
token: String
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
struct Checks
|
struct Checks
|
||||||
|
def initialize(section : Specs::Section)
|
||||||
|
@name = section.content["name"].as_s
|
||||||
|
@file = section.content["file"]?.try &.as_s
|
||||||
|
@directory = section.content["directory"]?.try &.as_s
|
||||||
|
@command = section.content["command"].as_s
|
||||||
|
end
|
||||||
YAML.mapping({
|
YAML.mapping({
|
||||||
name: String,
|
name: String,
|
||||||
file: String?,
|
file: String?,
|
||||||
|
@ -32,10 +49,6 @@ class ServiceDefinition
|
||||||
},
|
},
|
||||||
directory: String?, # Place to chdir to before running @command.
|
directory: String?, # Place to chdir to before running @command.
|
||||||
user: String?, # User that should run the service.
|
user: String?, # User that should run the service.
|
||||||
environment: {
|
|
||||||
type: Environment,
|
|
||||||
default: Environment.root
|
|
||||||
},
|
|
||||||
provides: {
|
provides: {
|
||||||
type: Array(Provides),
|
type: Array(Provides),
|
||||||
default: [] of Provides
|
default: [] of Provides
|
||||||
|
@ -55,19 +68,31 @@ class ServiceDefinition
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
def self.new(name)
|
|
||||||
Service.from_yaml File.read "#{name}.yaml"
|
|
||||||
end
|
|
||||||
|
|
||||||
class_getter all = [] of ServiceDefinition
|
class_getter all = [] of ServiceDefinition
|
||||||
|
|
||||||
|
def initialize(specs : Specs)
|
||||||
|
sections = specs.sections
|
||||||
|
pp! specs
|
||||||
|
specs = specs.assignments
|
||||||
|
@name = specs["name"].as_s
|
||||||
|
@command = specs["command"].as_s
|
||||||
|
@stop_command = specs["stop-command"]?.try &.as_s
|
||||||
|
@directory = specs["directory"]?.try &.as_s
|
||||||
|
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
|
||||||
|
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
|
||||||
|
@checks = sections.select(&.name.== "check").map { |x| Checks.new x } || Array(Checks).new
|
||||||
|
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new
|
||||||
|
end
|
||||||
|
|
||||||
def self.load(path)
|
def self.load(path)
|
||||||
Dir.each_child path do |child|
|
Dir.each_child path do |child|
|
||||||
unless child.match /\.yaml$/
|
if child.match /\.yaml$/
|
||||||
|
@@all << ServiceDefinition.from_yaml File.read "#{path}/#{child}"
|
||||||
|
elsif child.match /\.spec$/
|
||||||
|
@@all << ServiceDefinition.new Specs.parse("#{path}/#{child}").not_nil!
|
||||||
|
else
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@@all << ServiceDefinition.from_yaml File.read "#{path}/#{child}"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue