set schema on script template change

This commit is contained in:
Ruben Fiszel
2023-04-06 23:28:03 +02:00
parent 92be102a07
commit 8fe68c832b
3 changed files with 20 additions and 8 deletions
+14
View File
@@ -268,6 +268,20 @@ async fn copy_cache_from_bucket_as_tar(bucket: &str) -> bool {
return r;
}
async fn check_if_bucket_syncable(bucket: &str) -> bool {
match Command::new("rclone")
.arg("lsf")
.arg(format!(":s3,env_auth=true:{bucket}/NOSYNC"))
.arg("-vv")
.arg("--fast-list")
.stdin(Stdio::null())
.stdout(Stdio::null())
.output()
.await;
return true;
}
async fn move_tmp_cache_to_cache() -> Result<()> {
tokio::fs::remove_dir_all(ROOT_CACHE_DIR).await?;
tokio::fs::rename(ROOT_TMP_CACHE_DIR, ROOT_CACHE_DIR).await?;
@@ -31,6 +31,7 @@
let advancedOpen = false
let editor: Editor | undefined = undefined
let scriptEditor: ScriptEditor | undefined = undefined
export function setCode(code: string): void {
editor?.setCode(code)
@@ -79,6 +80,7 @@
template: 'pgsql' | 'mysql' | 'script'
) {
script.content = initialCode(language, kind, template)
scriptEditor?.inferSchema(script.content, language)
}
async function editScript(leave: boolean): Promise<void> {
@@ -331,6 +333,7 @@
</Drawer>
<ScriptEditor
bind:editor
bind:this={scriptEditor}
bind:schema={script.schema}
path={script.path}
bind:code={script.content}
@@ -68,7 +68,7 @@
})
}
async function inferSchema(code: string) {
export async function inferSchema(code: string, nlang?: 'go' | 'bash' | 'python3' | 'deno') {
schema = schema ?? emptySchema()
let isDefault: string[] = []
Object.entries(args).forEach(([k, v]) => {
@@ -78,7 +78,7 @@
})
try {
await inferArgs(lang, code, schema)
await inferArgs(nlang ?? lang, code, schema)
validCode = true
} catch (e) {
validCode = false
@@ -146,12 +146,7 @@
<SplitPanesWrapper>
<Splitpanes class="!overflow-visible">
<Pane size={60} minSize={10} class="!overflow-visible">
<div
class="pl-2 h-full !overflow-visible"
on:mouseleave={() => {
inferSchema(code)
}}
>
<div class="pl-2 h-full !overflow-visible">
{#key lang}
<Editor
bind:code