Fix: Show A Message such that the user will know there is something wrong (#1092)

* Fix: Show A Message such that the user will know there is something wrong

Fixes #31

* Update main.rs

* Apply suggestions from code review

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>

Co-authored-by: Aiden McClelland <3732071+dr-bonez@users.noreply.github.com>
This commit is contained in:
J M
2022-01-18 15:54:05 -07:00
committed by Aiden McClelland
parent 1dd1d21694
commit 577b75a76c

View File

@@ -1,4 +1,5 @@
use std::{
env,
fs::File,
io::{stdin, stdout},
path::Path,
@@ -19,6 +20,10 @@ use config::{
apply_dependency_configuration, validate_configuration, validate_dependency_configuration,
};
use embassy::config::action::ConfigRes;
use serde_json::json;
const PROPERTIES_FALLBACK_MESSAGE: &str =
"Could not find properties. The service might still be starting";
pub enum CompatRes {
SetResult,
ConfigRes,
@@ -155,6 +160,10 @@ fn inner_main() -> Result<(), anyhow::Error> {
Arg::with_name("mountpoint")
.help("The data directory of the service to mount to.")
.required(true),
).arg(
Arg::with_name("fallbackMessage")
.help("The message to indicate that the startup is still working, or stats.yaml couldn't be found")
.required(false),
),
);
let matches = app.get_matches();
@@ -295,7 +304,22 @@ fn inner_main() -> Result<(), anyhow::Error> {
let stats: serde_json::Value = if stats_path.exists() {
serde_yaml::from_reader(File::open(stats_path).unwrap()).unwrap()
} else {
serde_json::Value::from("{}")
let fallbackMessage: &str = sub_m
.value_of("fallbackMessage")
.unwrap_or_else(|| PROPERTIES_FALLBACK_MESSAGE);
json!({
"version": 2i64,
"data": {
"Not Ready": {
"type": "string",
"value": fallbackMessage,
"qr": false,
"copyable": false,
"masked": false,
"description":"Fallback Message When Properties could not be found"
}
}
})
};
serde_json::to_writer(stdout(), &stats)?;
Ok(())