This commit is contained in:
2025-08-12 10:33:29 +02:00
parent 0a7851b920
commit 4cd5b51085
9 changed files with 1821 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
!!hero_code.generate_client
name:'reprompt'
classname:'RepromptWorkspace'
singleton:0
default:1
hasconfig:1
reset:0

View File

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

View File

@@ -0,0 +1,12 @@
module reprompt
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import freeflowuniverse.herolib.core.pathlib
import os
// your checking & initialization code if needed
fn (mut ws RepromptWorkspace) reprompt() !string {
//TODO: fill in template based on selection
return ""
}

View File

@@ -0,0 +1,102 @@
module reprompt
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
__global (
reprompt_global map[string]&RepromptWorkspace
reprompt_default string
)
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
fn args_get(args_ ArgsGet) ArgsGet {
mut args := args_
if args.name == '' {
args.name = 'default'
}
return args
}
pub fn get(args_ ArgsGet) !&RepromptWorkspace {
mut context := base.context()!
mut args := args_get(args_)
mut obj := RepromptWorkspace{
name: args.name
}
if args.name !in reprompt_global {
if !exists(args)! {
set(obj)!
} else {
heroscript := context.hero_config_get('reprompt', args.name)!
mut obj_ := heroscript_loads(heroscript)!
set_in_mem(obj_)!
}
}
return reprompt_global[args.name] or {
println(reprompt_global)
// bug if we get here because should be in globals
panic('could not get config for reprompt with name, is bug:${args.name}')
}
}
// register the config for the future
pub fn set(o RepromptWorkspace) ! {
set_in_mem(o)!
mut context := base.context()!
heroscript := heroscript_dumps(o)!
context.hero_config_set('reprompt', o.name, heroscript)!
}
// does the config exists?
pub fn exists(args_ ArgsGet) !bool {
mut context := base.context()!
mut args := args_get(args_)
return context.hero_config_exists('reprompt', args.name)
}
pub fn delete(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()!
context.hero_config_delete('reprompt', args.name)!
if args.name in reprompt_global {
// del reprompt_global[args.name]
}
}
// only sets in mem, does not set as config
fn set_in_mem(o RepromptWorkspace) ! {
mut o2 := obj_init(o)!
reprompt_global[o.name] = &o2
reprompt_default = o.name
}
pub fn play(mut plbook PlayBook) ! {
mut install_actions := plbook.find(filter: 'reprompt.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
heroscript := install_action.heroscript()
mut obj2 := heroscript_loads(heroscript)!
set(obj2)!
}
}
}
// switch instance to be used for reprompt
pub fn switch(name string) {
reprompt_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -0,0 +1,49 @@
module reprompt
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero
import freeflowuniverse.herolib.core.pathlib
import os
pub const version = '0.0.0'
const singleton = false
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 RepromptWorkspace {
pub mut:
name string = 'default'
dirs []RepromptDir
}
pub struct RepromptDir {
pub mut:
path pathlib.Path
selections []string // paths selected in the RepromptDir
}
// your checking & initialization code if needed
fn obj_init(mycfg_ RepromptWorkspace) !RepromptWorkspace {
mut mycfg := mycfg_
if mycfg.password == '' && mycfg.secret == '' {
return error('password or secret needs to be filled in for ${mycfg.name}')
}
return mycfg
}
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_dumps(obj RepromptWorkspace) !string {
//create heroscript following template
//check for our homedir on our machine and replace in the heroscript to @HOME in path
return encoderhero.encode[RepromptWorkspace](obj)!
}
pub fn heroscript_loads(heroscript string) !RepromptWorkspace {
//TODO: parse heroscript populate RepromptWorkspace
mut obj := encoderhero.decode[RepromptWorkspace](heroscript)!
return obj
}

View File

@@ -0,0 +1,10 @@
!!reprompt.configure name:"default"
!!reprompt.workspace_dir name:"default"
path:"@HOME/code/github/freeflowuniverse/herolib/lib/builder"
selection:"path1,path2" //paths are relative in the path of workspace
filter_exclude:","
filter_include:","

View File

@@ -0,0 +1 @@
TODO:...

File diff suppressed because it is too large Load Diff

View File

@@ -54,10 +54,8 @@ fn play_core(mut plbook PlayBook) ! {
// 2. Session environment handling
// ----------------------------------------------------------------
// Guard make sure a session exists
mut session := plbook.session or {
return error('PlayBook has no attached Session')
}
mut session := plbook.session
// !!session.env_set / env_set_once
for mut action in plbook.find(filter: 'session.')! {
mut p := action.params