156 lines
4.2 KiB
Plaintext
156 lines
4.2 KiB
Plaintext
module ${model.name}
|
|
import freeflowuniverse.herolib.data.paramsparser
|
|
import os
|
|
|
|
pub const version = '0.0.0'
|
|
const singleton = ${model.singleton}
|
|
const default = ${model.default}
|
|
|
|
@if model.hasconfig
|
|
//TODO: THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE TO STRUCT BELOW, IS STRUCTURED AS HEROSCRIPT
|
|
pub fn heroscript_default() !string {
|
|
@if model.cat == .installer
|
|
heroscript:="
|
|
!!${model.name}.configure
|
|
name:'${model.name}'
|
|
homedir: '{HOME}/hero/var/${model.name}'
|
|
configpath: '{HOME}/.config/${model.name}/admin.yaml'
|
|
username: 'admin'
|
|
password: 'secretpassword'
|
|
secret: ''
|
|
title: 'My Hero DAG'
|
|
host: 'localhost'
|
|
port: 8888
|
|
|
|
"
|
|
@else
|
|
heroscript:="
|
|
!!${model.name}.configure
|
|
name:'${model.name}'
|
|
mail_from: 'info@@example.com'
|
|
mail_password: 'secretpassword'
|
|
mail_port: 587
|
|
mail_server: 'smtp-relay.brevo.com'
|
|
mail_username: 'kristof@@incubaid.com'
|
|
|
|
"
|
|
|
|
// mail_from := os.getenv_opt('MAIL_FROM') or {'info@@example.com'}
|
|
// mail_password := os.getenv_opt('MAIL_PASSWORD') or {'secretpassword'}
|
|
// mail_port := (os.getenv_opt('MAIL_PORT') or {"587"}).int()
|
|
// mail_server := os.getenv_opt('MAIL_SERVER') or {'smtp-relay.brevo.com'}
|
|
// mail_username := os.getenv_opt('MAIL_USERNAME') or {'kristof@@incubaid.com'}
|
|
//
|
|
// heroscript:="
|
|
// !!mailclient.configure name:'default'
|
|
// mail_from: '??{mail_from}'
|
|
// mail_password: '??{mail_password}'
|
|
// mail_port: ??{mail_port}
|
|
// mail_server: '??{mail_server}'
|
|
// mail_username: '??{mail_username}'
|
|
//
|
|
// "
|
|
//
|
|
|
|
@end
|
|
|
|
return heroscript
|
|
|
|
}
|
|
@end
|
|
|
|
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
|
@if model.cat == .installer
|
|
^^[heap]
|
|
pub struct ${model.classname} {
|
|
pub mut:
|
|
name string = 'default'
|
|
@if model.hasconfig
|
|
homedir string
|
|
configpath string
|
|
username string
|
|
password string @@[secret]
|
|
secret string @@[secret]
|
|
title string
|
|
host string
|
|
port int
|
|
@end
|
|
}
|
|
@if model.hasconfig
|
|
fn cfg_play(p paramsparser.Params) !${model.classname} {
|
|
//THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
|
|
mut mycfg := ${model.classname}{
|
|
name: p.get_default('name', 'default')!
|
|
homedir: p.get_default('homedir', '{HOME}/hero/var/${model.name}')!
|
|
configpath: p.get_default('configpath', '{HOME}/hero/var/${model.name}/admin.yaml')!
|
|
username: p.get_default('username', 'admin')!
|
|
password: p.get_default('password', '')!
|
|
secret: p.get_default('secret', '')!
|
|
title: p.get_default('title', 'HERO DAG')!
|
|
host: p.get_default('host', 'localhost')!
|
|
port: p.get_int_default('port', 8888)!
|
|
}
|
|
|
|
if mycfg.password == '' && mycfg.secret == '' {
|
|
return error('password or secret needs to be filled in for ${model.name}')
|
|
}
|
|
return mycfg
|
|
}
|
|
@end
|
|
|
|
@else
|
|
|
|
^^[heap]
|
|
pub struct ${model.classname} {
|
|
pub mut:
|
|
name string = 'default'
|
|
mail_from string
|
|
mail_password string @@[secret]
|
|
mail_port int
|
|
mail_server string
|
|
mail_username string
|
|
}
|
|
|
|
@if model.hasconfig
|
|
fn cfg_play(p paramsparser.Params) !${model.classname} {
|
|
//THIS IS EXAMPLE CODE AND NEEDS TO BE CHANGED IN LINE WITH struct above
|
|
mut mycfg := ${model.classname}{
|
|
name: p.get_default('name', 'default')!
|
|
mail_from: p.get('mail_from')!
|
|
mail_password: p.get('mail_password')!
|
|
mail_port: p.get_int_default('mail_port', 8888)!
|
|
mail_server: p.get('mail_server')!
|
|
mail_username: p.get('mail_username')!
|
|
}
|
|
set(mycfg)!
|
|
return mycfg
|
|
}
|
|
@end
|
|
|
|
@end
|
|
|
|
fn obj_init(obj_ ${model.classname})!${model.classname}{
|
|
//never call get here, only thing we can do here is work on object itself
|
|
mut obj:=obj_
|
|
return obj
|
|
}
|
|
|
|
@if model.cat == .installer
|
|
//called before start if done
|
|
fn configure() ! {
|
|
@if model.cat == .installer
|
|
//mut installer := get()!
|
|
@else
|
|
//mut client := get()!
|
|
@end
|
|
@if model.templates
|
|
// mut mycode := ??tmpl('templates/atemplate.yaml')
|
|
// mut path := pathlib.get_file(path: cfg.configpath, create: true)!
|
|
// path.write(mycode)!
|
|
// console.print_debug(mycode)
|
|
@end
|
|
}
|
|
@end
|
|
|
|
|