Skip to content

Commit

Permalink
fix(cli): yaml format should be used by default, when -y is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Jan 16, 2024
1 parent 1a20c75 commit 86f8537
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions crates/jrsonnet-cli/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jrsonnet_evaluator::manifest::{
};
use jrsonnet_stdlib::{TomlFormat, YamlFormat};

#[derive(Clone, ValueEnum)]
#[derive(Clone, Copy, ValueEnum)]
pub enum ManifestFormatName {
/// Expect string as output, and write them directly
String,
Expand All @@ -18,9 +18,11 @@ pub enum ManifestFormatName {
#[derive(Parser)]
#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]
pub struct ManifestOpts {
/// Output format, wraps resulting value to corresponding std.manifest call.
#[clap(long, short = 'f', default_value = "json")]
format: ManifestFormatName,
/// Output format, wraps resulting value to corresponding std.manifest call
///
/// [default: json, yaml when -y is used]
#[clap(long, short = 'f')]
format: Option<ManifestFormatName>,
/// Expect plain string as output.
/// Mutually exclusive with `--format`
#[clap(long, short = 'S', conflicts_with = "format")]
Expand All @@ -29,7 +31,9 @@ pub struct ManifestOpts {
#[clap(long, short = 'y', conflicts_with = "string")]
yaml_stream: bool,
/// Number of spaces to pad output manifest with.
/// `0` for hard tabs, `-1` for single line output [default: 3 for json, 2 for yaml/toml]
/// `0` for hard tabs, `-1` for single line output
///
/// [default: 3 for json, 2 for yaml/toml]
#[clap(long)]
line_padding: Option<usize>,
/// Preserve order in object manifestification
Expand All @@ -44,7 +48,12 @@ impl ManifestOpts {
} else {
#[cfg(feature = "exp-preserve-order")]
let preserve_order = self.preserve_order;
match self.format {
let format = match self.format {
Some(v) => v,
None if self.yaml_stream => ManifestFormatName::Yaml,
None => ManifestFormatName::Json,
};
match format {
ManifestFormatName::String => Box::new(ToStringFormat),
ManifestFormatName::Json => Box::new(JsonFormat::cli(
self.line_padding.unwrap_or(3),
Expand Down

0 comments on commit 86f8537

Please sign in to comment.