Skip to content

Commit 375723e

Browse files
committed
Centralize dfctl binary name
1 parent 796dbfd commit 375723e

11 files changed

Lines changed: 143 additions & 80 deletions

File tree

rust/otap-dataflow/crates/enginectl/src/args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use crate::BIN_NAME;
45
use clap::parser::ValueSource;
56
use clap::{
67
ArgAction, ArgMatches, Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum,
@@ -12,7 +13,7 @@ use std::time::Duration;
1213

1314
#[derive(Parser, Debug, Clone)]
1415
#[command(
15-
name = "dfctl",
16+
name = BIN_NAME,
1617
version,
1718
about = "Control CLI for the OTAP Dataflow Engine admin API"
1819
)]

rust/otap-dataflow/crates/enginectl/src/commands/catalog.rs

Lines changed: 85 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
//! long-running commands are classified correctly, and high-impact mutations
3737
//! expose safety, dry-run, wait/watch, stdin, and schema metadata.
3838
39-
use crate::Cli;
4039
use crate::args::CommandsArgs;
4140
use crate::commands::output::emit_read;
4241
use crate::commands::schemas::{
@@ -46,6 +45,7 @@ use crate::commands::schemas::{
4645
};
4746
use crate::error::CliError;
4847
use crate::style::HumanStyle;
48+
use crate::{BIN_NAME, Cli};
4949
use clap::builder::ValueRange;
5050
use clap::{Arg, ArgAction, Command as ClapCommand, CommandFactory};
5151
use serde::Serialize;
@@ -54,7 +54,6 @@ use std::io::Write;
5454
use std::time::SystemTime;
5555

5656
const SCHEMA_VERSION: &str = "dfctl-command-catalog/v1";
57-
const BIN_NAME: &str = "dfctl";
5857

5958
/// Runs `dfctl commands` and emits either a compact human table or the full
6059
/// machine-readable catalog, depending on the selected output mode.
@@ -345,7 +344,7 @@ fn supports_dry_run(arguments: &[ArgumentEntry]) -> bool {
345344

346345
/// Builds a stable, dot-separated command identifier.
347346
fn command_id(path: &[String]) -> String {
348-
format!("dfctl.{}", path.join(".").replace('-', "_"))
347+
format!("{BIN_NAME}.{}", path.join(".").replace('-', "_"))
349348
}
350349

351350
/// Builds the shortest command-line prefix for a command path.
@@ -435,91 +434,130 @@ fn curated_examples(path: &[String]) -> Vec<String> {
435434
.collect::<Vec<_>>()
436435
.as_slice()
437436
{
438-
["commands"] => vec!["dfctl commands --output json".to_string()],
437+
["commands"] => vec![command_example("commands --output json")],
439438
["schemas"] => vec![
440-
"dfctl schemas --output json".to_string(),
441-
"dfctl schemas dfctl.error.v1 --output json".to_string(),
439+
command_example("schemas --output json"),
440+
command_example("schemas dfctl.error.v1 --output json"),
442441
],
443-
["completions"] => vec!["dfctl completions bash".to_string()],
444-
["completions", "install"] => vec!["dfctl completions install zsh".to_string()],
445-
["config", "view"] => vec!["dfctl config view --output json".to_string()],
446-
["ui"] => vec!["dfctl ui --start-view pipelines".to_string()],
447-
["engine", "status"] => vec!["dfctl engine status --output json".to_string()],
448-
["engine", "livez"] => vec!["dfctl engine livez".to_string()],
449-
["engine", "readyz"] => vec!["dfctl engine readyz".to_string()],
450-
["groups", "status"] => vec!["dfctl groups status".to_string()],
451-
["groups", "describe"] => vec!["dfctl groups describe".to_string()],
452-
["groups", "events", "get"] => vec!["dfctl groups events get --tail 20".to_string()],
442+
["completions"] => vec![command_example("completions bash")],
443+
["completions", "install"] => vec![command_example("completions install zsh")],
444+
["config", "view"] => vec![command_example("config view --output json")],
445+
["ui"] => vec![command_example("ui --start-view pipelines")],
446+
["engine", "status"] => vec![command_example("engine status --output json")],
447+
["engine", "livez"] => vec![command_example("engine livez")],
448+
["engine", "readyz"] => vec![command_example("engine readyz")],
449+
["groups", "status"] => vec![command_example("groups status")],
450+
["groups", "describe"] => vec![command_example("groups describe")],
451+
["groups", "events", "get"] => vec![command_example("groups events get --tail 20")],
453452
["groups", "events", "watch"] => {
454-
vec!["dfctl groups events watch --kind error --tail 20".to_string()]
453+
vec![command_example(
454+
"groups events watch --kind error --tail 20",
455+
)]
455456
}
456-
["groups", "diagnose", "shutdown"] => vec!["dfctl groups diagnose shutdown".to_string()],
457-
["groups", "bundle"] => vec!["dfctl groups bundle --file bundle.json".to_string()],
458-
["groups", "shutdown"] => vec!["dfctl groups shutdown --watch".to_string()],
459-
["pipelines", "get"] => vec!["dfctl pipelines get tenant-a ingest".to_string()],
457+
["groups", "diagnose", "shutdown"] => vec![command_example("groups diagnose shutdown")],
458+
["groups", "bundle"] => vec![command_example("groups bundle --file bundle.json")],
459+
["groups", "shutdown"] => vec![command_example("groups shutdown --watch")],
460+
["pipelines", "get"] => vec![command_example("pipelines get tenant-a ingest")],
460461
["pipelines", "describe"] => {
461-
vec!["dfctl pipelines describe tenant-a ingest".to_string()]
462+
vec![command_example("pipelines describe tenant-a ingest")]
462463
}
463464
["pipelines", "status"] => {
464-
vec!["dfctl pipelines status tenant-a ingest --output json".to_string()]
465+
vec![command_example(
466+
"pipelines status tenant-a ingest --output json",
467+
)]
465468
}
466-
["pipelines", "livez"] => vec!["dfctl pipelines livez tenant-a ingest".to_string()],
467-
["pipelines", "readyz"] => vec!["dfctl pipelines readyz tenant-a ingest".to_string()],
469+
["pipelines", "livez"] => vec![command_example("pipelines livez tenant-a ingest")],
470+
["pipelines", "readyz"] => vec![command_example("pipelines readyz tenant-a ingest")],
468471
["pipelines", "events", "get"] => {
469-
vec!["dfctl pipelines events get tenant-a ingest --tail 20".to_string()]
472+
vec![command_example(
473+
"pipelines events get tenant-a ingest --tail 20",
474+
)]
470475
}
471476
["pipelines", "events", "watch"] => {
472-
vec!["dfctl pipelines events watch tenant-a ingest --kind error --tail 20".to_string()]
477+
vec![command_example(
478+
"pipelines events watch tenant-a ingest --kind error --tail 20",
479+
)]
473480
}
474481
["pipelines", "diagnose", "rollout"] => {
475-
vec!["dfctl pipelines diagnose rollout tenant-a ingest".to_string()]
482+
vec![command_example(
483+
"pipelines diagnose rollout tenant-a ingest",
484+
)]
476485
}
477486
["pipelines", "diagnose", "shutdown"] => {
478-
vec!["dfctl pipelines diagnose shutdown tenant-a ingest".to_string()]
487+
vec![command_example(
488+
"pipelines diagnose shutdown tenant-a ingest",
489+
)]
479490
}
480491
["pipelines", "bundle"] => {
481-
vec!["dfctl pipelines bundle tenant-a ingest --file bundle.json".to_string()]
492+
vec![command_example(
493+
"pipelines bundle tenant-a ingest --file bundle.json",
494+
)]
482495
}
483-
["pipelines", "reconfigure"] => vec![
484-
"dfctl pipelines reconfigure tenant-a ingest --file pipeline.yaml --wait".to_string(),
485-
],
496+
["pipelines", "reconfigure"] => vec![command_example(
497+
"pipelines reconfigure tenant-a ingest --file pipeline.yaml --wait",
498+
)],
486499
["pipelines", "shutdown"] => {
487-
vec!["dfctl pipelines shutdown tenant-a ingest --watch".to_string()]
500+
vec![command_example(
501+
"pipelines shutdown tenant-a ingest --watch",
502+
)]
488503
}
489504
["pipelines", "rollouts", "get"] => {
490-
vec!["dfctl pipelines rollouts get tenant-a ingest rollout-1".to_string()]
505+
vec![command_example(
506+
"pipelines rollouts get tenant-a ingest rollout-1",
507+
)]
491508
}
492509
["pipelines", "rollouts", "watch"] => {
493-
vec!["dfctl pipelines rollouts watch tenant-a ingest rollout-1".to_string()]
510+
vec![command_example(
511+
"pipelines rollouts watch tenant-a ingest rollout-1",
512+
)]
494513
}
495514
["pipelines", "rollout-status"] => {
496-
vec!["dfctl pipelines rollout-status tenant-a ingest rollout-1".to_string()]
515+
vec![command_example(
516+
"pipelines rollout-status tenant-a ingest rollout-1",
517+
)]
497518
}
498519
["pipelines", "shutdowns", "get"] => {
499-
vec!["dfctl pipelines shutdowns get tenant-a ingest shutdown-1".to_string()]
520+
vec![command_example(
521+
"pipelines shutdowns get tenant-a ingest shutdown-1",
522+
)]
500523
}
501524
["pipelines", "shutdowns", "watch"] => {
502-
vec!["dfctl pipelines shutdowns watch tenant-a ingest shutdown-1".to_string()]
525+
vec![command_example(
526+
"pipelines shutdowns watch tenant-a ingest shutdown-1",
527+
)]
503528
}
504529
["pipelines", "shutdown-status"] => {
505-
vec!["dfctl pipelines shutdown-status tenant-a ingest shutdown-1".to_string()]
530+
vec![command_example(
531+
"pipelines shutdown-status tenant-a ingest shutdown-1",
532+
)]
506533
}
507534
["telemetry", "logs", "get"] => {
508-
vec!["dfctl telemetry logs get --limit 50 --output json".to_string()]
535+
vec![command_example(
536+
"telemetry logs get --limit 50 --output json",
537+
)]
509538
}
510539
["telemetry", "logs", "watch"] => {
511-
vec!["dfctl telemetry logs watch --tail 50".to_string()]
540+
vec![command_example("telemetry logs watch --tail 50")]
512541
}
513542
["telemetry", "metrics", "get"] => {
514-
vec!["dfctl telemetry metrics get --shape compact --output json".to_string()]
543+
vec![command_example(
544+
"telemetry metrics get --shape compact --output json",
545+
)]
515546
}
516547
["telemetry", "metrics", "watch"] => {
517-
vec!["dfctl telemetry metrics watch --shape compact --output ndjson".to_string()]
548+
vec![command_example(
549+
"telemetry metrics watch --shape compact --output ndjson",
550+
)]
518551
}
519552
_ => Vec::new(),
520553
}
521554
}
522555

556+
/// Builds a curated command example from the shared binary name.
557+
fn command_example(args: &str) -> String {
558+
format!("{BIN_NAME} {args}")
559+
}
560+
523561
/// Returns the best display placeholder for an argument value.
524562
fn value_placeholder(argument: &ArgumentEntry) -> String {
525563
argument
@@ -709,7 +747,7 @@ fn render_human(style: &HumanStyle, catalog: &CommandCatalog) -> String {
709747
.collect::<Vec<_>>();
710748

711749
let lines = [
712-
style.header("dfctl command catalog"),
750+
style.header(format!("{BIN_NAME} command catalog")),
713751
format!("{}: {}", style.label("schema"), catalog.schema_version),
714752
format!("{}: {}", style.label("commands"), catalog.commands.len()),
715753
String::new(),
@@ -722,7 +760,7 @@ fn render_human(style: &HumanStyle, catalog: &CommandCatalog) -> String {
722760
rows,
723761
),
724762
String::new(),
725-
"Use `dfctl commands --output json` for the machine-readable catalog.".to_string(),
763+
format!("Use `{BIN_NAME} commands --output json` for the machine-readable catalog."),
726764
];
727765
lines.join("\n")
728766
}
@@ -1073,7 +1111,7 @@ mod tests {
10731111
pipeline_get.output_modes,
10741112
vec!["human", "json", "yaml", "agent-json"]
10751113
);
1076-
assert_eq!(pipeline_get.id, "dfctl.pipelines.get");
1114+
assert_eq!(pipeline_get.id, format!("{BIN_NAME}.pipelines.get"));
10771115
assert_eq!(pipeline_get.default_output.as_deref(), Some("human"));
10781116
assert_eq!(
10791117
pipeline_get.agent_default_output.as_deref(),

rust/otap-dataflow/crates/enginectl/src/commands/completions.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33

44
//! Shell completion generation and user-local installation helpers.
55
6-
use crate::Cli;
76
use crate::args::{CompletionArgs, CompletionCommand, CompletionInstallArgs};
87
use crate::error::CliError;
8+
use crate::{BIN_NAME, Cli};
99
use clap::CommandFactory;
1010
use clap_complete::Shell;
1111
use std::ffi::OsString;
1212
use std::fs;
1313
use std::io::Write;
1414
use std::path::{Path, PathBuf};
1515

16-
const BIN_NAME: &str = "dfctl";
17-
1816
pub(crate) fn run(stdout: &mut dyn Write, args: CompletionArgs) -> Result<(), CliError> {
1917
match args.command {
2018
Some(CompletionCommand::Install(args)) => install(stdout, args),
@@ -24,9 +22,9 @@ pub(crate) fn run(stdout: &mut dyn Write, args: CompletionArgs) -> Result<(), Cl
2422

2523
fn generate(stdout: &mut dyn Write, args: CompletionArgs) -> Result<(), CliError> {
2624
let shell = args.shell.ok_or_else(|| {
27-
CliError::invalid_usage(
28-
"missing shell; use `dfctl completions <shell>` or `dfctl completions install <shell>`",
29-
)
25+
CliError::invalid_usage(format!(
26+
"missing shell; use `{BIN_NAME} completions <shell>` or `{BIN_NAME} completions install <shell>`"
27+
))
3028
})?;
3129

3230
let mut command = Cli::command();
@@ -104,7 +102,7 @@ fn activation_note(shell: Shell, dir: &Path, path: &Path) -> Option<String> {
104102
Shell::Zsh => Some(format!(
105103
"If zsh does not load it, add this to .zshrc: fpath=({dir} $fpath); autoload -Uz compinit; compinit"
106104
)),
107-
Shell::Elvish => Some("Load it from rc.elv with: use dfctl".to_string()),
105+
Shell::Elvish => Some(format!("Load it from rc.elv with: use {BIN_NAME}")),
108106
Shell::PowerShell => Some(format!(
109107
"Load it from your PowerShell profile with: . {path}"
110108
)),
@@ -180,7 +178,7 @@ mod tests {
180178
)
181179
.expect("install completions");
182180

183-
let path = dir.path().join("dfctl.fish");
181+
let path = dir.path().join(format!("{BIN_NAME}.fish"));
184182
assert!(path.exists());
185183
let output = String::from_utf8(stdout).expect("stdout");
186184
assert!(output.contains(path.to_str().expect("path")));

rust/otap-dataflow/crates/enginectl/src/commands/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
//! Commands that inspect client-side `dfctl` configuration.
55
6+
use crate::BIN_NAME;
67
use crate::args::{ConfigArgs, ConfigCommand};
78
use crate::commands::output::emit_read;
89
use crate::config::{ResolvedConnection, ResolvedConnectionView};
@@ -28,7 +29,7 @@ pub(crate) fn run(
2829

2930
fn render_config_view(style: &HumanStyle, view: &ResolvedConnectionView) -> String {
3031
let mut lines = Vec::new();
31-
lines.push(style.header("dfctl configuration"));
32+
lines.push(style.header(format!("{BIN_NAME} configuration")));
3233
lines.push(format!("{}: {}", style.label("target"), view.url));
3334
lines.push(format!(
3435
"{}: {}",

0 commit comments

Comments
 (0)