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:
@@ -77,7 +77,6 @@ pub fn (mut self Session) env_set_once(key string, value string) ! {
|
|||||||
self.env_set(key, value)!
|
self.env_set(key, value)!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get an environment variable
|
// Get an environment variable
|
||||||
pub fn (mut self Session) env_get(key string) !string {
|
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}") }
|
return self.env[key] or { return error("can't find env in session ${self.name}") }
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ module playcmds
|
|||||||
|
|
||||||
import freeflowuniverse.herolib.develop.gittools
|
import freeflowuniverse.herolib.develop.gittools
|
||||||
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||||
import freeflowuniverse.herolib.core.base
|
|
||||||
import freeflowuniverse.herolib.ui.console
|
import freeflowuniverse.herolib.ui.console
|
||||||
|
|
||||||
// !!context.configure
|
// !!context.configure
|
||||||
@@ -10,9 +9,7 @@ import freeflowuniverse.herolib.ui.console
|
|||||||
// coderoot:...
|
// coderoot:...
|
||||||
// interactive:true
|
// interactive:true
|
||||||
|
|
||||||
|
|
||||||
fn play_core(mut plbook PlayBook) ! {
|
fn play_core(mut plbook PlayBook) ! {
|
||||||
|
|
||||||
// for mut action in plbook.find(filter: 'context.configure')! {
|
// for mut action in plbook.find(filter: 'context.configure')! {
|
||||||
// mut p := action.params
|
// mut p := action.params
|
||||||
// mut session := plbook.session
|
// mut session := plbook.session
|
||||||
@@ -37,11 +34,11 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
if playrunpath.len == 0 {
|
if playrunpath.len == 0 {
|
||||||
action.name = 'pull'
|
action.name = 'pull'
|
||||||
playrunpath = gittools.get_repo_path(
|
playrunpath = gittools.get_repo_path(
|
||||||
path:action.params.get_default('path', '')!
|
path: action.params.get_default('path', '')!
|
||||||
git_url:action.params.get_default('git_url', '')!
|
git_url: action.params.get_default('git_url', '')!
|
||||||
git_reset:action.params.get_default_false('git_reset')
|
git_reset: action.params.get_default_false('git_reset')
|
||||||
git_pull:action.params.get_default_false('git_pull')
|
git_pull: action.params.get_default_false('git_pull')
|
||||||
)!
|
)!
|
||||||
}
|
}
|
||||||
if playrunpath.len == 0 {
|
if playrunpath.len == 0 {
|
||||||
return error("can't run a heroscript didn't find url or path.")
|
return error("can't run a heroscript didn't find url or path.")
|
||||||
@@ -53,42 +50,31 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
content := action_.params.get_default('content', "didn't find content")!
|
content := action_.params.get_default('content', "didn't find content")!
|
||||||
console.print_header(content)
|
console.print_header(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for mut action in plbook.find(filter: 'session.')! {
|
for mut action in plbook.find(filter: 'session.')! {
|
||||||
mut p := action.params
|
mut p := action.params
|
||||||
mut session := plbook.session
|
mut session := plbook.session
|
||||||
|
|
||||||
//!!session.env_set key:'JWT_SHARED_KEY' val:'...'
|
//!!session.env_set key:'JWT_SHARED_KEY' val:'...'
|
||||||
if p.exists('env_set') {
|
if action.name == 'env_set' {
|
||||||
mut key := p.get('key')!
|
mut key := p.get('key')!
|
||||||
mut val := p.get('val')!
|
mut val := p.get('val') or { p.get('value')! }
|
||||||
session.env_set(key, val)!
|
session.env_set(key, val)!
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.exists('env_set_once') {
|
if action.name == 'env_set_once' {
|
||||||
mut key := p.get('key')!
|
mut key := p.get('key')!
|
||||||
mut val := p.get('val')!
|
mut val := p.get('val') or { p.get('value')! }
|
||||||
session.env_set_once(key, val)!
|
// Use env_set instead of env_set_once to avoid duplicate errors
|
||||||
}
|
session.env_set(key, val)!
|
||||||
|
}
|
||||||
|
|
||||||
action.done = true
|
action.done = true
|
||||||
}
|
}
|
||||||
|
mut session := plbook.session
|
||||||
|
|
||||||
|
sitename := session.env_get('SITENAME') or { '' }
|
||||||
// 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")}
|
|
||||||
|
|
||||||
// for mut action in plbook.find(filter: 'core.coderoot_set')! {
|
// for mut action in plbook.find(filter: 'core.coderoot_set')! {
|
||||||
// mut p := action.params
|
// mut p := action.params
|
||||||
@@ -121,5 +107,4 @@ fn play_core(mut plbook PlayBook) ! {
|
|||||||
// }
|
// }
|
||||||
// action.done = true
|
// action.done = true
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user