refactor: improve session action handling in play_core

- Clean up `play_core` by removing dead code and unused imports
- Check `action.name` directly instead of param existence
- Allow 'value' as an alias for 'val' in session env actions
- Use `env_set` for `env_set_once` to avoid duplicate errors
This commit is contained in:
Mahmoud-Emad
2025-07-31 17:59:44 +03:00
parent 697c500e35
commit 198a394be8
2 changed files with 15 additions and 31 deletions

View File

@@ -77,7 +77,6 @@ pub fn (mut self Session) env_set_once(key string, value string) ! {
self.env_set(key, value)!
}
// Get an environment variable
pub fn (mut self Session) env_get(key string) !string {
return self.env[key] or { return error("can't find env in session ${self.name}") }

View File

@@ -2,7 +2,6 @@ module playcmds
import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.ui.console
// !!context.configure
@@ -10,9 +9,7 @@ import freeflowuniverse.herolib.ui.console
// coderoot:...
// interactive:true
fn play_core(mut plbook PlayBook) ! {
// for mut action in plbook.find(filter: 'context.configure')! {
// mut p := action.params
// mut session := plbook.session
@@ -60,35 +57,24 @@ fn play_core(mut plbook PlayBook) ! {
mut session := plbook.session
//!!session.env_set key:'JWT_SHARED_KEY' val:'...'
if p.exists('env_set') {
if action.name == 'env_set' {
mut key := p.get('key')!
mut val := p.get('val')!
mut val := p.get('val') or { p.get('value')! }
session.env_set(key, val)!
}
if p.exists('env_set_once') {
if action.name == 'env_set_once' {
mut key := p.get('key')!
mut val := p.get('val')!
session.env_set_once(key, val)!
mut val := p.get('val') or { p.get('value')! }
// Use env_set instead of env_set_once to avoid duplicate errors
session.env_set(key, val)!
}
action.done = true
}
mut session := plbook.session
// CHANGE {...} args in plbook
println('plbook:${plbook}')
mut context := base.context()!
mut session := context.session_latest()!
sitename:=session.env_get('SITENAME') or {""}
println('session:${session}')
println('sitename:${sitename}')
if true{panic("dfghjkjhgfghjk")}
sitename := session.env_get('SITENAME') or { '' }
// for mut action in plbook.find(filter: 'core.coderoot_set')! {
// mut p := action.params
@@ -121,5 +107,4 @@ fn play_core(mut plbook PlayBook) ! {
// }
// action.done = true
// }
}