From 62a5718ccc21174c07491c83a36bab388eb2c137 Mon Sep 17 00:00:00 2001 From: Tony Worm <1390600+verdverm@users.noreply.github.com> Date: Sat, 4 May 2024 16:11:35 -0400 Subject: [PATCH] Add support for embedding user local files as strings into the CUE value during load (#363) Co-authored-by: Tony Worm --- .hof/shadow/cli/cmd/hof/flags/root.go | 2 + cmd/hof/flags/root.go | 2 + design/pflags.cue | 7 + docs/code/cmd-help/chat | 29 ++-- docs/code/cmd-help/create | 29 ++-- docs/code/cmd-help/dm | 29 ++-- docs/code/cmd-help/flow | 29 ++-- docs/code/cmd-help/fmt | 29 ++-- docs/code/cmd-help/gen | 29 ++-- docs/code/cmd-help/hof | 31 ++-- docs/code/cmd-help/mod | 29 ++-- docs/code/cmd-help/tui | 24 ++++ docs/content/data-modeling/_index.md | 2 +- docs/content/getting-started/llm-chat.md | 1 + docs/content/reference/hof-mod/_index.md | 2 +- docs/content/reference/hof-tui/_index.md | 16 +++ docs/hack/make/extern.inc | 1 + docs/layouts/partials/menu-hugo.html | 4 +- docs/layouts/partials/navbar.html | 4 +- docs/static/images/hof-tui-help.png | Bin 0 -> 520755 bytes lib/runtime/load.go | 173 ++++++++++++++++++++--- lib/runtime/runtime.go | 8 +- test/userfiles/content/cow.txt | 1 + test/userfiles/content/foo.md | 3 + test/userfiles/main.cue | 8 ++ test/userfiles/other/baz.txt | 1 + 26 files changed, 350 insertions(+), 143 deletions(-) create mode 100644 docs/code/cmd-help/tui create mode 100644 docs/content/reference/hof-tui/_index.md create mode 100644 docs/static/images/hof-tui-help.png create mode 100644 test/userfiles/content/cow.txt create mode 100644 test/userfiles/content/foo.md create mode 100644 test/userfiles/main.cue create mode 100644 test/userfiles/other/baz.txt diff --git a/.hof/shadow/cli/cmd/hof/flags/root.go b/.hof/shadow/cli/cmd/hof/flags/root.go index 1f12354c7..d8d6265bf 100644 --- a/.hof/shadow/cli/cmd/hof/flags/root.go +++ b/.hof/shadow/cli/cmd/hof/flags/root.go @@ -18,6 +18,7 @@ type RootPflagpole struct { IncludeData bool WithContext bool InjectEnv bool + UserFiles []string AllErrors bool IngoreErrors bool Stats bool @@ -37,6 +38,7 @@ func SetupRootPflags(fset *pflag.FlagSet, fpole *RootPflagpole) { fset.BoolVarP(&(fpole.IncludeData), "include-data", "D", false, "auto include all data files found with cue files") fset.BoolVarP(&(fpole.WithContext), "with-context", "", false, "add extra context for data files, usable in the -l/path flag") fset.BoolVarP(&(fpole.InjectEnv), "inject-env", "V", false, "inject all ENV VARs as default tag vars") + fset.StringArrayVarP(&(fpole.UserFiles), "user-files", "U", nil, "file globs to embed into the root value (=), use % as slash to trim before") fset.BoolVarP(&(fpole.AllErrors), "all-errors", "E", false, "print all available errors") fset.BoolVarP(&(fpole.IngoreErrors), "ignore-errors", "i", false, "turn off output and assume defaults at prompts") fset.BoolVarP(&(fpole.Stats), "stats", "", false, "print generator statistics") diff --git a/cmd/hof/flags/root.go b/cmd/hof/flags/root.go index 1f12354c7..d8d6265bf 100644 --- a/cmd/hof/flags/root.go +++ b/cmd/hof/flags/root.go @@ -18,6 +18,7 @@ type RootPflagpole struct { IncludeData bool WithContext bool InjectEnv bool + UserFiles []string AllErrors bool IngoreErrors bool Stats bool @@ -37,6 +38,7 @@ func SetupRootPflags(fset *pflag.FlagSet, fpole *RootPflagpole) { fset.BoolVarP(&(fpole.IncludeData), "include-data", "D", false, "auto include all data files found with cue files") fset.BoolVarP(&(fpole.WithContext), "with-context", "", false, "add extra context for data files, usable in the -l/path flag") fset.BoolVarP(&(fpole.InjectEnv), "inject-env", "V", false, "inject all ENV VARs as default tag vars") + fset.StringArrayVarP(&(fpole.UserFiles), "user-files", "U", nil, "file globs to embed into the root value (=), use % as slash to trim before") fset.BoolVarP(&(fpole.AllErrors), "all-errors", "E", false, "print all available errors") fset.BoolVarP(&(fpole.IngoreErrors), "ignore-errors", "i", false, "turn off output and assume defaults at prompts") fset.BoolVarP(&(fpole.Stats), "stats", "", false, "print generator statistics") diff --git a/design/pflags.cue b/design/pflags.cue index bd256fca6..ee61b8045 100644 --- a/design/pflags.cue +++ b/design/pflags.cue @@ -67,6 +67,13 @@ CliPflags: [...schema.Flag] & [ { Type: "bool" Default: "" Help: "inject all ENV VARs as default tag vars" +}, { + Name: "UserFiles" + Long: "user-files" + Short: "U" + Type: "[]string" + Default: "nil" + Help: "file globs to embed into the root value (=), use % as slash to trim before" }, { Name: "AllErrors" Long: "all-errors" diff --git a/docs/code/cmd-help/chat b/docs/code/cmd-help/chat index 77c3498b5..514c83281 100644 --- a/docs/code/cmd-help/chat +++ b/docs/code/cmd-help/chat @@ -69,19 +69,20 @@ Flags: --topp float param: TopP (default 0.42) Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof chat [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/create b/docs/code/cmd-help/create index afe65103c..3a2fc68a1 100644 --- a/docs/code/cmd-help/create +++ b/docs/code/cmd-help/create @@ -45,17 +45,18 @@ Flags: -O, --outdir string base directory to write all output to Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag diff --git a/docs/code/cmd-help/dm b/docs/code/cmd-help/dm index cacf3b0cd..68b31794c 100644 --- a/docs/code/cmd-help/dm +++ b/docs/code/cmd-help/dm @@ -111,19 +111,20 @@ Flags: -M, --model stringArray specify one or more data models to operate on Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof datamodel [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/flow b/docs/code/cmd-help/flow index 42f92a214..ffdb9158f 100644 --- a/docs/code/cmd-help/flow +++ b/docs/code/cmd-help/flow @@ -18,19 +18,20 @@ Flags: --progress print task progress as it happens Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof flow [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/fmt b/docs/code/cmd-help/fmt index c1fdef623..ed4961736 100644 --- a/docs/code/cmd-help/fmt +++ b/docs/code/cmd-help/fmt @@ -19,19 +19,20 @@ Flags: -h, --help help for fmt Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof fmt [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/gen b/docs/code/cmd-help/gen index 33d46a65f..e6a96186a 100644 --- a/docs/code/cmd-help/gen +++ b/docs/code/cmd-help/gen @@ -96,19 +96,20 @@ Flags: -W, --watch-globs stringArray filepath globs to watch for changes and trigger full regen Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof gen [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/hof b/docs/code/cmd-help/hof index 1a6cbd349..1ff8dd3ad 100644 --- a/docs/code/cmd-help/hof +++ b/docs/code/cmd-help/hof @@ -27,21 +27,22 @@ Additional commands: feedback open an issue or discussion on GitHub Flags: - -E, --all-errors print all available errors - -h, --help help for hof - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -h, --help help for hof + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof [command] --help / -h" for more information about a command. diff --git a/docs/code/cmd-help/mod b/docs/code/cmd-help/mod index 39d70975e..16fb9c63c 100644 --- a/docs/code/cmd-help/mod +++ b/docs/code/cmd-help/mod @@ -106,19 +106,20 @@ Flags: -h, --help help for mod Global Flags: - -E, --all-errors print all available errors - -i, --ignore-errors turn off output and assume defaults at prompts - -D, --include-data auto include all data files found with cue files - -V, --inject-env inject all ENV VARs as default tag vars - -I, --input stringArray extra data to unify into the root value - -p, --package string the Cue package context to use during execution - -l, --path stringArray CUE expression for single path component when placing data files - -q, --quiet turn off output and assume defaults at prompts - -d, --schema stringArray expression to select schema to apply to data files - --stats print generator statistics - -0, --stdin-empty A flag that ensure stdin is zero and does not block - -t, --tags stringArray @tags() to be injected into CUE code - -v, --verbosity int set the verbosity of output - --with-context add extra context for data files, usable in the -l/path flag + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag Use "hof mod [command] --help" for more information about a command. diff --git a/docs/code/cmd-help/tui b/docs/code/cmd-help/tui new file mode 100644 index 000000000..f6831d033 --- /dev/null +++ b/docs/code/cmd-help/tui @@ -0,0 +1,24 @@ +a terminal interface to Hof and CUE + +Usage: + hof tui [flags] + +Flags: + -h, --help help for tui + +Global Flags: + -E, --all-errors print all available errors + -i, --ignore-errors turn off output and assume defaults at prompts + -D, --include-data auto include all data files found with cue files + -V, --inject-env inject all ENV VARs as default tag vars + -I, --input stringArray extra data to unify into the root value + -p, --package string the Cue package context to use during execution + -l, --path stringArray CUE expression for single path component when placing data files + -q, --quiet turn off output and assume defaults at prompts + -d, --schema stringArray expression to select schema to apply to data files + --stats print generator statistics + -0, --stdin-empty A flag that ensure stdin is zero and does not block + -t, --tags stringArray @tags() to be injected into CUE code + -U, --user-files stringArray file globs to embed into the root value (=), use % as slash to trim before + -v, --verbosity int set the verbosity of output + --with-context add extra context for data files, usable in the -l/path flag diff --git a/docs/content/data-modeling/_index.md b/docs/content/data-modeling/_index.md index d8ff7ebb2..97e356c23 100644 --- a/docs/content/data-modeling/_index.md +++ b/docs/content/data-modeling/_index.md @@ -1,6 +1,6 @@ --- title: Data Modeling - +draft: true weight: 40 --- diff --git a/docs/content/getting-started/llm-chat.md b/docs/content/getting-started/llm-chat.md index 92b044c03..9b06a6e41 100644 --- a/docs/content/getting-started/llm-chat.md +++ b/docs/content/getting-started/llm-chat.md @@ -2,6 +2,7 @@ title: LLM Chat description: "Combining LLMs, Bard, ChatGPT, and Hof." brief: "Combining LLMs, ChatGPT, and hof." +draft: true keywords: - LLM diff --git a/docs/content/reference/hof-mod/_index.md b/docs/content/reference/hof-mod/_index.md index 1313a9e58..9e7bf7d80 100644 --- a/docs/content/reference/hof-mod/_index.md +++ b/docs/content/reference/hof-mod/_index.md @@ -10,4 +10,4 @@ Use it to initialize a new module, set versioned dependencies, and fetch them with a single command. {{}} -{{}} +{{}} diff --git a/docs/content/reference/hof-tui/_index.md b/docs/content/reference/hof-tui/_index.md new file mode 100644 index 000000000..ce20f371b --- /dev/null +++ b/docs/content/reference/hof-tui/_index.md @@ -0,0 +1,16 @@ +--- +title: "hof / tui" +linkTitle: "hof / tui" +weight: 60 +--- + +{{}} +`hof/tui` is a command for working with CUE and Hof Flow dynamically. +{{}} + +{{< youtube id="XNBqBWO4y08" >}} + +
+ +![hof tui help](/images/hof-tui-help.png) + diff --git a/docs/hack/make/extern.inc b/docs/hack/make/extern.inc index dfd6402e0..e3a094e34 100644 --- a/docs/hack/make/extern.inc +++ b/docs/hack/make/extern.inc @@ -15,4 +15,5 @@ cmdhelp: @hof fmt -h > code/cmd-help/fmt @hof create -h > code/cmd-help/create @hof chat -h > code/cmd-help/chat + @hof tui -h > code/cmd-help/tui diff --git a/docs/layouts/partials/menu-hugo.html b/docs/layouts/partials/menu-hugo.html index 1de9f0260..5d2bf8f1c 100644 --- a/docs/layouts/partials/menu-hugo.html +++ b/docs/layouts/partials/menu-hugo.html @@ -32,7 +32,7 @@ {{- if $hasChildren }} - + {{safeHTML .Params.Pre}}{{.LinkTitle}}{{safeHTML .Params.Post}} diff --git a/docs/layouts/partials/navbar.html b/docs/layouts/partials/navbar.html index ad2c9d438..4f5024348 100644 --- a/docs/layouts/partials/navbar.html +++ b/docs/layouts/partials/navbar.html @@ -13,11 +13,11 @@