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 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();