WIP support for .spec service files.
This commit is contained in:
parent
2e57922ffd
commit
3769303ad5
@ -13,4 +13,8 @@ targets:
|
||||
status:
|
||||
main: src/status.cr
|
||||
|
||||
dependencies:
|
||||
spec:
|
||||
git: https://git.karchnu.fr/JunkOS/recipes-parser
|
||||
|
||||
license: MIT
|
||||
|
@ -1,7 +1,16 @@
|
||||
require "yaml"
|
||||
require "spec"
|
||||
|
||||
class ServiceDefinition
|
||||
struct Consumes
|
||||
def initialize(@token : String)
|
||||
@optional = false
|
||||
|
||||
if @token.match /\?$/
|
||||
@token = @token.gsub /\?$/, ""
|
||||
@optional = true
|
||||
end
|
||||
end
|
||||
YAML.mapping({
|
||||
token: String,
|
||||
optional: {
|
||||
@ -11,11 +20,19 @@ class ServiceDefinition
|
||||
})
|
||||
end
|
||||
struct Provides
|
||||
def initialize(@token : String)
|
||||
end
|
||||
YAML.mapping({
|
||||
token: String
|
||||
})
|
||||
end
|
||||
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({
|
||||
name: String,
|
||||
file: String?,
|
||||
@ -32,10 +49,6 @@ class ServiceDefinition
|
||||
},
|
||||
directory: String?, # Place to chdir to before running @command.
|
||||
user: String?, # User that should run the service.
|
||||
environment: {
|
||||
type: Environment,
|
||||
default: Environment.root
|
||||
},
|
||||
provides: {
|
||||
type: Array(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
|
||||
|
||||
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)
|
||||
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
|
||||
end
|
||||
|
||||
@@all << ServiceDefinition.from_yaml File.read "#{path}/#{child}"
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user