-
Notifications
You must be signed in to change notification settings - Fork 110
feat(ctl): allow library embedders to override CLI branding #3382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daviddahl
wants to merge
14
commits into
open-telemetry:main
Choose a base branch
from
daviddahl:feat/ctl-configurable-branding
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
57050c8
feat(ctl): allow library embedders to override CLI branding
daviddahl 9b62871
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl 1329c75
test(ctl): cover branding-routed envelope, completion, and diagnostic…
daviddahl e3dabe7
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl 6f4bf9a
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl 7553ce7
feat(ctl): add branded parse path + route catalog through active bran…
daviddahl 8c9d719
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl 2f08856
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl a44d14f
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl a3eb71e
fix(ctl): relax catalog JSON Schema binary const and brand schemas ou…
daviddahl dfe4281
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl dbde6de
Update rust/otap-dataflow/crates/ctl/src/args.rs
daviddahl b204d42
Merge branch 'main' into feat/ctl-configurable-branding
daviddahl 25a21f4
fix(ctl): repair try_parse_from_branded body after suggestion merge
daviddahl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
rust/otap-dataflow/.chloggen/ctl-configurable-branding.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. engine, otap). | ||
| # Must be one of the components listed in rust/otap-dataflow/.chloggen/config.yaml. | ||
| component: engine | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: >- | ||
| `otap-df-ctl` now lets library embedders override the CLI identity used in | ||
| output. A new `Branding` type (binary name + output-envelope `schemaVersion`) | ||
| and a `run_with_terminal_and_diagnostics_branded` entrypoint allow a | ||
| downstream binary that embeds the library to emit help, shell completions, and | ||
| machine-readable JSON envelopes under its own identity instead of `dfctl`. The | ||
| standalone `dfctl` binary and the existing public entrypoints are unchanged; | ||
| they use the default `dfctl` / `dfctl/v1` branding. | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [3370] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: >- | ||
| Initial scope covers the binary name and envelope `schemaVersion`. Schema | ||
| catalog identifiers, schema `$id` URLs, `DFCTL_*` environment-variable | ||
| prefixes, and the interactive TUI command hints remain `dfctl`-branded and may | ||
| be addressed in follow-ups. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Configurable CLI identity for library embedders. | ||
| //! | ||
| //! The standalone `dfctl` binary always uses the default identity. A downstream | ||
| //! binary that embeds this crate's library entrypoints can override the identity | ||
| //! so that help text, shell completions, and machine-readable output envelopes | ||
| //! reflect the embedding binary instead of `dfctl`. | ||
| //! | ||
| //! Branding is process-global and set-once, mirroring the crypto-provider | ||
| //! bootstrap in [`crate::crypto`]: a process runs as exactly one binary identity. | ||
| //! The branded entrypoints install the branding before executing a command; all | ||
| //! other entrypoints leave it unset and observe [`Branding::default`]. | ||
|
|
||
| use std::sync::OnceLock; | ||
|
|
||
| /// The single `dfctl` default binary-name literal shared by the standalone | ||
| /// `BIN_NAME` constant and [`Branding::default`]. | ||
| pub(crate) const DEFAULT_BIN_NAME: &str = "dfctl"; | ||
|
|
||
| /// Identity strings used in the CLI's user-visible and machine-readable output. | ||
| /// | ||
| /// Defaults reproduce the standalone `dfctl` identity. The fields are | ||
| /// `&'static str` because a binary's identity is fixed for the life of the | ||
| /// process. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | ||
| pub struct Branding { | ||
| /// Installed command name used in help, completions, shell completions, | ||
| /// generated command metadata, and diagnostics (e.g. `dfctl`). Use | ||
| /// [`crate::Cli::command_branded`] to produce a clap `Command` with your | ||
| /// own name before parsing, and [`crate::run_with_terminal_and_diagnostics_branded`] | ||
| /// to install the branding for runtime output. | ||
| pub bin_name: &'static str, | ||
| /// Schema-version identifier stamped into machine-readable output envelopes | ||
| /// (e.g. `dfctl/v1`). | ||
| pub schema_version: &'static str, | ||
| } | ||
|
|
||
| impl Default for Branding { | ||
| fn default() -> Self { | ||
| Self { | ||
| bin_name: DEFAULT_BIN_NAME, | ||
| schema_version: "dfctl/v1", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Process-global active branding. Unset means [`Branding::default`]. | ||
| static ACTIVE: OnceLock<Branding> = OnceLock::new(); | ||
|
|
||
| /// Install the process-wide branding. | ||
| /// | ||
| /// Idempotent and set-once (like the crypto provider): the first call wins and | ||
| /// subsequent calls are ignored. Standalone `dfctl` never calls this and so | ||
| /// observes [`Branding::default`]. | ||
| pub(crate) fn set_branding(branding: Branding) { | ||
| // First-writer-wins; a binary has a single identity for its lifetime. | ||
| let _ = ACTIVE.set(branding); | ||
| } | ||
|
|
||
| /// Return the active branding, or the default if none was installed. | ||
| pub(crate) fn active() -> Branding { | ||
| ACTIVE.get().copied().unwrap_or_default() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn default_is_dfctl() { | ||
| let b = Branding::default(); | ||
| assert_eq!(b.bin_name, "dfctl"); | ||
| assert_eq!(b.schema_version, "dfctl/v1"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the catalog can use a custom
binaryname, the schema still says binary must always bedfctl. Should we update the schema too, or keep the catalog binary field fixed asdfctl?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Relaxed the schema: "binary" is now { "type": "string", "description": "Active binary name at catalog generation time." }