This commit is contained in:
2025-07-25 13:25:48 +02:00
parent f2079c7c3d
commit 181a81a84a
11 changed files with 190 additions and 214 deletions

View File

@@ -160,7 +160,7 @@ fn cmd_docusaurus_execute(cmd Command) ! {
heroscript_path: heroscript_config_dir // Pass the directory path
)!
mut site := docs.get(
mut site := docs.add(
git_url: url // Map CLI 'url' flag to DSiteGetArgs 'git_url'
update: update
path_publish: publish_path // Map CLI 'publish' flag to DSiteGetArgs 'path_publish'

View File

@@ -21,7 +21,7 @@ pub fn (mut plbook PlayBook) add(args_ PlayBookNewArgs) ! {
git_pull: args.git_pull
git_reset: args.git_reset
}
args.path = gittools.path(git_path_args)!
args.path = gittools.path(git_path_args)!.path
}
// walk over directory

View File

@@ -21,7 +21,7 @@ pub fn run(mut plbook playbook.PlayBook, dagu bool) ! {
play_core(mut plbook)!
play_ssh(mut plbook)!
play_git.play(mut plbook)! // Changed to play_git.play
// play_git.play(mut plbook)! // Changed to play_git.play
// play_publisher(mut plbook)!
// play_zola(mut plbook)!
// play_caddy(mut plbook)!

View File

@@ -42,13 +42,12 @@ pub fn play_core(mut plbook playbook.PlayBook) ! {
mut playrunpath := action.params.get_default('path', '')!
if playrunpath.len == 0 {
action.name = 'pull'
mut git_path_args := gittools.GitPathGetArgs{
git_url: action.params.get_default('git_url', '')!
git_pull: action.params.get_default_false('git_pull')
git_reset: action.params.get_default_false('git_reset')
git_root: action.params.get_default('git_root', '')!
}
playrunpath = gittools.path(git_path_args)!
playrunpath = gittools.get_repo_path(
path:action.params.get_default('path', '')!
git_url:action.params.get_default('git_url', '')!
git_reset:action.params.get_default_false('git_reset')
git_pull:action.params.get_default_false('git_pull')
)!
}
if playrunpath.len == 0 {
return error("can't run a heroscript didn't find url or path.")

View File

@@ -1,16 +1,10 @@
module docusaurus
module playcmds
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
@[params]
pub struct PlayArgs {
pub mut:
heroscript string
heroscript_path string
plbook ?PlayBook
reset bool
}
import freeflowuniverse.herolib.web.docusaurus
pub fn play(args_ PlayArgs) ! {
mut args := args_
@@ -18,7 +12,7 @@ pub fn play(args_ PlayArgs) ! {
playbook.new(text: args.heroscript, path: args.heroscript_path)!
}
mut ds := new()!
mut ds := docusaurus.new()!
if plbook.exists_once(filter: 'docusaurus.define') { // Changed if_once to exists_once and removed or block
mut action := plbook.action_get(actor: 'docusaurus', name: 'define')!
@@ -26,7 +20,7 @@ pub fn play(args_ PlayArgs) ! {
mut p := action.params
path_publish := p.get_default('path_publish', '')!
path_build := p.get_default('path_build', '')! // don't do heroscript here because this could already be done before
ds = new(
ds = docusaurus.new(
path_publish: path_publish
path_build: path_build
install: plbook.exists(filter: 'docusaurus.reset') || plbook.exists(filter: 'docusaurus.update')
@@ -39,9 +33,9 @@ pub fn play(args_ PlayArgs) ! {
for action in actions {
mut p := action.params
mut site := ds.get(
name: p.get('name') or {return error("can't find name in params for docusaurus.add.\n${args}")!}
nameshort: p.get_default('nameshort', name)!
mut site := ds.add(
name: p.get('name') or {return error("can't find name in params for docusaurus.add.\n${args}")}
nameshort: p.get_default('nameshort', p.get('name')!)!
path: p.get_default('path', '')!
git_url: p.get_default('git_url', '')!
git_reset: p.get_default_false('git_reset')

View File

@@ -4,165 +4,157 @@ import freeflowuniverse.herolib.develop.gittools
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
@[params]
pub struct PlayArgs {
pub mut:
heroscript string
heroscript_path string
plbook ?PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
pub fn play_git(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or {
playbook.new(text: args.heroscript, path: args.heroscript_path)!
}
// mut plbook := args.plbook or {
// playbook.new(text: args.heroscript, path: args.heroscript_path)!
// }
// Handle !!git.define action first to configure GitStructure
define_actions := plbook.find(filter: 'git.define')!
mut gs := if define_actions.len > 0 {
mut p := define_actions[0].params
coderoot := p.get_default('coderoot', '')!
light := p.get_default_true('light')
log := p.get_default_true('log')
debug := p.get_default_false('debug')
offline := p.get_default_false('offline')
ssh_key_path := p.get_default('ssh_key_path', '')!
reload := p.get_default_false('reload')
// // Handle !!git.define action first to configure GitStructure
// define_actions := plbook.find(filter: 'git.define')!
// mut gs := if define_actions.len > 0 {
// mut p := define_actions[0].params
// coderoot := p.get_default('coderoot', '')!
// light := p.get_default_true('light')
// log := p.get_default_true('log')
// debug := p.get_default_false('debug')
// offline := p.get_default_false('offline')
// ssh_key_path := p.get_default('ssh_key_path', '')!
// reload := p.get_default_false('reload')
gittools.new( // Changed to gittools.new
coderoot: coderoot
light: light
log: log
debug: debug
offline: offline
ssh_key_path: ssh_key_path
reload: reload
)!
} else {
// Initialize GitStructure with defaults
gittools.get(gittools.GitStructureArgGet{})! // Changed to gittools.get with default args
}
// gittools.new( // Changed to gittools.new
// coderoot: coderoot
// light: light
// log: log
// debug: debug
// offline: offline
// ssh_key_path: ssh_key_path
// reload: reload
// )!
// } else {
// // Initialize GitStructure with defaults
// gittools.get(gittools.GitStructureArgGet{})! // Changed to gittools.get with default args
// }
// Handle !!git.clone action
clone_actions := plbook.find(filter: 'git.clone')!
for action in clone_actions {
mut p := action.params
url := p.get('url')!
coderoot := p.get_default('coderoot', '')!
sshkey := p.get_default('sshkey', '')!
light := p.get_default_true('light')
recursive := p.get_default_false('recursive')
// // Handle !!git.clone action
// clone_actions := plbook.find(filter: 'git.clone')!
// for action in clone_actions {
// mut p := action.params
// url := p.get('url')!
// coderoot := p.get_default('coderoot', '')!
// sshkey := p.get_default('sshkey', '')!
// light := p.get_default_true('light')
// recursive := p.get_default_false('recursive')
mut clone_args := gittools.GitCloneArgs{ // Changed to gittools.GitCloneArgs
url: url
sshkey: sshkey
recursive: recursive
light: light
}
if coderoot.len > 0 {
gs = gittools.new(coderoot: coderoot)! // Changed to gittools.new
}
gs.clone(clone_args)!
}
// mut clone_args := gittools.GitCloneArgs{ // Changed to gittools.GitCloneArgs
// url: url
// sshkey: sshkey
// recursive: recursive
// light: light
// }
// if coderoot.len > 0 {
// gs = gittools.new(coderoot: coderoot)! // Changed to gittools.new
// }
// gs.clone(clone_args)!
// }
// Handle !!git.repo_action
repo_actions := plbook.find(filter: 'git.repo_action')!
for action in repo_actions {
mut p := action.params
filter_str := p.get_default('filter', '')!
name := p.get_default('name', '')!
account := p.get_default('account', '')!
provider := p.get_default('provider', '')!
action_type := p.get('action')!
message := p.get_default('message', '')!
branchname := p.get_default('branchname', '')!
tagname := p.get_default('tagname', '')!
submodules := p.get_default_false('submodules')
error_ignore := p.get_default_false('error_ignore')
// // Handle !!git.repo_action
// repo_actions := plbook.find(filter: 'git.repo_action')!
// for action in repo_actions {
// mut p := action.params
// filter_str := p.get_default('filter', '')!
// name := p.get_default('name', '')!
// account := p.get_default('account', '')!
// provider := p.get_default('provider', '')!
// action_type := p.get('action')!
// message := p.get_default('message', '')!
// branchname := p.get_default('branchname', '')!
// tagname := p.get_default('tagname', '')!
// submodules := p.get_default_false('submodules')
// error_ignore := p.get_default_false('error_ignore')
mut repos := gs.get_repos(
filter: filter_str
name: name
account: account
provider: provider
)!
// mut repos := gs.get_repos(
// filter: filter_str
// name: name
// account: account
// provider: provider
// )!
if repos.len == 0 {
if !error_ignore {
return error('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
}
console.print_stderr('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}. Ignoring due to error_ignore: true.')
continue
}
// if repos.len == 0 {
// if !error_ignore {
// return error('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}')
// }
// console.print_stderr('No repositories found for git.repo_action with filter: ${filter_str}, name: ${name}, account: ${account}, provider: ${provider}. Ignoring due to error_ignore: true.')
// continue
// }
for mut repo in repos {
match action_type {
'pull' {
repo.pull(submodules: submodules)
}
'commit' {
repo.commit(message)
}
'push' {
repo.push()
}
'reset' {
repo.reset()
}
'branch_create' {
repo.branch_create(branchname)
}
'branch_switch' {
repo.branch_switch(branchname)
}
'tag_create' {
repo.tag_create(tagname)
}
'tag_switch' {
repo.tag_switch(tagname)
}
'delete' {
repo.delete()
}
else {
if !error_ignore {
return error('Unknown git.repo_action: ${action_type}')
}
console.print_stderr('Unknown git.repo_action: ${action_type}. Ignoring due to error_ignore: true.')
}
}
}
}
// for mut repo in repos {
// match action_type {
// 'pull' {
// repo.pull(submodules: submodules)
// }
// 'commit' {
// repo.commit(message)
// }
// 'push' {
// repo.push()
// }
// 'reset' {
// repo.reset()
// }
// 'branch_create' {
// repo.branch_create(branchname)
// }
// 'branch_switch' {
// repo.branch_switch(branchname)
// }
// 'tag_create' {
// repo.tag_create(tagname)
// }
// 'tag_switch' {
// repo.tag_switch(tagname)
// }
// 'delete' {
// repo.delete()
// }
// else {
// if !error_ignore {
// return error('Unknown git.repo_action: ${action_type}')
// }
// console.print_stderr('Unknown git.repo_action: ${action_type}. Ignoring due to error_ignore: true.')
// }
// }
// }
// }
// Handle !!git.list
list_actions := plbook.find(filter: 'git.list')!
for action in list_actions {
mut p := action.params
filter_str := p.get_default('filter', '')!
name := p.get_default('name', '')!
account := p.get_default('account', '')!
provider := p.get_default('provider', '')!
status_update := p.get_default_false('status_update')
// // Handle !!git.list
// list_actions := plbook.find(filter: 'git.list')!
// for action in list_actions {
// mut p := action.params
// filter_str := p.get_default('filter', '')!
// name := p.get_default('name', '')!
// account := p.get_default('account', '')!
// provider := p.get_default('provider', '')!
// status_update := p.get_default_false('status_update')
gs.repos_print(
filter: filter_str
name: name
account: account
provider: provider
status_update: status_update
)
}
// gs.repos_print(
// filter: filter_str
// name: name
// account: account
// provider: provider
// status_update: status_update
// )
// }
// Handle !!git.reload_cache
reload_cache_actions := plbook.find(filter: 'git.reload_cache')!
for action in reload_cache_actions {
mut p := action.params
coderoot := p.get_default('coderoot', '')!
if coderoot.len > 0 {
gs = gittools.new(coderoot: coderoot)!
}
gs.load(true) // Force reload
}
// // Handle !!git.reload_cache
// reload_cache_actions := plbook.find(filter: 'git.reload_cache')!
// for action in reload_cache_actions {
// mut p := action.params
// coderoot := p.get_default('coderoot', '')!
// if coderoot.len > 0 {
// gs = gittools.new(coderoot: coderoot)!
// }
// gs.load(true) // Force reload
// }
}

View File

@@ -0,0 +1,11 @@
module playcmds
import freeflowuniverse.herolib.core.playbook
@[params]
pub struct PlayArgs {
pub mut:
heroscript string
heroscript_path string
plbook ?playbook.PlayBook
reset bool
}

View File

@@ -3,30 +3,33 @@ module gittools
import os
import json
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.develop.gitresolver // Added import for gitresolver
__global (
gsinstances map[string]&GitStructure
)
// GitToolsResolver implements the GitUrlResolver interface
struct GitToolsResolver {}
// get_repo_path implements the GitUrlResolver interface
pub fn (resolver GitToolsResolver) get_repo_path(url string, pull bool, reset bool) !string {
mut gs := get()!
mut repo := gs.get_repo(
url: url
pull: pull
reset: reset
)!
return repo.path()
@[params]
pub struct GetRepoArgs{
pub mut:
path string //if used will check if path exists if yes, just return
git_url string
git_pull bool
git_reset bool
}
// init function to register the resolver when the module is imported
fn init() {
resolver := GitToolsResolver{}
gitresolver.register_resolver(resolver)
// get_repo_path implements the GitUrlResolver interface
pub fn get_repo_path(args GetRepoArgs) !string {
if os.exists(args.path){
return args.path
}
mut gs := get()!
mut repo := gs.get_repo(
url: args.git_url
pull: args.git_pull
reset: args.git_reset
)!
return repo.path()
}
pub fn reset() {

View File

@@ -9,25 +9,6 @@ import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.osal.core as osal
import freeflowuniverse.herolib.data.doctree
@[params]
pub struct DSiteGetArgs {
pub mut:
name string
nameshort string
// gittools will use these params to find the right path
path string
git_url string
git_reset bool
git_root string
git_pull bool
// more params
path_publish string // default empty
production bool
// update bool
// init bool // means create new one if needed
// deploykey string
// config ?Configuration
}
pub fn (mut f DocusaurusFactory) add(args_ DSiteGetArgs) !&DocSite {
console.print_header(' Docusaurus: ${args_.name}')

View File

@@ -44,16 +44,12 @@ pub fn new(args_ DocusaurusArgs) !&DocusaurusFactory {
f.install(install: args.install, template_update: args.template_update, reset: args.reset)!
if args.heroscript != '' {
play(heroscript: args.heroscript, heroscript_path: args.heroscript_path)!
}
return f
}
// get site from the docusaurus factory
pub fn (mut self DocusaurusFactory) site_get(name string) !&DocSite { // Changed return type to !&DocSite
name_:=texttools.name_fix(name: name) // Removed !
name_:=texttools.name_fix(name) // Removed !
return self.sites[name_] or {return error('site not found: ${name} in docusaurus factory.') } // Removed ! from error()
}

View File

@@ -21,7 +21,7 @@ fn (mut self DocusaurusFactory) install(args_ TemplateInstallArgs) ! {
if args.reset {
osal.rm('${self.path_build.path}')!
osal.mkdir_all('${self.path_build.path}')! // Changed mkdir to mkdir_all
osal.dir_ensure('${self.path_build.path}')!
}
template_path := gs.get_path(