From f4f924ee9a47c5aca1b8d1e68d47c742be0d6b2a Mon Sep 17 00:00:00 2001 From: Kinflou Date: Fri, 2 Oct 2026 10:56:53 +0800 Subject: [PATCH 1/2] feat: add `comline targets` to print compiled-in generator targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prints one `language#version` per line to stdout, mirroring `completions`'s existing stdout-payload precedent — everything else goes through `ui::*` to stderr. Reflects how this binary was compiled (which `gen-` Cargo features are on), not any project, so it ignores `--path` entirely and needs no `config.idp` to exist. A standalone subcommand rather than a `generate --list-targets` flag: `generate::run` calls `ensure_project` as its first line and the rest of the function assumes a real project, which this data has nothing to do with — bolting it on would mean special-casing past that invariant or wrongly requiring a project, plus inventing a rule for what `--target` + `--list-targets` together would even mean. A separate subcommand makes that question structurally impossible instead. Depends on the new `Registry::targets()` in ComlineProject/generation (separate PR) — needed by the upcoming comline-vscode `.idp` completion/ hover work for `code_generation.languages`, so the extension can show the real set of targets instead of guessing. --- src/cli.rs | 12 ++++++++++++ src/commands/mod.rs | 1 + src/commands/targets.rs | 21 +++++++++++++++++++++ src/main.rs | 7 ++++--- src/ui.rs | 10 +++++----- tests/cli/global.rs | 23 ++++++++++++++++++++++- 6 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 src/commands/targets.rs diff --git a/src/cli.rs b/src/cli.rs index 2340784..f2739a9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -184,4 +184,16 @@ Examples: #[arg(value_enum)] shell: Shell, }, + + /// Print every language#version this build can generate, to stdout + #[command(long_about = "\ +Print one `language#version` per line — the exact token syntax `config.idp`'s \ +`code_generation.languages` expects — for every generator this binary of \ +`comline` was compiled with. Ignores `--path`: this reflects the build, not \ +any particular project. + +Examples: + comline targets + comline targets | grep '^rust#'")] + Targets, } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index c58ac60..fdc9e10 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,6 +9,7 @@ pub mod diff; pub mod generate; pub mod new; pub mod reset; +pub mod targets; use std::path::Path; diff --git a/src/commands/targets.rs b/src/commands/targets.rs new file mode 100644 index 0000000..ab5a319 --- /dev/null +++ b/src/commands/targets.rs @@ -0,0 +1,21 @@ +//! `comline targets` — print every `language#version` this build of +//! `comline` can generate, to stdout. +//! +//! Reflects how this binary was compiled (which `gen-` Cargo features +//! were on), not any particular project — ignores `--path` entirely, same as +//! `completions`. + +use std::io::Write as _; + +use miette::{IntoDiagnostic, Result}; + +use crate::commands::generate::generator_registry; + +pub fn run() -> Result<()> { + let registry = generator_registry(); + let mut out = std::io::stdout().lock(); + for t in registry.targets() { + writeln!(out, "{}#{}", t.name, t.version).into_diagnostic()?; + } + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 14126fe..8be3abc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,9 +41,9 @@ fn main() -> ExitCode { /// `tracing` carries `comline-core` diagnostics only; the CLI's own output goes /// through [`ui`]. Everything is written to stderr so stdout stays a clean -/// channel for payloads (`comline completions`). Verbosity is shifted down a -/// notch from the usual so the default run is quiet: `-v` shows info, `-vv` -/// debug, `-vvv` trace. `RUST_LOG` still overrides. +/// channel for payloads (`comline completions`, `comline targets`). Verbosity +/// is shifted down a notch from the usual so the default run is quiet: `-v` +/// shows info, `-vv` debug, `-vvv` trace. `RUST_LOG` still overrides. fn init_tracing(cli: &Cli) { let level = if cli.quiet { "error" @@ -110,5 +110,6 @@ fn run(cli: Cli) -> Result<()> { Commands::Reset { force, dry_run } => commands::reset::run(&work_dir, force, dry_run), Commands::New { name, git } => commands::new::run(&work_dir, &name, git), Commands::Completions { shell } => commands::completions::run(shell), + Commands::Targets => commands::targets::run(), } } diff --git a/src/ui.rs b/src/ui.rs index 7e767a6..7952eac 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -2,11 +2,11 @@ //! //! `tracing` (`-v` / `-vv`) carries diagnostics coming out of `comline-core`. //! This module carries the CLI's own progress and result lines: written to -//! **stderr** so stdout stays clean for machine-readable payloads (e.g. `comline -//! completions`). By default it is colored and uses a few leading symbols; -//! `--plain` drops all of that for logs and CI. Coloring otherwise goes through -//! `anstream`, which also strips escapes when stderr is not a terminal or -//! `NO_COLOR` is set. +//! **stderr** so stdout stays clean for machine-readable payloads (e.g. +//! `comline completions`, `comline targets`). By default it is colored and +//! uses a few leading symbols; `--plain` drops all of that for logs and CI. +//! Coloring otherwise goes through `anstream`, which also strips escapes when +//! stderr is not a terminal or `NO_COLOR` is set. use std::borrow::Cow; use std::path::Path; diff --git a/tests/cli/global.rs b/tests/cli/global.rs index 4031198..61eaab9 100644 --- a/tests/cli/global.rs +++ b/tests/cli/global.rs @@ -1,5 +1,5 @@ //! Global flags and cross-cutting output behaviour (`--plain`, `--quiet`, -//! `--path`) plus `comline completions`. +//! `--path`) plus `comline completions`/`comline targets`. use predicates::prelude::*; @@ -38,6 +38,27 @@ fn completions_are_written_to_stdout() { .stderr(predicate::str::is_empty()); } +#[test] +fn targets_are_written_to_stdout_as_language_hash_version() { + comline_cmd() + .args(["targets"]) + .assert() + .success() + .stdout(predicate::str::contains("rust#")) + .stderr(predicate::str::is_empty()); +} + +#[test] +fn targets_ignores_path_and_works_outside_any_project() { + let temp = tempfile::tempdir().unwrap(); + + comline_cmd() + .current_dir(&temp) + .args(["targets"]) + .assert() + .success(); +} + #[test] fn quiet_build_is_silent_on_success() { let temp = tempfile::tempdir().unwrap(); From 6c5f3a53457e666c3f3a85124a0e0125ab5ed27f Mon Sep 17 00:00:00 2001 From: Kinflou Date: Fri, 2 Oct 2026 11:17:31 +0800 Subject: [PATCH 2/2] chore: bump comline-core/-codegen/-codegen-rust/-codegen-typescript pins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All four were pinned at older revs (comline-core@ed584ae) while generation/comline-rust/comline-typescript's own default branches had already independently been bumped to comline-core@91b3c1a — this crate was the one left behind in that cascade. Needed as a hard prerequisite for the previous commit: comline-codegen's old pin predates Registry::targets() entirely, so `comline targets` can't compile without at least that one bump — and bumping only that one (while leaving comline-core/-codegen-rust/-codegen-typescript on the old ed584ae-era revs) produces a "multiple different versions of crate comline_core/ comline_codegen in the dependency graph" compile error, since the crates can no longer be unified. All four together resolve to one consistent graph again. Also required two small upstream rev bumps (comline-codegen-rust / comline-codegen-typescript's own comline-codegen pin was one commit behind generation's tip, same root cause) — see ComlineProject/comline-rust#14 and ComlineProject/comline-typescript#12, both merged. --- Cargo.lock | 8 ++++---- Cargo.toml | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1730ba9..b299986 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -389,7 +389,7 @@ dependencies = [ [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=0f8dfcd5b27f9571fd7b6bac57b314de240db707#0f8dfcd5b27f9571fd7b6bac57b314de240db707" +source = "git+https://github.com/ComlineProject/generation?rev=eb7e4bcf9ad1b3dca856a8c3ab1f4180692ecd18#eb7e4bcf9ad1b3dca856a8c3ab1f4180692ecd18" dependencies = [ "comline-core", "eyre", @@ -398,7 +398,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=7d56cefbdfde787a3ffdfe0b66bfaeba7ba6d500#7d56cefbdfde787a3ffdfe0b66bfaeba7ba6d500" +source = "git+https://github.com/ComlineProject/comline-rust?rev=99f94be1fe39bc42c98c3eb7ca9051c0563c431c#99f94be1fe39bc42c98c3eb7ca9051c0563c431c" dependencies = [ "comline-codegen", "comline-core", @@ -408,7 +408,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=9af8674291ea7f2b344be9c838d5dc9237319044#9af8674291ea7f2b344be9c838d5dc9237319044" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=e713a19370fa6ac99f3fdbf33de1a42a29b6e664#e713a19370fa6ac99f3fdbf33de1a42a29b6e664" dependencies = [ "comline-codegen", "comline-core", @@ -418,7 +418,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=ed584aef249e8a9282393d39d24f2615c9b8088a#ed584aef249e8a9282393d39d24f2615c9b8088a" +source = "git+https://github.com/ComlineProject/core?rev=91b3c1a64fce50789a3dfb8299c2fd1f739f1a58#91b3c1a64fce50789a3dfb8299c2fd1f739f1a58" dependencies = [ "ariadne", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 11a45d0..187acda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,14 +29,15 @@ toml = "0.8" # needs real I/O (git fetch, filesystem), so it's off by default for # `comline-core`'s wasm32 consumers (the playground editor, the language # server); the CLI is the one consumer that actually runs `comline build`. -comline-core = { git = "https://github.com/ComlineProject/core", rev = "ed584aef249e8a9282393d39d24f2615c9b8088a", features = ["deps"] } -# Pinned to the same generation rev `comline-codegen-rust` / `-typescript` -# pin (below) — `codegen/`'s content is identical at this rev and the later -# `generation` tip (only `conformance/`, which this crate never touches, -# differs), so matching it here keeps one `comline-codegen` in the tree. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "0f8dfcd5b27f9571fd7b6bac57b314de240db707" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "7d56cefbdfde787a3ffdfe0b66bfaeba7ba6d500", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "9af8674291ea7f2b344be9c838d5dc9237319044", optional = true } +comline-core = { git = "https://github.com/ComlineProject/core", rev = "91b3c1a64fce50789a3dfb8299c2fd1f739f1a58", features = ["deps"] } +# All three pinned to revs that already agree on comline-core@91b3c1a (the +# `generation`/`comline-rust`/`comline-typescript` default branches were each +# bumped there independently of this crate — this crate was the one left +# behind). `comline-codegen`'s rev additionally carries Registry::targets(), +# needed by `comline targets` (src/commands/targets.rs). +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "eb7e4bcf9ad1b3dca856a8c3ab1f4180692ecd18" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "99f94be1fe39bc42c98c3eb7ca9051c0563c431c", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "e713a19370fa6ac99f3fdbf33de1a42a29b6e664", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole