From b154a91867cbf37464cb5c79a082b53468093776 Mon Sep 17 00:00:00 2001 From: despiegk Date: Mon, 13 Oct 2025 08:30:42 +0400 Subject: [PATCH] ... --- cli/hero.v | 9 +- examples/gittools/test_check.hero | 3 +- examples/jobs/vfs_jobs_example.vsh | 84 ------------ install_v.sh | 14 +- .../giteaclient/giteaclient_factory_.v | 6 +- lib/clients/ipapi/ipapi_factory_.v | 6 +- lib/clients/jina/jina_factory_.v | 6 +- lib/clients/livekit/livekit_factory_.v | 6 +- lib/clients/mailclient/mailclient_factory_.v | 6 +- .../meilisearch/meilisearch_factory_.v | 6 +- lib/clients/mycelium/mycelium_factory_.v | 7 +- .../mycelium_rpc/mycelium_rpc_factory_.v | 6 +- lib/clients/openai/openai_factory_.v | 6 +- .../postgresql_client_factory_.v | 6 +- lib/clients/qdrant/qdrant_factory_.v | 6 +- lib/clients/rclone/rclone_factory_.v | 6 +- lib/clients/runpod/runpod_factory_.v | 6 +- lib/clients/sendgrid/sendgrid_factory_.v | 6 +- lib/clients/vastai/vastai_factory_.v | 6 +- lib/clients/wireguard/wireguard_factory_.v | 6 +- .../zerodb_client/zerodb_client_factory_.v | 6 +- lib/clients/zinit/zinit_factory_.v | 6 +- lib/core/generator/generic/generate.v | 2 +- lib/core/generator/generic/scanner.v | 11 +- lib/core/herocmds/generator.v | 39 +++--- lib/core/herocmds/run.v | 40 ------ lib/develop/gittools/repository_check.v | 6 +- lib/develop/heroprompt/heroprompt_factory_.v | 37 ++---- .../virt/herorunner/herorunner_factory_.v | 3 +- .../grid3/deployer/deployer_factory_.v | 124 ++++++++++++------ .../hetznermanager/hetznermanager_factory_.v | 3 + 31 files changed, 242 insertions(+), 242 deletions(-) delete mode 100644 examples/jobs/vfs_jobs_example.vsh delete mode 100644 lib/core/herocmds/run.v diff --git a/cli/hero.v b/cli/hero.v index 31f4def7..ac44c514 100644 --- a/cli/hero.v +++ b/cli/hero.v @@ -38,6 +38,10 @@ fn do() ! { if os.args.len == 2 { mypath := os.args[1] + if mypath == '.' { + playcmds_do(os.getwd())! + return + } if mypath.to_lower().ends_with('.hero') || mypath.to_lower().ends_with('.heroscript') || mypath.to_lower().ends_with('.hs') { // hero was called from a file @@ -82,7 +86,6 @@ fn do() ! { base.redis_install()! - herocmds.cmd_run(mut cmd) herocmds.cmd_git(mut cmd) herocmds.cmd_generator(mut cmd) herocmds.cmd_docusaurus(mut cmd) @@ -101,7 +104,3 @@ fn main() { exit(1) } } - -// fn pre_func(cmd Command) ! { -// herocmds.plbook_run(cmd)! -// } \ No newline at end of file diff --git a/examples/gittools/test_check.hero b/examples/gittools/test_check.hero index 77cb3720..1c0bd6ab 100644 --- a/examples/gittools/test_check.hero +++ b/examples/gittools/test_check.hero @@ -1,2 +1 @@ -!!git.check - filter: 'test_repo' \ No newline at end of file +!!git.check filter:'herolib' \ No newline at end of file diff --git a/examples/jobs/vfs_jobs_example.vsh b/examples/jobs/vfs_jobs_example.vsh deleted file mode 100644 index e17b8a22..00000000 --- a/examples/jobs/vfs_jobs_example.vsh +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/env -S v -n -w -gc none -cc tcc -d use_openssl -enable-globals run - -import incubaid.herolib.core.jobs.model -import flag -import os -import time - -// This example demonstrates using the VFS-based job storage -// - Creating jobs and storing them in VFS -// - Listing jobs from VFS -// - Cleaning up old jobs - -mut fp := flag.new_flag_parser(os.args) -fp.application('vfs_jobs_example.vsh') -fp.version('v0.1.0') -fp.description('Example of VFS-based job storage with cleanup functionality') -fp.skip_executable() - -cleanup_days := fp.int('days', `d`, 7, 'Clean up jobs older than this many days') -create_count := fp.int('create', `c`, 5, 'Number of jobs to create') -help_requested := fp.bool('help', `h`, false, 'Show help message') - -if help_requested { - println(fp.usage()) - exit(0) -} - -additional_args := fp.finalize() or { - eprintln(err) - println(fp.usage()) - exit(1) -} - -// Create a new HeroRunner instance -mut runner := model.new() or { panic('Failed to create HeroRunner: ${err}') } - -println('\n---------BEGIN VFS JOBS EXAMPLE') - -// Create some jobs -println('\n---------CREATING JOBS') -for i in 0 .. create_count { - mut job := runner.jobs.new() - job.guid = 'job_${i}_${time.now().unix}' - job.actor = 'example_actor' - job.action = 'test_action' - job.params = { - 'param1': 'value1' - 'param2': 'value2' - } - - // For demonstration, make some jobs older by adjusting their creation time - if i % 2 == 0 { - job.status.created.time = time.now().add_days(-(cleanup_days + 1)) - } - - runner.jobs.set(job) or { panic('Failed to set job: ${err}') } - println('Created job with GUID: ${job.guid}') -} - -// List all jobs -println('\n---------LISTING ALL JOBS') -jobs := runner.jobs.list() or { panic('Failed to list jobs: ${err}') } -println('Found ${jobs.len} jobs:') -for job in jobs { - days_ago := (time.now().unix - job.status.created.time.unix) / (60 * 60 * 24) - println('- ${job.guid} (created ${days_ago} days ago)') -} - -// Clean up old jobs -println('\n---------CLEANING UP OLD JOBS') -println('Cleaning up jobs older than ${cleanup_days} days...') -deleted_count := runner.cleanup_jobs(cleanup_days) or { panic('Failed to clean up jobs: ${err}') } -println('Deleted ${deleted_count} old jobs') - -// List remaining jobs -println('\n---------LISTING REMAINING JOBS') -remaining_jobs := runner.jobs.list() or { panic('Failed to list jobs: ${err}') } -println('Found ${remaining_jobs.len} remaining jobs:') -for job in remaining_jobs { - days_ago := (time.now().unix - job.status.created.time.unix) / (60 * 60 * 24) - println('- ${job.guid} (created ${days_ago} days ago)') -} - -println('\n---------END VFS JOBS EXAMPLE') diff --git a/install_v.sh b/install_v.sh index a34aeca4..3b98561b 100755 --- a/install_v.sh +++ b/install_v.sh @@ -444,7 +444,17 @@ check_and_start_redis() { fi return fi - + + if command_exists zinit; then + # Check if redis service is managed by zinit and is running + if zinit status redis | grep -q "state: Running"; then + echo "redis is already running and managed by zinit." + return + else + echo "zinit is installed, but redis is not running or not managed by zinit. Proceeding with other checks." + fi + fi + if systemctl is-active --quiet "redis"; then echo "redis is already running." else @@ -631,7 +641,7 @@ if [ "$RESET" = true ] || ! command_exists v; then fi - +# set -x check_and_start_redis if [ "$HEROLIB" = true ]; then diff --git a/lib/clients/giteaclient/giteaclient_factory_.v b/lib/clients/giteaclient/giteaclient_factory_.v index 116925b1..840c5f2b 100644 --- a/lib/clients/giteaclient/giteaclient_factory_.v +++ b/lib/clients/giteaclient/giteaclient_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&GiteaClient { if r.hexists('context:giteaclient', args.name)! { data := r.hget('context:giteaclient', args.name)! if data.len == 0 { + print_backtrace() return error('GiteaClient with name: giteaclient does not exist, prob bug.') } mut obj := json.decode(GiteaClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&GiteaClient { if args.create { new(args)! } else { + print_backtrace() return error("GiteaClient with name 'giteaclient' does not exist") } } return get(name: args.name)! // no longer from db nor create } return giteaclient_global[args.name] or { + print_backtrace() return error('could not get config for giteaclient with name:giteaclient') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'giteaclient.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/ipapi/ipapi_factory_.v b/lib/clients/ipapi/ipapi_factory_.v index 933c1904..475fb156 100644 --- a/lib/clients/ipapi/ipapi_factory_.v +++ b/lib/clients/ipapi/ipapi_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&IPApi { if r.hexists('context:ipapi', args.name)! { data := r.hget('context:ipapi', args.name)! if data.len == 0 { + print_backtrace() return error('IPApi with name: ipapi does not exist, prob bug.') } mut obj := json.decode(IPApi, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&IPApi { if args.create { new(args)! } else { + print_backtrace() return error("IPApi with name 'ipapi' does not exist") } } return get(name: args.name)! // no longer from db nor create } return ipapi_global[args.name] or { + print_backtrace() return error('could not get config for ipapi with name:ipapi') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'ipapi.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/jina/jina_factory_.v b/lib/clients/jina/jina_factory_.v index 2f5006a1..9fbc17b8 100644 --- a/lib/clients/jina/jina_factory_.v +++ b/lib/clients/jina/jina_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&Jina { if r.hexists('context:jina', args.name)! { data := r.hget('context:jina', args.name)! if data.len == 0 { + print_backtrace() return error('Jina with name: jina does not exist, prob bug.') } mut obj := json.decode(Jina, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&Jina { if args.create { new(args)! } else { + print_backtrace() return error("Jina with name 'jina' does not exist") } } return get(name: args.name)! // no longer from db nor create } return jina_global[args.name] or { + print_backtrace() return error('could not get config for jina with name:jina') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'jina.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/livekit/livekit_factory_.v b/lib/clients/livekit/livekit_factory_.v index d50bcc6b..9ba5045c 100644 --- a/lib/clients/livekit/livekit_factory_.v +++ b/lib/clients/livekit/livekit_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&LivekitClient { if r.hexists('context:livekit', args.name)! { data := r.hget('context:livekit', args.name)! if data.len == 0 { + print_backtrace() return error('LivekitClient with name: livekit does not exist, prob bug.') } mut obj := json.decode(LivekitClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&LivekitClient { if args.create { new(args)! } else { + print_backtrace() return error("LivekitClient with name 'livekit' does not exist") } } return get(name: args.name)! // no longer from db nor create } return livekit_global[args.name] or { + print_backtrace() return error('could not get config for livekit with name:livekit') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'livekit.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/mailclient/mailclient_factory_.v b/lib/clients/mailclient/mailclient_factory_.v index 03b6ed6e..8c906b87 100644 --- a/lib/clients/mailclient/mailclient_factory_.v +++ b/lib/clients/mailclient/mailclient_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MailClient { if r.hexists('context:mailclient', args.name)! { data := r.hget('context:mailclient', args.name)! if data.len == 0 { + print_backtrace() return error('MailClient with name: mailclient does not exist, prob bug.') } mut obj := json.decode(MailClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MailClient { if args.create { new(args)! } else { + print_backtrace() return error("MailClient with name 'mailclient' does not exist") } } return get(name: args.name)! // no longer from db nor create } return mailclient_global[args.name] or { + print_backtrace() return error('could not get config for mailclient with name:mailclient') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'mailclient.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/meilisearch/meilisearch_factory_.v b/lib/clients/meilisearch/meilisearch_factory_.v index 3d3992ff..edba0702 100644 --- a/lib/clients/meilisearch/meilisearch_factory_.v +++ b/lib/clients/meilisearch/meilisearch_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MeilisearchClient { if r.hexists('context:meilisearch', args.name)! { data := r.hget('context:meilisearch', args.name)! if data.len == 0 { + print_backtrace() return error('MeilisearchClient with name: meilisearch does not exist, prob bug.') } mut obj := json.decode(MeilisearchClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MeilisearchClient { if args.create { new(args)! } else { + print_backtrace() return error("MeilisearchClient with name 'meilisearch' does not exist") } } return get(name: args.name)! // no longer from db nor create } return meilisearch_global[args.name] or { + print_backtrace() return error('could not get config for meilisearch with name:meilisearch') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'meilisearch.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/mycelium/mycelium_factory_.v b/lib/clients/mycelium/mycelium_factory_.v index 449d8ea6..d3ede4c1 100644 --- a/lib/clients/mycelium/mycelium_factory_.v +++ b/lib/clients/mycelium/mycelium_factory_.v @@ -2,6 +2,7 @@ module mycelium import incubaid.herolib.core.base import incubaid.herolib.core.playbook { PlayBook } +import incubaid.herolib.ui.console import json __global ( @@ -35,6 +36,7 @@ pub fn get(args ArgsGet) !&Mycelium { if r.hexists('context:mycelium', args.name)! { data := r.hget('context:mycelium', args.name)! if data.len == 0 { + print_backtrace() return error('Mycelium with name: mycelium does not exist, prob bug.') } mut obj := json.decode(Mycelium, data)! @@ -43,12 +45,14 @@ pub fn get(args ArgsGet) !&Mycelium { if args.create { new(args)! } else { + print_backtrace() return error("Mycelium with name 'mycelium' does not exist") } } return get(name: args.name)! // no longer from db nor create } return mycelium_global[args.name] or { + print_backtrace() return error('could not get config for mycelium with name:mycelium') } } @@ -121,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'mycelium.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v b/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v index 399cc230..0cfc94c7 100644 --- a/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v +++ b/lib/clients/mycelium_rpc/mycelium_rpc_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&MyceliumRPC { if r.hexists('context:mycelium_rpc', args.name)! { data := r.hget('context:mycelium_rpc', args.name)! if data.len == 0 { + print_backtrace() return error('MyceliumRPC with name: mycelium_rpc does not exist, prob bug.') } mut obj := json.decode(MyceliumRPC, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&MyceliumRPC { if args.create { new(args)! } else { + print_backtrace() return error("MyceliumRPC with name 'mycelium_rpc' does not exist") } } return get(name: args.name)! // no longer from db nor create } return mycelium_rpc_global[args.name] or { + print_backtrace() return error('could not get config for mycelium_rpc with name:mycelium_rpc') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'mycelium_rpc.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/openai/openai_factory_.v b/lib/clients/openai/openai_factory_.v index 14187a0e..e24c132a 100644 --- a/lib/clients/openai/openai_factory_.v +++ b/lib/clients/openai/openai_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&OpenAI { if r.hexists('context:openai', args.name)! { data := r.hget('context:openai', args.name)! if data.len == 0 { + print_backtrace() return error('OpenAI with name: openai does not exist, prob bug.') } mut obj := json.decode(OpenAI, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&OpenAI { if args.create { new(args)! } else { + print_backtrace() return error("OpenAI with name 'openai' does not exist") } } return get(name: args.name)! // no longer from db nor create } return openai_global[args.name] or { + print_backtrace() return error('could not get config for openai with name:openai') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'openai.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/postgresql_client/postgresql_client_factory_.v b/lib/clients/postgresql_client/postgresql_client_factory_.v index c3fa262d..7daa898c 100644 --- a/lib/clients/postgresql_client/postgresql_client_factory_.v +++ b/lib/clients/postgresql_client/postgresql_client_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&PostgresqlClient { if r.hexists('context:postgresql_client', args.name)! { data := r.hget('context:postgresql_client', args.name)! if data.len == 0 { + print_backtrace() return error('PostgresqlClient with name: postgresql_client does not exist, prob bug.') } mut obj := json.decode(PostgresqlClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&PostgresqlClient { if args.create { new(args)! } else { + print_backtrace() return error("PostgresqlClient with name 'postgresql_client' does not exist") } } return get(name: args.name)! // no longer from db nor create } return postgresql_client_global[args.name] or { + print_backtrace() return error('could not get config for postgresql_client with name:postgresql_client') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'postgresql_client.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/qdrant/qdrant_factory_.v b/lib/clients/qdrant/qdrant_factory_.v index 889bbb4b..f00cf534 100644 --- a/lib/clients/qdrant/qdrant_factory_.v +++ b/lib/clients/qdrant/qdrant_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&QDrantClient { if r.hexists('context:qdrant', args.name)! { data := r.hget('context:qdrant', args.name)! if data.len == 0 { + print_backtrace() return error('QDrantClient with name: qdrant does not exist, prob bug.') } mut obj := json.decode(QDrantClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&QDrantClient { if args.create { new(args)! } else { + print_backtrace() return error("QDrantClient with name 'qdrant' does not exist") } } return get(name: args.name)! // no longer from db nor create } return qdrant_global[args.name] or { + print_backtrace() return error('could not get config for qdrant with name:qdrant') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'qdrant.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/rclone/rclone_factory_.v b/lib/clients/rclone/rclone_factory_.v index 627fffd1..8f6483e7 100644 --- a/lib/clients/rclone/rclone_factory_.v +++ b/lib/clients/rclone/rclone_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RCloneClient { if r.hexists('context:rclone', args.name)! { data := r.hget('context:rclone', args.name)! if data.len == 0 { + print_backtrace() return error('RCloneClient with name: rclone does not exist, prob bug.') } mut obj := json.decode(RCloneClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RCloneClient { if args.create { new(args)! } else { + print_backtrace() return error("RCloneClient with name 'rclone' does not exist") } } return get(name: args.name)! // no longer from db nor create } return rclone_global[args.name] or { + print_backtrace() return error('could not get config for rclone with name:rclone') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'rclone.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/runpod/runpod_factory_.v b/lib/clients/runpod/runpod_factory_.v index 5767a054..e9977edb 100644 --- a/lib/clients/runpod/runpod_factory_.v +++ b/lib/clients/runpod/runpod_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&RunPod { if r.hexists('context:runpod', args.name)! { data := r.hget('context:runpod', args.name)! if data.len == 0 { + print_backtrace() return error('RunPod with name: runpod does not exist, prob bug.') } mut obj := json.decode(RunPod, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&RunPod { if args.create { new(args)! } else { + print_backtrace() return error("RunPod with name 'runpod' does not exist") } } return get(name: args.name)! // no longer from db nor create } return runpod_global[args.name] or { + print_backtrace() return error('could not get config for runpod with name:runpod') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'runpod.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/sendgrid/sendgrid_factory_.v b/lib/clients/sendgrid/sendgrid_factory_.v index 4b17f855..fe3d2dfa 100644 --- a/lib/clients/sendgrid/sendgrid_factory_.v +++ b/lib/clients/sendgrid/sendgrid_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&SendGrid { if r.hexists('context:sendgrid', args.name)! { data := r.hget('context:sendgrid', args.name)! if data.len == 0 { + print_backtrace() return error('SendGrid with name: sendgrid does not exist, prob bug.') } mut obj := json.decode(SendGrid, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&SendGrid { if args.create { new(args)! } else { + print_backtrace() return error("SendGrid with name 'sendgrid' does not exist") } } return get(name: args.name)! // no longer from db nor create } return sendgrid_global[args.name] or { + print_backtrace() return error('could not get config for sendgrid with name:sendgrid') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'sendgrid.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/vastai/vastai_factory_.v b/lib/clients/vastai/vastai_factory_.v index 0b64ee75..c1390d8d 100644 --- a/lib/clients/vastai/vastai_factory_.v +++ b/lib/clients/vastai/vastai_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&VastAI { if r.hexists('context:vastai', args.name)! { data := r.hget('context:vastai', args.name)! if data.len == 0 { + print_backtrace() return error('VastAI with name: vastai does not exist, prob bug.') } mut obj := json.decode(VastAI, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&VastAI { if args.create { new(args)! } else { + print_backtrace() return error("VastAI with name 'vastai' does not exist") } } return get(name: args.name)! // no longer from db nor create } return vastai_global[args.name] or { + print_backtrace() return error('could not get config for vastai with name:vastai') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'vastai.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/wireguard/wireguard_factory_.v b/lib/clients/wireguard/wireguard_factory_.v index b356d38a..a5198606 100644 --- a/lib/clients/wireguard/wireguard_factory_.v +++ b/lib/clients/wireguard/wireguard_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&WireGuard { if r.hexists('context:wireguard', args.name)! { data := r.hget('context:wireguard', args.name)! if data.len == 0 { + print_backtrace() return error('WireGuard with name: wireguard does not exist, prob bug.') } mut obj := json.decode(WireGuard, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&WireGuard { if args.create { new(args)! } else { + print_backtrace() return error("WireGuard with name 'wireguard' does not exist") } } return get(name: args.name)! // no longer from db nor create } return wireguard_global[args.name] or { + print_backtrace() return error('could not get config for wireguard with name:wireguard') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'wireguard.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/zerodb_client/zerodb_client_factory_.v b/lib/clients/zerodb_client/zerodb_client_factory_.v index fa73b1f3..651d65a7 100644 --- a/lib/clients/zerodb_client/zerodb_client_factory_.v +++ b/lib/clients/zerodb_client/zerodb_client_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZeroDBClient { if r.hexists('context:zerodb_client', args.name)! { data := r.hget('context:zerodb_client', args.name)! if data.len == 0 { + print_backtrace() return error('ZeroDBClient with name: zerodb_client does not exist, prob bug.') } mut obj := json.decode(ZeroDBClient, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZeroDBClient { if args.create { new(args)! } else { + print_backtrace() return error("ZeroDBClient with name 'zerodb_client' does not exist") } } return get(name: args.name)! // no longer from db nor create } return zerodb_client_global[args.name] or { + print_backtrace() return error('could not get config for zerodb_client with name:zerodb_client') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'zerodb_client.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/clients/zinit/zinit_factory_.v b/lib/clients/zinit/zinit_factory_.v index 0b26a24e..402eb3b0 100644 --- a/lib/clients/zinit/zinit_factory_.v +++ b/lib/clients/zinit/zinit_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&ZinitRPC { if r.hexists('context:zinit', args.name)! { data := r.hget('context:zinit', args.name)! if data.len == 0 { + print_backtrace() return error('ZinitRPC with name: zinit does not exist, prob bug.') } mut obj := json.decode(ZinitRPC, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&ZinitRPC { if args.create { new(args)! } else { + print_backtrace() return error("ZinitRPC with name 'zinit' does not exist") } } return get(name: args.name)! // no longer from db nor create } return zinit_global[args.name] or { + print_backtrace() return error('could not get config for zinit with name:zinit') } } @@ -122,10 +125,11 @@ pub fn play(mut plbook PlayBook) ! { } mut install_actions := plbook.find(filter: 'zinit.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } diff --git a/lib/core/generator/generic/generate.v b/lib/core/generator/generic/generate.v index 45c37dc9..bc4c052c 100644 --- a/lib/core/generator/generic/generate.v +++ b/lib/core/generator/generic/generate.v @@ -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 == '' { diff --git a/lib/core/generator/generic/scanner.v b/lib/core/generator/generic/scanner.v index 81a72cb1..6985aa18 100644 --- a/lib/core/generator/generic/scanner.v +++ b/lib/core/generator/generic/scanner.v @@ -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; } diff --git a/lib/core/herocmds/generator.v b/lib/core/herocmds/generator.v index a5db411a..5cb82b2d 100644 --- a/lib/core/herocmds/generator.v +++ b/lib/core/herocmds/generator.v @@ -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 { diff --git a/lib/core/herocmds/run.v b/lib/core/herocmds/run.v deleted file mode 100644 index 77dd1170..00000000 --- a/lib/core/herocmds/run.v +++ /dev/null @@ -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)! -} diff --git a/lib/develop/gittools/repository_check.v b/lib/develop/gittools/repository_check.v index 827268e1..213e48af 100644 --- a/lib/develop/gittools/repository_check.v +++ b/lib/develop/gittools/repository_check.v @@ -2,7 +2,7 @@ module gittools pub fn (mut repo GitRepo) check() ! { repo.init()! - if repo.lfs()! { - repo.lfs_check()! - } + // if repo.lfs()! { + // repo.lfs_check()! + // } } diff --git a/lib/develop/heroprompt/heroprompt_factory_.v b/lib/develop/heroprompt/heroprompt_factory_.v index 2a474891..7b12dd25 100644 --- a/lib/develop/heroprompt/heroprompt_factory_.v +++ b/lib/develop/heroprompt/heroprompt_factory_.v @@ -16,15 +16,13 @@ __global ( pub struct ArgsGet { pub mut: name string = 'default' - path string fromdb bool // will load from filesystem create bool // default will not create if not exist } pub fn new(args ArgsGet) !&Workspace { mut obj := Workspace{ - name: args.name - base_path: args.path + name: args.name } set(obj)! return get(name: args.name)! @@ -38,6 +36,7 @@ pub fn get(args ArgsGet) !&Workspace { if r.hexists('context:heroprompt', args.name)! { data := r.hget('context:heroprompt', args.name)! if data.len == 0 { + print_backtrace() return error('Workspace with name: heroprompt does not exist, prob bug.') } mut obj := json.decode(Workspace, data)! @@ -46,12 +45,14 @@ pub fn get(args ArgsGet) !&Workspace { if args.create { new(args)! } else { + print_backtrace() return error("Workspace with name 'heroprompt' does not exist") } } return get(name: args.name)! // no longer from db nor create } return heroprompt_global[args.name] or { + print_backtrace() return error('could not get config for heroprompt with name:heroprompt') } } @@ -122,28 +123,14 @@ pub fn play(mut plbook PlayBook) ! { if !plbook.exists(filter: 'heroprompt.') { return } - // 1) Configure workspaces - mut cfg_actions := plbook.find(filter: 'heroprompt.configure')! - for cfg_action in cfg_actions { - heroscript := cfg_action.heroscript() - mut obj := heroscript_loads(heroscript)! - set(obj)! - } - // 2) Add directories - for action in plbook.find(filter: 'heroprompt.add_dir')! { - mut p := action.params - wsname := p.get_default('name', heroprompt_default)! - mut wsp := get(name: wsname)! - path := p.get('path') or { return error("heroprompt.add_dir requires 'path'") } - wsp.add_dir(path: path)! - } - // 3) Add files - for action in plbook.find(filter: 'heroprompt.add_file')! { - mut p := action.params - wsname := p.get_default('name', heroprompt_default)! - mut wsp := get(name: wsname)! - path := p.get('path') or { return error("heroprompt.add_file requires 'path'") } - wsp.add_file(path: path)! + mut install_actions := plbook.find(filter: 'heroprompt.configure')! + if install_actions.len > 0 { + for mut install_action in install_actions { + heroscript := install_action.heroscript() + mut obj2 := heroscript_loads(heroscript)! + set(obj2)! + install_action.done = true + } } } diff --git a/lib/installers/virt/herorunner/herorunner_factory_.v b/lib/installers/virt/herorunner/herorunner_factory_.v index 793510b5..daf72af6 100644 --- a/lib/installers/virt/herorunner/herorunner_factory_.v +++ b/lib/installers/virt/herorunner/herorunner_factory_.v @@ -35,7 +35,7 @@ pub fn play(mut plbook PlayBook) ! { return error("can't configure herorunner, because no configuration allowed for this installer.") } mut other_actions := plbook.find(filter: 'herorunner.')! - for other_action in other_actions { + for mut other_action in other_actions { if other_action.name in ['destroy', 'install', 'build'] { mut p := other_action.params reset := p.get_default_false('reset') @@ -48,6 +48,7 @@ pub fn play(mut plbook PlayBook) ! { install()! } } + other_action.done = true } } diff --git a/lib/threefold/grid3/deployer/deployer_factory_.v b/lib/threefold/grid3/deployer/deployer_factory_.v index 3367087b..99b3f920 100644 --- a/lib/threefold/grid3/deployer/deployer_factory_.v +++ b/lib/threefold/grid3/deployer/deployer_factory_.v @@ -3,6 +3,7 @@ module deployer import incubaid.herolib.core.base import incubaid.herolib.core.playbook { PlayBook } import incubaid.herolib.ui.console +import json __global ( deployer_global map[string]&TFGridDeployer @@ -14,77 +15,121 @@ __global ( @[params] pub struct ArgsGet { pub mut: - name string + name string = 'default' + fromdb bool // will load from filesystem + create bool // default will not create if not exist } -fn args_get(args_ ArgsGet) ArgsGet { - mut args := args_ - if args.name == '' { - args.name = 'default' - } - return args -} - -pub fn get(args_ ArgsGet) !&TFGridDeployer { - mut context := base.context()! - mut args := args_get(args_) +pub fn new(args ArgsGet) !&TFGridDeployer { mut obj := TFGridDeployer{ name: args.name } - if args.name !in deployer_global { - if !exists(args)! { - set(obj)! + set(obj)! + return get(name: args.name)! +} + +pub fn get(args ArgsGet) !&TFGridDeployer { + mut context := base.context()! + deployer_default = args.name + if args.fromdb || args.name !in deployer_global { + mut r := context.redis()! + if r.hexists('context:deployer', args.name)! { + data := r.hget('context:deployer', args.name)! + if data.len == 0 { + print_backtrace() + return error('TFGridDeployer with name: deployer does not exist, prob bug.') + } + mut obj := json.decode(TFGridDeployer, data)! + set_in_mem(obj)! } else { - heroscript := context.hero_config_get('deployer', args.name)! - mut obj_ := heroscript_loads(heroscript)! - set_in_mem(obj_)! + if args.create { + new(args)! + } else { + print_backtrace() + return error("TFGridDeployer with name 'deployer' does not exist") + } } + return get(name: args.name)! // no longer from db nor create } return deployer_global[args.name] or { - println(deployer_global) - // bug if we get here because should be in globals - panic('could not get config for deployer with name, is bug:${args.name}') + print_backtrace() + return error('could not get config for deployer with name:deployer') } } // register the config for the future pub fn set(o TFGridDeployer) ! { - set_in_mem(o)! + mut o2 := set_in_mem(o)! + deployer_default = o2.name mut context := base.context()! - heroscript := heroscript_dumps(o)! - context.hero_config_set('deployer', o.name, heroscript)! + mut r := context.redis()! + r.hset('context:deployer', o2.name, json.encode(o2))! } // does the config exists? -pub fn exists(args_ ArgsGet) !bool { +pub fn exists(args ArgsGet) !bool { mut context := base.context()! - mut args := args_get(args_) - return context.hero_config_exists('deployer', args.name) + mut r := context.redis()! + return r.hexists('context:deployer', args.name)! } -pub fn delete(args_ ArgsGet) ! { - mut args := args_get(args_) +pub fn delete(args ArgsGet) ! { mut context := base.context()! - context.hero_config_delete('deployer', args.name)! - if args.name in deployer_global { - // del deployer_global[args.name] + mut r := context.redis()! + r.hdel('context:deployer', args.name)! +} + +@[params] +pub struct ArgsList { +pub mut: + fromdb bool // will load from filesystem +} + +// if fromdb set: load from filesystem, and not from mem, will also reset what is in mem +pub fn list(args ArgsList) ![]&TFGridDeployer { + mut res := []&TFGridDeployer{} + mut context := base.context()! + if args.fromdb { + // reset what is in mem + deployer_global = map[string]&TFGridDeployer{} + deployer_default = '' } + if args.fromdb { + mut r := context.redis()! + mut l := r.hkeys('context:deployer')! + + for name in l { + res << get(name: name, fromdb: true)! + } + return res + } else { + // load from memory + for _, client in deployer_global { + res << client + } + } + return res } // only sets in mem, does not set as config -fn set_in_mem(o TFGridDeployer) ! { +fn set_in_mem(o TFGridDeployer) !TFGridDeployer { mut o2 := obj_init(o)! - deployer_global[o.name] = &o2 - deployer_default = o.name + deployer_global[o2.name] = &o2 + deployer_default = o2.name + return o2 } pub fn play(mut plbook PlayBook) ! { + if !plbook.exists(filter: 'deployer.') { + return + } mut install_actions := plbook.find(filter: 'deployer.configure')! if install_actions.len > 0 { - for install_action in install_actions { + for mut install_action in install_actions { heroscript := install_action.heroscript() mut obj2 := heroscript_loads(heroscript)! set(obj2)! + install_action.done = true } } } @@ -93,10 +138,3 @@ pub fn play(mut plbook PlayBook) ! { pub fn switch(name string) { deployer_default = name } - -// helpers - -@[params] -pub struct DefaultConfigArgs { - instance string = 'default' -} diff --git a/lib/virt/hetznermanager/hetznermanager_factory_.v b/lib/virt/hetznermanager/hetznermanager_factory_.v index 93fbdd04..8c6bdf9c 100644 --- a/lib/virt/hetznermanager/hetznermanager_factory_.v +++ b/lib/virt/hetznermanager/hetznermanager_factory_.v @@ -36,6 +36,7 @@ pub fn get(args ArgsGet) !&HetznerManager { if r.hexists('context:hetznermanager', args.name)! { data := r.hget('context:hetznermanager', args.name)! if data.len == 0 { + print_backtrace() return error('HetznerManager with name: hetznermanager does not exist, prob bug.') } mut obj := json.decode(HetznerManager, data)! @@ -44,12 +45,14 @@ pub fn get(args ArgsGet) !&HetznerManager { if args.create { new(args)! } else { + print_backtrace() return error("HetznerManager with name 'hetznermanager' does not exist") } } return get(name: args.name)! // no longer from db nor create } return hetznermanager_global[args.name] or { + print_backtrace() return error('could not get config for hetznermanager with name:hetznermanager') } }