diff --git a/examples/core/openapi/gitea/gitea_client/client.v b/examples/core/openapi/gitea/gitea_client/client.v deleted file mode 100644 index 9c6bbe14..00000000 --- a/examples/core/openapi/gitea/gitea_client/client.v +++ /dev/null @@ -1,4 +0,0 @@ -module gitea_client - -struct GiteaClient { -} diff --git a/examples/core/openapi/gitea/gitea_client/factory.v b/examples/core/openapi/gitea/gitea_client/factory.v deleted file mode 100644 index 00a52a5b..00000000 --- a/examples/core/openapi/gitea/gitea_client/factory.v +++ /dev/null @@ -1,83 +0,0 @@ -module dagu - -// import os -import freeflowuniverse.herolib.core.httpconnection -import os - -struct GiteaClient[T] { - base.Base[T] -mut: - connection &httpconnection.HTTPConnection -} - -struct Config { - play.ConfigBase[T] - url string -} - -// -pub fn get(args PlayArgs) GiteaClient[Config] { - mut client := GiteaClient[Config]{} - client.init(args)! - return client -} - -// -pub fn heroplay(args PlayBookAddArgs) ! { - // make session for configuring from heroscript - mut session := play.session_new(session_name: 'config')! - session.playbook_add(path: args.path, text: args.text, git_url: args.git_url)! - for mut action in session.plbook.find(filter: 'gitea_client.define')! { - mut p := action.params - instance := p.get_default('instance', 'default')! - mut cl := get(instance: instance)! - mut cfg := cl.config()! - mut config := p.decode[T]()! - cl.config_save()! - } -} - -// -pub fn (self GiteaClient[T]) config_interactive() ! { - mut myui := ui.new()! - console.clear() - println(' -## Configure B2 Client') - println('======================== - -') - - mut cfg := self.config()! - - self.instance = myui.ask_question( - question: 'name for B2 (backblaze) client' - default: self.instance - )! - - cfg.description = myui.ask_question( - question: 'description' - minlen: 0 - default: cfg.description - )! - cfg.keyid = myui.ask_question( - question: 'keyid e.g. 003e2a7be6357fb0000000001' - minlen: 5 - default: cfg.keyid - )! - - cfg.appkey = myui.ask_question( - question: 'appkey e.g. K008UsdrYOAou2ulBHA8p4KBe/dL2n4' - minlen: 5 - default: cfg.appkey - )! - - buckets := self.list_buckets()! - bucket_names := buckets.map(it.name) - - cfg.bucketname = myui.ask_dropdown( - question: 'choose default bucket name' - items: bucket_names - )! - - self.config_save()! -} diff --git a/examples/core/openapi/gitea/gitea_client/model.v b/examples/core/openapi/gitea/gitea_client/model.v deleted file mode 100644 index 08eb1783..00000000 --- a/examples/core/openapi/gitea/gitea_client/model.v +++ /dev/null @@ -1 +0,0 @@ -module gitea_client diff --git a/lib/clients/gitea_client/.heroscript b/lib/clients/gitea_client/.heroscript new file mode 100644 index 00000000..3b85ca0d --- /dev/null +++ b/lib/clients/gitea_client/.heroscript @@ -0,0 +1,8 @@ + +!!hero_code.generate_client + name:'gitea_client' + classname:'GiteaClient' + singleton:0 + default:1 + hasconfig:1 + reset:0 \ No newline at end of file diff --git a/lib/clients/gitea_client/gitea_client_factory_.v b/lib/clients/gitea_client/gitea_client_factory_.v new file mode 100644 index 00000000..c4fa8160 --- /dev/null +++ b/lib/clients/gitea_client/gitea_client_factory_.v @@ -0,0 +1,102 @@ +module gitea_client + +import freeflowuniverse.herolib.core.base +import freeflowuniverse.herolib.core.playbook { PlayBook } +import freeflowuniverse.herolib.ui.console + +__global ( + gitea_client_global map[string]&GiteaClient + gitea_client_default string +) + +/////////FACTORY + +@[params] +pub struct ArgsGet { +pub mut: + name string +} + +fn args_get(args_ ArgsGet) ArgsGet { + mut args := args_ + if args.name == '' { + args.name = 'default' + } + return args +} + +pub fn get(args_ ArgsGet) !&GiteaClient { + mut context := base.context()! + mut args := args_get(args_) + mut obj := GiteaClient{ + name: args.name + } + if args.name !in gitea_client_global { + if !exists(args)! { + set(obj)! + } else { + heroscript := context.hero_config_get('gitea_client', args.name)! + mut obj_ := heroscript_loads(heroscript)! + set_in_mem(obj_)! + } + } + return gitea_client_global[args.name] or { + println(gitea_client_global) + // bug if we get here because should be in globals + panic('could not get config for gitea_client with name, is bug:${args.name}') + } +} + +// register the config for the future +pub fn set(o GiteaClient) ! { + set_in_mem(o)! + mut context := base.context()! + heroscript := heroscript_dumps(o)! + context.hero_config_set('gitea_client', o.name, heroscript)! +} + +// does the config exists? +pub fn exists(args_ ArgsGet) !bool { + mut context := base.context()! + mut args := args_get(args_) + return context.hero_config_exists('gitea_client', args.name) +} + +pub fn delete(args_ ArgsGet) ! { + mut args := args_get(args_) + mut context := base.context()! + context.hero_config_delete('gitea_client', args.name)! + if args.name in gitea_client_global { + // del gitea_client_global[args.name] + } +} + +// only sets in mem, does not set as config +fn set_in_mem(o GiteaClient) ! { + mut o2 := obj_init(o)! + gitea_client_global[o.name] = &o2 + gitea_client_default = o.name +} + +pub fn play(mut plbook PlayBook) ! { + mut install_actions := plbook.find(filter: 'gitea_client.configure')! + if install_actions.len > 0 { + for install_action in install_actions { + heroscript := install_action.heroscript() + mut obj2 := heroscript_loads(heroscript)! + set(obj2)! + } + } +} + +// switch instance to be used for gitea_client +pub fn switch(name string) { + gitea_client_default = name +} + +// helpers + +@[params] +pub struct DefaultConfigArgs { + instance string = 'default' +} diff --git a/lib/clients/gitea_client/gitea_client_model.v b/lib/clients/gitea_client/gitea_client_model.v new file mode 100644 index 00000000..40b31f18 --- /dev/null +++ b/lib/clients/gitea_client/gitea_client_model.v @@ -0,0 +1,42 @@ +module gitea_client + +import freeflowuniverse.herolib.data.paramsparser +import freeflowuniverse.herolib.data.encoderhero +import os + +pub const version = '0.0.0' +const singleton = false +const default = true + +// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED + +@[heap] +pub struct GiteaClient { +pub mut: + name string = 'default' + url string = "https://git.ourworld.tf" + key string +} + +// your checking & initialization code if needed +fn obj_init(mycfg_ GiteaClient) !GiteaClient { + mut mycfg := mycfg_ + if mycfg.url == '' { + return error('url needs to be filled in for ${mycfg.name}') + } + if mycfg.key == '' { + return error('key needs to be filled in for ${mycfg.name}') + } + return mycfg +} + +/////////////NORMALLY NO NEED TO TOUCH + +pub fn heroscript_dumps(obj GiteaClient) !string { + return encoderhero.encode[GiteaClient](obj)! +} + +pub fn heroscript_loads(heroscript string) !GiteaClient { + mut obj := encoderhero.decode[GiteaClient](heroscript)! + return obj +} diff --git a/examples/core/openapi/gitea/gitea_client/methods.v b/lib/clients/gitea_client/methods.v similarity index 100% rename from examples/core/openapi/gitea/gitea_client/methods.v rename to lib/clients/gitea_client/methods.v diff --git a/lib/clients/gitea_client/readme.md b/lib/clients/gitea_client/readme.md new file mode 100644 index 00000000..5bf14612 --- /dev/null +++ b/lib/clients/gitea_client/readme.md @@ -0,0 +1,29 @@ +# gitea_client + + + +To get started + +```vlang + + +import freeflowuniverse.herolib.clients.gitea_client + +mut client:= gitea_client.get()! + +client... + + + + +``` + +## example heroscript + +```hero +!!gitea_client.configure + url: 'https://git.ourworld.tf/' + key: '...' +``` + + diff --git a/lib/web/docusaurus/dsite.v b/lib/web/docusaurus/dsite.v index 2ea3f876..81868ab3 100644 --- a/lib/web/docusaurus/dsite.v +++ b/lib/web/docusaurus/dsite.v @@ -35,7 +35,7 @@ pub fn (mut s DocSite) build_dev_publish() ! { osal.exec( cmd: ' cd ${s.path_build.path} - bun run build + bun run buildp ' retry: 0 )!