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

pull/218/head
Chip Senkbeil 11 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 ### Changed
- Cli no longer uses `-c` as shorthand for specifying a config file - 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] ## [0.20.0-alpha.10]

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

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

Loading…
Cancel
Save