Skip to content

Commit

Permalink
implement config variables prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
blake-mealey committed Apr 28, 2024
1 parent 6088180 commit dac38d2
Show file tree
Hide file tree
Showing 16 changed files with 776 additions and 397 deletions.
19 changes: 19 additions & 0 deletions mantle/Cargo.lock

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

26 changes: 13 additions & 13 deletions mantle/mantle/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn log_target_results(

pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchases: bool) -> i32 {
logger::start_action("Loading project:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -137,7 +137,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchas
payment_source,
state_config,
owner_config,
} = match load_project(project_path.clone(), config, environment).await {
} = match load_project(&config_file, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No deployment necessary");
Expand All @@ -149,7 +149,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchas
}
};
let mut next_graph =
match get_desired_graph(project_path.as_path(), &target_config, &owner_config) {
match get_desired_graph(&config_file.project_path, &target_config, &owner_config) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -159,14 +159,14 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchas
logger::end_action("Succeeded");

logger::start_action("Deploying resources:");
let mut resource_manager = match RobloxResourceManager::new(&project_path, payment_source).await
{
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
let mut resource_manager =
match RobloxResourceManager::new(&config_file.project_path, payment_source).await {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

let results = next_graph
.evaluate(&current_graph, &mut resource_manager, allow_purchases)
Expand Down Expand Up @@ -201,7 +201,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchas
if environment_config.tag_commit && results.is_ok() {
logger::start_action("Tagging commit:");
match tag_commit(
project_path.clone(),
config_file.project_path.clone(),
&target_config,
&next_graph,
&current_graph,
Expand All @@ -219,7 +219,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, allow_purchas
environment_config.label.clone(),
next_graph.get_resource_list(),
);
match save_state(&project_path, &state_config, &state).await {
match save_state(&config_file.project_path, &state_config, &state).await {
Ok(_) => {}
Err(e) => {
logger::end_action(Paint::red(e));
Expand Down
22 changes: 11 additions & 11 deletions mantle/mantle/src/commands/destroy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rbx_mantle::{

pub async fn run(project: Option<&str>, environment: Option<&str>) -> i32 {
logger::start_action("Loading project:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -26,7 +26,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>) -> i32 {
payment_source,
state_config,
..
} = match load_project(project_path.clone(), config, environment).await {
} = match load_project(&config_file, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No deployment necessary");
Expand All @@ -40,14 +40,14 @@ pub async fn run(project: Option<&str>, environment: Option<&str>) -> i32 {
logger::end_action("Succeeded");

logger::start_action("Destroying resources:");
let mut resource_manager = match RobloxResourceManager::new(&project_path, payment_source).await
{
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
let mut resource_manager =
match RobloxResourceManager::new(&config_file.project_path, payment_source).await {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

let mut next_graph = ResourceGraph::new(&Vec::new());
let results = next_graph
Expand Down Expand Up @@ -79,7 +79,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>) -> i32 {
next_graph.get_resource_list(),
);
}
match save_state(&project_path, &state_config, &state).await {
match save_state(&config_file.project_path, &state_config, &state).await {
Ok(_) => {}
Err(e) => {
logger::end_action(Paint::red(e));
Expand Down
23 changes: 13 additions & 10 deletions mantle/mantle/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub async fn run(
format: Option<&str>,
) -> i32 {
logger::start_action("Loading project:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -76,7 +76,7 @@ pub async fn run(
target_config,
owner_config,
..
} = match load_project(project_path.clone(), config, environment).await {
} = match load_project(&config_file, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No diff available");
Expand All @@ -87,14 +87,17 @@ pub async fn run(
return 1;
}
};
let mut next_graph =
match get_desired_graph(project_path.as_path(), &target_config, &owner_config) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
let mut next_graph = match get_desired_graph(
config_file.project_path.as_path(),
&target_config,
&owner_config,
) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
logger::end_action("Succeeded");

logger::start_action("Diffing resource graphs:");
Expand Down
10 changes: 6 additions & 4 deletions mantle/mantle/src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ use rbx_mantle::{

pub async fn run(project: Option<&str>, key: Option<&str>) -> i32 {
logger::start_action("Download state file:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

if !matches!(config.state, StateConfig::Remote(_)) {
// config_file.header.

if !matches!(config_file.header.state, StateConfig::Remote(_)) {
logger::end_action(Paint::red("Project is not configured with remote state"));
return 1;
}

let state = match get_state(&project_path, &config).await {
let state = match get_state(&config_file.project_path, &config_file.header).await {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -32,7 +34,7 @@ pub async fn run(project: Option<&str>, key: Option<&str>) -> i32 {
Some(key) => StateConfig::LocalKey(key.to_owned()),
None => StateConfig::Local,
};
match save_state(&project_path, &state_config, &state).await {
match save_state(&config_file.project_path, &state_config, &state).await {
Ok(_) => {}
Err(e) => {
logger::end_action(Paint::red(e));
Expand Down
6 changes: 3 additions & 3 deletions mantle/mantle/src/commands/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rbx_mantle::{

pub async fn run(project: Option<&str>, environment: Option<&str>, target_id: &str) -> i32 {
logger::start_action("Loading project:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
Expand All @@ -23,7 +23,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, target_id: &s
environment_config,
state_config,
..
} = match load_project(project_path.clone(), config, environment).await {
} = match load_project(&config_file, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No import necessary");
Expand Down Expand Up @@ -90,7 +90,7 @@ pub async fn run(project: Option<&str>, environment: Option<&str>, target_id: &s
environment_config.label.clone(),
imported_graph.get_resource_list(),
);
match save_state(&project_path, &state_config, &state).await {
match save_state(&config_file.project_path, &state_config, &state).await {
Ok(_) => {}
Err(e) => {
logger::end_action(Paint::red(e));
Expand Down
25 changes: 12 additions & 13 deletions mantle/mantle/src/commands/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,24 @@ pub async fn run(
format: &str,
) -> i32 {
logger::start_action("Load outputs:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
let Project { current_graph, .. } =
match load_project(project_path.clone(), config, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No outputs available");
return 0;
}
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};
let Project { current_graph, .. } = match load_project(&config_file, environment).await {
Ok(Some(v)) => v,
Ok(None) => {
logger::end_action("No outputs available");
return 0;
}
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

let resources = current_graph.get_resource_list();
let outputs_map = resources
Expand Down
8 changes: 4 additions & 4 deletions mantle/mantle/src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use rbx_mantle::{

pub async fn run(project: Option<&str>, key: Option<&str>) -> i32 {
logger::start_action("Upload state file:");
let (project_path, config) = match load_project_config(project) {
let config_file = match load_project_config(project) {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

if !matches!(config.state, StateConfig::Remote(_)) {
if !matches!(config_file.header.state, StateConfig::Remote(_)) {
logger::end_action(Paint::red("Project is not configured with remote state"));
return 1;
}
Expand All @@ -24,15 +24,15 @@ pub async fn run(project: Option<&str>, key: Option<&str>) -> i32 {
Some(key) => StateConfig::LocalKey(key.to_owned()),
None => StateConfig::Local,
};
let state = match get_state_from_source(&project_path, state_config).await {
let state = match get_state_from_source(&config_file.project_path, state_config).await {
Ok(v) => v,
Err(e) => {
logger::end_action(Paint::red(e));
return 1;
}
};

match save_state(&project_path, &config.state, &state).await {
match save_state(&config_file.project_path, &config_file.header.state, &state).await {
Ok(_) => {}
Err(e) => {
logger::end_action(Paint::red(e));
Expand Down
Loading

0 comments on commit dac38d2

Please sign in to comment.