This commit is contained in:
2025-10-13 08:30:42 +04:00
parent cf304e004e
commit b154a91867
31 changed files with 242 additions and 242 deletions

View File

@@ -13,7 +13,7 @@ pub fn generate(args_ GeneratorArgs) ! {
console.print_header('Generate code for path: ${args.path} (reset:${args.force}, force:${args.force})')
console.print_debug(args)
if args.path == '' {
args.path = os.getwd()
return error('no path provided')
}
if args.name == '' {

View File

@@ -21,10 +21,19 @@ pub fn scan(args_ GeneratorArgs) ! {
regex: ['.heroscript']
)!
console.print_debug('Found ${plist.paths.len} directories with .heroscript file.')
for mut p in plist.paths {
pparent := p.parent()!
args.force = true
args.path = pparent.path
// println("-- ${pparent}")
generate(args)!
}
mut res := []GeneratorArgs{}
for mut p in plist.paths {
pparent := p.parent()!
res << args_get(pparent.path)!
}
console.print_debug('Found ${res.len} generator args.')
println(res)
$dbg;
}

View File

@@ -6,10 +6,10 @@ import cli { Command, Flag }
pub fn cmd_generator(mut cmdroot Command) {
mut cmd_run := Command{
name: 'generate'
description: 'generator for vlang code in hero context.'
required_args: 0
execute: cmd_generator_execute
name: 'generate'
description: 'generator for vlang code in hero context.\narg is path (required). Use "." for current directory.'
// required_args: 1
execute: cmd_generator_execute
}
cmd_run.add_flag(Flag{
@@ -20,14 +20,6 @@ pub fn cmd_generator(mut cmdroot Command) {
description: 'will reset.'
})
cmd_run.add_flag(Flag{
flag: .string
required: false
name: 'path'
abbrev: 'p'
description: 'path where to generate the code or scan over multiple directories.'
})
cmd_run.add_flag(Flag{
flag: .bool
required: false
@@ -48,7 +40,7 @@ pub fn cmd_generator(mut cmdroot Command) {
required: false
name: 'scan'
abbrev: 's'
description: 'force scanning operation.'
description: 'scanning operation, walk over directories.'
})
cmd_run.add_flag(Flag{
@@ -68,17 +60,30 @@ fn cmd_generator_execute(cmd Command) ! {
mut scan := cmd.flags.get_bool('scan') or { false }
mut playonly := cmd.flags.get_bool('playonly') or { false }
mut installer := cmd.flags.get_bool('installer') or { false }
mut path := cmd.flags.get_string('path') or { '' }
// Get path from required argument
mut path := ''
if cmd.args.len > 0 {
path = cmd.args[0]
}
if playonly {
force = true
}
if path == '' {
// Handle "." as current working directory
if path == '.' {
path = os.getwd()
}
} else {
// Expand home directory
path = path.replace('~', os.home_dir())
path = path.replace('~', os.home_dir())
// Validate that path exists
if !os.exists(path) {
return error('Path does not exist: ${path}')
}
}
mut cat := generic.Cat.client
if installer {

View File

@@ -1,40 +0,0 @@
module herocmds
import cli { Command }
// path string //if location on filessytem, if exists, this has prio on git_url
// git_url string // location of where the hero scripts are
// git_pull bool // means when getting new repo will pull even when repo is already there
// git_pullreset bool // means we will force a pull and reset old content
// coderoot string //the location of coderoot if its another one
pub fn cmd_run(mut cmdroot Command) {
mut cmd_run := Command{
name: 'run'
usage: '
## Powerfull command to run heroscript
heroscript has numerous ways to execute actions using your hero tool.
example:
hero run -u https://git.threefold.info/threefold_coop/info_asimov/src/branch/main/heroscript
Can also do -e or -st to see sourcetree
If you do -gp it will pull newest heroscripts from git and give error if there are local changes.
If you do -gr it will pull newest heroscripts from git and overwrite local changes (careful).
'
required_args: 0
description: 'run heroscript commands'
execute: cmd_heroscript_execute
}
cmd_run_add_flags(mut cmd_run)
cmdroot.add_command(cmd_run)
}
fn cmd_heroscript_execute(cmd Command) ! {
plbook_edit_sourcetree(cmd)!
}