Refactor generation commands to use --output for files and printing to stdout by default

pull/218/head
Chip Senkbeil 10 months ago
parent 84ea28402d
commit be7a15caa0
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Cli no longer uses `-c` as shorthand for specifying a config file
- `--file` option for generating completion has been renamed to `--output`
- CLI command to generate config files now defaults to printing to stdout with
`--output` providing the option to write to a file
## [0.20.0-alpha.10]

@ -14,15 +14,18 @@ pub fn run(cmd: GenerateSubcommand) -> CliResult {
async fn async_run(cmd: GenerateSubcommand) -> CliResult {
match cmd {
GenerateSubcommand::Config { file } => tokio::fs::write(file, Config::default_raw_str())
.await
.context("Failed to write default config to {file:?}")?,
GenerateSubcommand::Config { output } => match output {
Some(path) => tokio::fs::write(path, Config::default_raw_str())
.await
.context("Failed to write default config to {path:?}")?,
None => println!("{}", Config::default_raw_str()),
},
GenerateSubcommand::Completion { file, shell } => {
GenerateSubcommand::Completion { output, shell } => {
let name = "distant";
let mut cmd = Options::command();
if let Some(path) = file {
if let Some(path) = output {
clap_generate(
shell,
&mut cmd,

@ -933,15 +933,16 @@ impl ClientFileSystemSubcommand {
pub enum GenerateSubcommand {
/// Generate configuration file with base settings
Config {
/// Path to where the configuration file should be created
file: PathBuf,
/// Write output to a file instead of stdout
#[clap(short, long, value_name = "FILE")]
output: Option<PathBuf>,
},
// Generate completion info for CLI
Completion {
/// If specified, will output to the file at the given path instead of stdout
#[clap(long)]
file: Option<PathBuf>,
/// Write output to a file instead of stdout
#[clap(long, value_name = "FILE")]
output: Option<PathBuf>,
/// Specific shell to target for the generated output
#[clap(value_enum, value_parser)]
@ -3340,7 +3341,7 @@ mod tests {
log_level: None,
},
command: DistantSubcommand::Generate(GenerateSubcommand::Completion {
file: None,
output: None,
shell: ClapCompleteShell::Bash,
}),
};
@ -3364,7 +3365,7 @@ mod tests {
log_level: Some(LogLevel::Trace),
},
command: DistantSubcommand::Generate(GenerateSubcommand::Completion {
file: None,
output: None,
shell: ClapCompleteShell::Bash,
}),
}
@ -3380,7 +3381,7 @@ mod tests {
log_level: Some(LogLevel::Info),
},
command: DistantSubcommand::Generate(GenerateSubcommand::Completion {
file: None,
output: None,
shell: ClapCompleteShell::Bash,
}),
};
@ -3404,7 +3405,7 @@ mod tests {
log_level: Some(LogLevel::Info),
},
command: DistantSubcommand::Generate(GenerateSubcommand::Completion {
file: None,
output: None,
shell: ClapCompleteShell::Bash,
}),
}

Loading…
Cancel
Save