generation starts working again

This commit is contained in:
2024-12-25 19:32:53 +01:00
parent 7bbeee570e
commit eff6338f71
9 changed files with 110 additions and 12 deletions

View File

@@ -13,6 +13,7 @@ fp.skip_executable()
mut path := fp.string('path', `p`, "", 'Path where to generate a module, if not mentioned will scan over all installers & clients.\nif . then will be path we are on.') mut path := fp.string('path', `p`, "", 'Path where to generate a module, if not mentioned will scan over all installers & clients.\nif . then will be path we are on.')
reset := fp.bool('reset', `r`, false, 'If we want to reset') reset := fp.bool('reset', `r`, false, 'If we want to reset')
interactive := fp.bool('interactive', `i`, true, 'If we want to work interactive') interactive := fp.bool('interactive', `i`, true, 'If we want to work interactive')
scan := fp.bool('scan', `s`, false, 'If we want to scan')
help_requested := fp.bool('help', `h`, false, 'Show help message') help_requested := fp.bool('help', `h`, false, 'Show help message')
if help_requested { if help_requested {
@@ -36,11 +37,13 @@ if additional_args.len > 0 {
// interactive bool //if we want to ask // interactive bool //if we want to ask
// path string // path string
if path.trim_space() == "." { if path.trim_space() == "." {
path = os.getwd() path = os.getwd()
} }
if path { if ! scan {
generator.do(path:path, reset:reset, interactive:interactive)! generator.do(path:path, reset:reset, interactive:interactive)!
}else{ }else{
generator.scan(path:path, reset:reset, interactive:interactive)! generator.scan(path:path, reset:reset, interactive:interactive)!

View File

@@ -0,0 +1,32 @@
module mycelium
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
__global (
mycelium_global map[string]&Mycelium
mycelium_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet{
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Mycelium {
return &Mycelium{}
}
//switch instance to be used for mycelium
pub fn switch(name string) {
mycelium_default = name
}

View File

@@ -0,0 +1,32 @@
module mycelium
import freeflowuniverse.herolib.data.paramsparser
import os
pub const version = '1.14.3'
const singleton = true
const default = true
//THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
$[heap]
pub struct Mycelium {
pub mut:
name string = 'default'
mail_from string
mail_password string @[secret]
mail_port int
mail_server string
mail_username string
}
fn obj_init(obj_ Mycelium)!Mycelium{
//never call get here, only thing we can do here is work on object itself
mut obj:=obj_
return obj
}

View File

@@ -0,0 +1,30 @@
# mycelium
|
To get started
```vlang
import freeflowuniverse.herolib.clients. mycelium
mut client:= mycelium.get()!
client...
```
## example heroscript
```hero
!!mycelium.configure
secret: '...'
host: 'localhost'
port: 8888
```

View File

@@ -10,7 +10,7 @@ import freeflowuniverse.herolib.core.pathlib
pub fn ask(path string) ! { pub fn ask(path string) ! {
mut myconsole := console.new() mut myconsole := console.new()
mut model:= gen_model_get(path)! mut model:= gen_model_get(path, false)!
console.clear() console.clear()
console.print_header('Configure generation of code for a module on path:') console.print_header('Configure generation of code for a module on path:')

View File

@@ -33,7 +33,7 @@ pub fn do(args_ GenerateArgs) ! {
if args.path == '' { if args.path == '' {
args.path = os.getwd() args.path = os.getwd()
} }
mut m := gen_model_get(args.path,create:false)! mut m := gen_model_get(args.path, false)!
m m
} }
@@ -56,7 +56,7 @@ pub fn do(args_ GenerateArgs) ! {
if args.interactive{ if args.interactive{
ask(args.path)! ask(args.path)!
args.model = gen_model_get(args.path)! args.model = gen_model_get(args.path, false)!
} }
console.print_debug(args) console.print_debug(args)

View File

@@ -43,7 +43,7 @@ fn generate(args GenerateArgs) ! {
if args.reset { if args.reset {
path_templ_dir.delete()! path_templ_dir.delete()!
} }
if args.model.templates { if (args.model or { panic('bug') }).templates {
if !path_templ_dir.exists() { if !path_templ_dir.exists() {
mut templ_6 := $tmpl('templates/atemplate.yaml') mut templ_6 := $tmpl('templates/atemplate.yaml')
pathlib.template_write(templ_6, '${args.path}/templates/atemplate.yaml', true)! pathlib.template_write(templ_6, '${args.path}/templates/atemplate.yaml', true)!

View File

@@ -33,12 +33,13 @@ pub enum Cat {
pub fn gen_model_set(args GenerateArgs) ! { pub fn gen_model_set(args GenerateArgs) ! {
model := args.model model := args.model or { return error('model is none') }
mut heroscript_templ := match model.cat { heroscript_templ := match model.cat {
.client { heroscript_templ := $tmpl('templates/heroscript_client' )} .client { $tmpl('templates/heroscript_client') }
.installer { heroscript_templ := $tmpl('templates/heroscript_installer' )} .installer { $tmpl('templates/heroscript_installer') }
else { return error('Invalid category: ${model.cat}') } else { return error('Invalid category: ${model.cat}') }
} }
pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)! pathlib.template_write(heroscript_templ, '${args.path}/.heroscript', true)!
} }

View File

@@ -16,8 +16,8 @@ pub mut:
pub fn scan(args ScannerArgs) ! { pub fn scan(args ScannerArgs) ! {
if args.path == "" { if args.path == "" {
scan(path:"${os.home_dir()}/code/github/freeflowuniverse/herolib/lib/installers") scan(path:"${os.home_dir()}/code/github/freeflowuniverse/herolib/lib/installers")!
scan(path:"${os.home_dir()}/code/github/freeflowuniverse/herolib/lib/clients") scan(path:"${os.home_dir()}/code/github/freeflowuniverse/herolib/lib/clients")!
return return
} }