Skip to content
Open
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
29 changes: 19 additions & 10 deletions src/commands/config/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ impl RunnerResponse {
#[derive(Deserialize, serde::Serialize)]
pub(super) struct ChangeSet {
pub(super) changes: Vec<Change>,
#[serde(default)]
info: Vec<String>,
}

#[derive(Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -987,6 +989,11 @@ pub(super) fn print_response_with_options_and_next(
return;
}

let info = response
.change_set
.as_ref()
.map(|change_set| change_set.info.as_slice())
.unwrap_or(&[]);
if changes.is_empty() {
println!(
"{}",
Expand All @@ -1010,16 +1017,18 @@ pub(super) fn print_response_with_options_and_next(
format!("{destructive} destructive change(s) will remove Railway resources or variables.").red()
);
}

if show_next {
println!();
println!("{}", "Next".bold());
println!(
" {} Run {} to apply these changes.",
"•".cyan(),
"railway config apply".cyan()
);
}
}
for line in info {
println!(" {}", line.dimmed());
}
if !changes.is_empty() && show_next {
println!();
println!("{}", "Next".bold());
println!(
" {} Run {} to apply these changes.",
"•".cyan(),
"railway config apply".cyan()
);
}
}

Expand Down
35 changes: 18 additions & 17 deletions src/iac/change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub struct ChangeSet {
pub declared: Vec<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub telemetry: Option<ChangeSetTelemetry>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub info: Vec<String>,
}

/// Authoring language is the only adoption dimension the server cannot observe
Expand Down Expand Up @@ -80,9 +82,13 @@ pub fn diff_graphs_following(
) -> ChangeSet {
let mut changes = Vec::new();
let mut diagnostics = Vec::new();
let desired_by: Map<String, Value> = options
let desired_resources: Vec<Value> = options
.desired
.resources
.iter()
.map(super::environments::without_environments)
.collect();
let desired_by: Map<String, Value> = desired_resources
.iter()
.map(|resource| (resource_addr(resource), resource.clone()))
.collect();
Expand All @@ -93,12 +99,7 @@ pub fn diff_graphs_following(
.map(|resource| (paired_address(resource, &desired_by), resource.clone()))
.collect();
let p = effective_partial(options.partial).to_string();
let declared: Vec<String> = options
.desired
.resources
.iter()
.map(resource_addr)
.collect();
let declared: Vec<String> = desired_resources.iter().map(resource_addr).collect();

if p == super::partial::PROJECT_PARTIAL && has_named_partials(options.owners) {
diagnostics.push(Diagnostic {
Expand All @@ -112,7 +113,7 @@ pub fn diff_graphs_following(
let mut compiled = compile_variable_policy(options.current, options.desired);
diagnostics.append(&mut compiled.diagnostics);

for resource in &options.desired.resources {
for resource in &desired_resources {
let address = resource_addr(resource);
let previous = current_by.get(&address);
if let Some(owner) = owner_of(options.owners, &address) {
Expand Down Expand Up @@ -374,17 +375,16 @@ fn change_set_result(
partial: partial.map(str::to_string),
declared,
telemetry: None,
info: Vec::new(),
}
}

pub fn render_change_set(change_set: &ChangeSet) -> String {
let mut lines = Vec::new();
if change_set.changes.is_empty() {
return "No changes.".to_string();
}
change_set
.changes
.iter()
.map(|change| {
lines.push("No changes.".to_string());
} else {
lines.extend(change_set.changes.iter().map(|change| {
let marker = match field_str(change, "kind") {
Some("resource.create") | Some("domain.create") => "+",
Some("resource.delete") => "-",
Expand All @@ -394,9 +394,10 @@ pub fn render_change_set(change_set: &ChangeSet) -> String {
"{marker} {}",
field_str(change, "summary").unwrap_or("change")
)
})
.collect::<Vec<_>>()
.join("\n")
}));
}
lines.extend(change_set.info.iter().cloned());
lines.join("\n")
}

struct ParsedPattern {
Expand Down
Loading
Loading