Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 71 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ log = { version = "0.4.17", features = [
] }
openssl = { version = '0.10', features = ["vendored"] }
prettytable-rs = "0.10.0"
pretty_yaml = "0.6.0"
protobuf = "3.3.0"
rayon = "1.7.0"
regex = "1.9.3"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/edge_app/instance_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_with::serde_as;

use crate::commands::edge_app::manifest::beautify_error_message;
use crate::commands::serde_utils::{
deserialize_option_string_field, string_field_is_none_or_empty,
deserialize_option_string_field, format_yaml, string_field_is_none_or_empty,
};
use crate::commands::CommandError;

Expand Down Expand Up @@ -123,7 +123,7 @@ impl InstanceManifest {
}

pub fn save_to_file(manifest: &InstanceManifest, path: &Path) -> Result<(), CommandError> {
let yaml = serde_yaml::to_string(&manifest)?;
let yaml = format_yaml(&serde_yaml::to_string(&manifest)?);
let manifest_file = File::create(path)?;
write!(&manifest_file, "---\n{yaml}")?;
Ok(())
Expand Down
20 changes: 10 additions & 10 deletions src/commands/edge_app/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_json::json;
use super::manifest_auth::AuthType;
use crate::api::edge_app::setting::{deserialize_settings, serialize_settings, Setting};
use crate::commands::serde_utils::{
deserialize_option_string_field, string_field_is_none_or_empty,
deserialize_option_string_field, format_yaml, string_field_is_none_or_empty,
};
use crate::commands::CommandError;

Expand Down Expand Up @@ -270,7 +270,7 @@ impl EdgeAppManifest {
}

pub fn save_to_file(manifest: &EdgeAppManifest, path: &Path) -> Result<(), CommandError> {
let yaml = serde_yaml::to_string(&manifest)?;
let yaml = format_yaml(&serde_yaml::to_string(&manifest)?);
let manifest_file = File::create(path)?;
write!(&manifest_file, "---\n{yaml}")?;
Ok(())
Expand Down Expand Up @@ -405,8 +405,8 @@ icon: test_icon
author: test_author
homepage_url: test_url
categories:
- Utilities
- Dashboards
- Utilities
- Dashboards
entrypoint:
type: file
ready_signal: true
Expand Down Expand Up @@ -442,8 +442,8 @@ user_version: test_version
icon: test_icon
homepage_url: test_url
categories:
- Utilities
- Dashboards
- Utilities
- Dashboards
entrypoint:
type: file
settings:
Expand Down Expand Up @@ -477,8 +477,8 @@ user_version: test_version
icon: test_icon
homepage_url: test_url
categories:
- Utilities
- Dashboards
- Utilities
- Dashboards
entrypoint:
type: file
ready_signal: true
Expand Down Expand Up @@ -939,8 +939,8 @@ icon: test_icon
author: test_author
homepage_url: test_url
categories:
- Utilities
- Dashboards
- Utilities
- Dashboards
entrypoint:
type: file
settings:
Expand Down
4 changes: 2 additions & 2 deletions src/commands/edge_app/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::api::edge_app::setting::SettingType;
use crate::commands::edge_app::manifest::EdgeAppManifest;
use crate::commands::edge_app::EdgeAppCommand;
use crate::commands::ignorer::Ignorer;
use crate::commands::serde_utils::format_yaml;
use crate::commands::CommandError;

pub const MOCK_DATA_FILENAME: &str = "mock-data.yml";
Expand Down Expand Up @@ -331,7 +332,7 @@ impl EdgeAppCommand {
);
mock_data.insert("settings".to_string(), serde_yaml::to_value(settings)?);

let mock_data_yaml = serde_yaml::to_string(&mock_data)?;
let mock_data_yaml = format_yaml(&serde_yaml::to_string(&mock_data)?);

fs::write(edge_app_dir.join(MOCK_DATA_FILENAME), mock_data_yaml)?;
Comment thread
nicomiguelino marked this conversation as resolved.

Expand Down Expand Up @@ -484,7 +485,6 @@ settings: {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test_manifest.yml");

// The EdgeAppManifest structure from your example
let manifest = create_edge_app_manifest_for_test(vec![
Setting {
name: "asetting".to_string(),
Expand Down
12 changes: 12 additions & 0 deletions src/commands/serde_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
use pretty_yaml::config::{FormatOptions, LanguageOptions, Quotes};
use serde::{Deserialize, Deserializer};

pub fn format_yaml(raw: &str) -> String {
let options = FormatOptions {
language: LanguageOptions {
quotes: Quotes::PreferSingle,
..Default::default()
},
..Default::default()
};
pretty_yaml::format_text(raw, &options).unwrap_or_else(|_| raw.to_owned())
Comment thread
nicomiguelino marked this conversation as resolved.
}
Comment thread
nicomiguelino marked this conversation as resolved.

pub fn deserialize_option_string_field<'de, D>(
field_name: &'static str,
error_on_empty: bool,
Expand Down
Loading