Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod diff;
pub mod generate;
pub mod new;
pub mod reset;
pub mod targets;

use std::path::Path;

Expand Down
21 changes: 21 additions & 0 deletions src/commands/targets.rs
Original file line number Diff line number Diff line change
@@ -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-<lang>` 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(())
}
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(),
}
}
10 changes: 5 additions & 5 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion tests/cli/global.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down Expand Up @@ -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();
Expand Down
Loading