Skip to content

Commit babdebf

Browse files
authoredSep 9, 2024··
fix: implement profile export toml and make it default option (#4172)
* fix: implement toml profile export and make it default option * fix: enable display feature for toml package
1 parent 32e4068 commit babdebf

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/fluvio-cli/src/profile/export.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::error::CliError;
1313
pub struct ExportOpt {
1414
profile_name: Option<String>,
1515
#[arg(
16-
default_value_t = OutputType::json,
16+
default_value_t = OutputType::toml,
1717
short = 'O',
1818
long = "output",
1919
value_name = "type",
@@ -27,8 +27,8 @@ impl ExportOpt {
2727
pub fn process<O: Terminal>(self, out: Arc<O>) -> Result<()> {
2828
let output_format = match self.output_format {
2929
OutputType::table => {
30-
eprintln!("Table format is not supported, using JSON instead");
31-
OutputType::json
30+
eprintln!("Table format is not supported, using TOML instead");
31+
OutputType::toml
3232
}
3333
_ => self.output_format,
3434
};

‎crates/fluvio-extension-common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde_yaml = { workspace = true }
2626
semver = { workspace = true, features = ["serde"] }
2727
thiserror = { workspace = true }
2828
tracing = { workspace = true }
29+
toml = { workspace = true, features = ["display"] }
2930

3031
fluvio = { workspace = true, optional = true }
3132
fluvio-package-index = { workspace = true }

‎crates/fluvio-extension-common/src/output/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ mod error {
4040

4141
use serde_json::Error as SerdeJsonError;
4242
use serde_yaml::Error as SerdeYamlError;
43+
use toml::ser::Error as SerdeTomlError;
4344

4445
#[derive(thiserror::Error, Debug)]
4546
pub enum OutputError {
@@ -53,6 +54,11 @@ mod error {
5354
#[from]
5455
source: SerdeYamlError,
5556
},
57+
#[error("Fluvio client error")]
58+
SerdeTomlError {
59+
#[from]
60+
source: SerdeTomlError,
61+
},
5662
}
5763
}
5864

@@ -94,6 +100,7 @@ mod output {
94100
table,
95101
yaml,
96102
json,
103+
toml,
97104
}
98105

99106
/// OutputType defaults to table formatting

‎crates/fluvio-extension-common/src/output/serde.rs

+15
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use super::OutputError;
1313
pub enum SerializeType {
1414
yaml,
1515
json,
16+
toml,
1617
}
1718

1819
impl From<OutputType> for SerializeType {
1920
fn from(output: OutputType) -> Self {
2021
match output {
2122
OutputType::yaml => SerializeType::yaml,
2223
OutputType::json => SerializeType::json,
24+
OutputType::toml => SerializeType::toml,
2325
_ => panic!("should never happen"),
2426
}
2527
}
@@ -42,6 +44,7 @@ where
4244
match output_type {
4345
SerializeType::yaml => self.to_yaml(value),
4446
SerializeType::json => self.to_json(value),
47+
SerializeType::toml => self.to_toml(value),
4548
}
4649
}
4750

@@ -68,4 +71,16 @@ where
6871

6972
Ok(())
7073
}
74+
75+
/// convert to toml format and print to terminal
76+
fn to_toml<S>(&self, value: &S) -> Result<(), OutputError>
77+
where
78+
S: Serialize,
79+
{
80+
let serialized = toml::to_string(value)?;
81+
82+
self.0.println(&serialized);
83+
84+
Ok(())
85+
}
7186
}

0 commit comments

Comments
 (0)
Please sign in to comment.