diff --git a/scripts/cue.sh b/scripts/cue.sh index 5bf6ba6e67044..2fe80d7588dca 100755 --- a/scripts/cue.sh +++ b/scripts/cue.sh @@ -28,10 +28,6 @@ cmd_fmt() { list-docs-files | grep -v "${CUE_SOURCES}/reference/remap/functions/" | xargs cue fmt "$@" } -cmd_vet() { - list-docs-files | xargs cue vet --concrete --all-errors "$@" -} - cmd_eval() { list-docs-files | xargs cue eval --concrete --all-errors "$@" } @@ -53,7 +49,7 @@ cmd_build() { usage() { cat >&2 <<-EOF -Usage: $0 [build|check|fmt|list|vet|eval|export] +Usage: $0 [build|check|fmt|list|eval|export] Modes: build - build all of the CUE sources and export them into a Hugo-processable @@ -61,7 +57,6 @@ Modes: check - check for the CUE sources' correctness fmt - format all CUE files using the built-in formatter list - list all the documentation files - vet - check the documentation files and print errors eval - print the evaluated documentation, optionally pass the expression to evaluate via "-e EXPRESSION" export - export the documentation, @@ -92,7 +87,7 @@ EOF MODE="${1:-}" case "$MODE" in - build|check|fmt|list|vet|eval|export) + build|check|fmt|list|eval|export) shift "cmd_$MODE" "$@" ;; diff --git a/vdev/src/commands/check/docs.rs b/vdev/src/commands/check/docs.rs index abff220b56163..33e58de6c368a 100644 --- a/vdev/src/commands/check/docs.rs +++ b/vdev/src/commands/check/docs.rs @@ -1,7 +1,10 @@ use crate::app; use crate::app::CommandExt; -use crate::utils::git; -use anyhow::{Result, bail}; +use crate::utils::{git, paths}; +use anyhow::{Context as _, Result, bail}; +use glob::glob; +use std::env; +use std::path::PathBuf; use std::process::Command; #[derive(clap::Args, Debug)] @@ -17,6 +20,12 @@ const CUE_DIR: &str = "website/cue"; /// 2. Ensuring that the .cue files can compile. impl Cli { pub fn exec(self) -> Result<()> { + // Resolve all `website/cue/**` globs against the repo root rather + // than the caller's CWD. Without this, running the binary from + // anywhere outside the repo root silently scans nothing and reports `0 error(s)` + let repo_root = paths::find_repo_root()?; + env::set_current_dir(&repo_root)?; + if Command::new("cue").arg("version").check_output().is_err() { bail!("Error: cue is not installed"); } @@ -35,9 +44,13 @@ impl Cli { println!("Validating cue files correctness..."); - if let Err(err) = app::exec(CUE_SCRIPT, ["vet"], true) { - bail!("CUE files validation failed:\n{err}"); - } + let all_cue_files = Self::get_all_cue_files()?; + + Command::new("cue") + .args(["vet", "--concrete", "--all-errors"]) + .args(all_cue_files) + .check_output() + .context("CUE files validation failed")?; println!("Success! The contents of the sources in the './{CUE_DIR}' directory are valid"); Ok(()) @@ -55,4 +68,13 @@ impl Cli { Ok(file_names) } + + fn get_all_cue_files() -> Result> { + let pattern = &format!("{CUE_DIR}/**/*.cue"); + + // Paths are yielded in alphabetical order via glob + let files: Vec = glob(pattern)?.collect::, _>>()?; + + Ok(files) + } }