This commit is contained in:
2024-12-25 19:11:07 +01:00
parent 41f0c13da6
commit 49286ffcd0
6 changed files with 26 additions and 27 deletions

View File

@@ -1,5 +1,7 @@
#!/usr/bin/env -S v -n -w -gc none -no-retry-compilation -cc tcc -d use_openssl -enable-globals run
import os
import flag
import freeflowuniverse.herolib.code.generator.installer_client as generator
mut fp := flag.new_flag_parser(os.args)
@@ -43,5 +45,3 @@ if path {
}else{
generator.scan(path:path, reset:reset, interactive:interactive)!
}

View File

@@ -14,7 +14,7 @@ pub fn ask(path string) ! {
console.clear()
console.print_header('Configure generation of code for a module on path:')
console.print_green('Path: ${args.path}')
console.print_green('Path: ${path}')
console.lf()
model.classname = myconsole.ask_question(
@@ -30,13 +30,13 @@ pub fn ask(path string) ! {
default: model.title
)!
model.config = !myconsole.ask_yesno(
model.hasconfig = !myconsole.ask_yesno(
description: 'Is there a config (normally yes)?'
default: model.config
default: model.hasconfig
)!
if model.config{
if model.hasconfig {
model.singleton = !myconsole.ask_yesno(
description: 'Can there be multiple instances (normally yes)?'
default: model.singleton
@@ -64,7 +64,6 @@ pub fn ask(path string) ! {
)!
}
gen_model_set(model)!
gen_model_set(GenerateArgs{model: model, path: path})!
}

View File

@@ -9,27 +9,27 @@ fn generate(args GenerateArgs) ! {
console.print_debug('generate code for path: ${args.path}')
//as used in the templates
model :=args.model or { panic("bug)" }
model := args.model or { panic('bug') }
mut path_actions := pathlib.get(args.path + '/${args.model.name}_actions.v')
mut path_actions := pathlib.get(args.path + '/${model.name}_actions.v')
if args.reset {
path_actions.delete()!
}
if !path_actions.exists() && args.model.cat == .installer {
if !path_actions.exists() && model.cat == .installer {
console.print_debug('write installer actions')
mut templ_1 := $tmpl('templates/objname_actions.vtemplate')
pathlib.template_write(templ_1, '${args.path}/${args.model.name}_actions.v', true)!
pathlib.template_write(templ_1, '${args.path}/${model.name}_actions.v', true)!
}
mut templ_2 := $tmpl('templates/objname_factory_.vtemplate')
pathlib.template_write(templ_2, '${args.path}/${args.model.name}_factory_.v', true)!
pathlib.template_write(templ_2, '${args.path}/${model.name}_factory_.v', true)!
mut path_model := pathlib.get(args.path + '/${args.model.name}_model.v')
mut path_model := pathlib.get(args.path + '/${model.name}_model.v')
if args.reset || !path_model.exists() {
console.print_debug('write model.')
mut templ_3 := $tmpl('templates/objname_model.vtemplate')
pathlib.template_write(templ_3, '${args.path}/${args.model.name}_model.v', true)!
pathlib.template_write(templ_3, '${args.path}/${model.name}_model.v', true)!
}
// TODO: check case sensistivity for delete
@@ -78,6 +78,3 @@ fn generate(args GenerateArgs) ! {
// out = out.trim_right('|')
// return out
// }

View File

@@ -1,5 +1,6 @@
module installer_client
import os
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
@@ -34,7 +35,10 @@ pub enum Cat {
pub fn gen_model_set(args GenerateArgs) ! {
model := args.model
heroscript_templ := $tmpl('templates/heroscript')
pathlib.template_write(heroscript_templ, '${args.path}/templates/.heroscript', true)!
//TODO: look in lib/code/generator/installer_client/templates/heroscript, don't use the if in template, use 2 templates, depending type use other template, and the args used should be set here in code
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
}
@@ -69,7 +73,6 @@ pub fn gen_model_get(path string, create: bool) !GenModel {
hasconfig: p.get_default_false('hasconfig')
cat: .installer
}
return model
}
}
@@ -95,10 +98,10 @@ pub fn gen_model_get(path string, create: bool) !GenModel {
}
if model.cat == .unknown {
if path.contains("clients"){
model.cat == .client
}else{
model.cat == .installer
if path.contains("clients") {
model.cat = .client
} else {
model.cat = .installer
}
}

View File

@@ -21,10 +21,10 @@ pub fn scan(args ScannerArgs) ! {
return
}
console.print_header('Scan for generation of code for ${path}')
console.print_header('Scan for generation of code for ${args.path}')
// now walk over all directories, find .heroscript
mut pathroot := pathlib.get_dir(path: path, create: false)!
mut pathroot := pathlib.get_dir(path: args.path, create: false)!
mut plist := pathroot.list(
recursive: true
ignoredefault: false

View File

@@ -7,6 +7,6 @@
title:\"${model.title}\"
${if model.cat == .installer {
templates:${if model.templates { "1" } else { "0" }}
build:${if model.build { "1" } else { "0" }}"
build:${if model.build { "1" } else { "0" }}
startupmanager:${if model.startupmanager { "1" } else { "0" }}
}