-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ink0rr/dev
rgl v0.9.0
- Loading branch information
Showing
36 changed files
with
1,275 additions
and
1,005 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,35 @@ | ||
use super::Command; | ||
use crate::info; | ||
use crate::rgl::{Config, FilterInstaller, FilterType, Session}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
|
||
pub fn add_filters(filters: Vec<&String>, force: bool) -> Result<()> { | ||
let mut config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
let data_path = config.get_data_path(); | ||
for arg in filters { | ||
info!("Adding filter <b>{}</>...", arg); | ||
let filter = FilterInstaller::from_arg(arg)?; | ||
if filter.install(FilterType::Remote, Some(&data_path), force)? { | ||
info!("Filter <b>{}</> successfully added", filter.name); | ||
config.add_filter(filter)?; | ||
/// Add filter(s) to current project | ||
#[derive(Args)] | ||
pub struct Add { | ||
#[arg(required = true)] | ||
filters: Vec<String>, | ||
#[arg(short, long)] | ||
force: bool, | ||
} | ||
|
||
impl Command for Add { | ||
fn dispatch(&self) -> Result<()> { | ||
let mut config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
let data_path = config.get_data_path(); | ||
for arg in &self.filters { | ||
info!("Adding filter <b>{}</>...", arg); | ||
let filter = FilterInstaller::from_arg(arg)?; | ||
if filter.install(FilterType::Remote, Some(&data_path), self.force)? { | ||
info!("Filter <b>{}</> successfully added", filter.name); | ||
config.add_filter(filter)?; | ||
} | ||
} | ||
config.save()?; | ||
session.unlock() | ||
} | ||
fn error_context(&self) -> String { | ||
"Error adding filter".to_owned() | ||
} | ||
config.save()?; | ||
session.unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
use crate::fs::{empty_dir, try_symlink}; | ||
use crate::info; | ||
use crate::rgl::{Config, Filter, FilterContext, Session}; | ||
use super::Command; | ||
use crate::fs::{copy_dir, empty_dir, sync_dir, try_symlink}; | ||
use crate::rgl::{Config, Session}; | ||
use crate::{info, measure_time}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
use std::path::Path; | ||
|
||
pub fn apply(filter_name: &str, run_args: Vec<String>) -> Result<()> { | ||
let config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
/// Runs a profile and apply changes to the current project | ||
#[derive(Args)] | ||
pub struct Apply { | ||
profile: String, | ||
} | ||
|
||
impl Command for Apply { | ||
fn dispatch(&self) -> Result<()> { | ||
let config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
|
||
let bp = config.get_behavior_pack(); | ||
let rp = config.get_resource_pack(); | ||
|
||
let temp = Path::new(".regolith").join("tmp"); | ||
let temp_bp = temp.join("BP"); | ||
let temp_rp = temp.join("RP"); | ||
|
||
let temp = Path::new(".regolith").join("tmp"); | ||
let temp_bp = temp.join("BP"); | ||
let temp_rp = temp.join("RP"); | ||
empty_dir(&temp)?; | ||
copy_dir(&bp, &temp_bp)?; | ||
copy_dir(&rp, &temp_rp)?; | ||
try_symlink(config.get_data_path(), temp.join("data"))?; | ||
|
||
empty_dir(&temp)?; | ||
try_symlink(config.get_behavior_pack(), temp_bp)?; | ||
try_symlink(config.get_resource_pack(), temp_rp)?; | ||
try_symlink(config.get_data_path(), temp.join("data"))?; | ||
let profile = config.get_profile(&self.profile)?; | ||
measure_time!(self.profile, { | ||
info!("Running <b>{}</> profile", self.profile); | ||
profile.run(&config, &temp, &self.profile)?; | ||
}); | ||
|
||
let filter = config.get_filter(filter_name)?; | ||
let context = FilterContext::new(filter.get_type(), filter_name)?; | ||
filter.run(&context, &temp, &run_args)?; | ||
info!("Successfully applied filter <b>{filter_name}</>"); | ||
info!( | ||
"Applying changes to source directory: \n\ | ||
\tBP: {} \n\ | ||
\tRP: {}", | ||
bp.display(), | ||
rp.display() | ||
); | ||
sync_dir(temp_bp, bp)?; | ||
sync_dir(temp_rp, rp)?; | ||
|
||
session.unlock() | ||
info!("Successfully applied profile <b>{}</>", self.profile); | ||
session.unlock() | ||
} | ||
fn error_context(&self) -> String { | ||
format!("Error applying profile <b>{}</>", self.profile) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
use super::Command; | ||
use crate::fs::rimraf; | ||
use crate::info; | ||
use crate::rgl::{Config, Session}; | ||
use anyhow::Result; | ||
use clap::Args; | ||
|
||
pub fn clean() -> Result<()> { | ||
// Make sure it's a valid project | ||
let _ = Config::load()?; | ||
let mut session = Session::lock()?; | ||
info!("Cleaning .regolith folder..."); | ||
rimraf(".regolith")?; | ||
info!("Cleaning build files..."); | ||
rimraf("build")?; | ||
info!("Completed!"); | ||
session.unlock() | ||
/// Clean the current project's cache and build files | ||
#[derive(Args)] | ||
pub struct Clean; | ||
|
||
impl Command for Clean { | ||
fn dispatch(&self) -> Result<()> { | ||
// Make sure it's a valid project | ||
let _ = Config::load()?; | ||
let mut session = Session::lock()?; | ||
info!("Cleaning .regolith folder..."); | ||
rimraf(".regolith")?; | ||
info!("Cleaning build files..."); | ||
rimraf("build")?; | ||
info!("Completed!"); | ||
session.unlock() | ||
} | ||
fn error_context(&self) -> String { | ||
"Error cleaning files".to_owned() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,67 @@ | ||
use crate::fs::{empty_dir, read_json, try_symlink}; | ||
use super::Command; | ||
use crate::fs::{copy_dir, empty_dir, read_json, sync_dir, try_symlink}; | ||
use crate::info; | ||
use crate::rgl::{Config, Filter, FilterContext, FilterType, RemoteFilterConfig, Session}; | ||
use anyhow::{Context, Result}; | ||
use clap::Args; | ||
use std::path::Path; | ||
|
||
pub fn exec(filter_name: &str, run_args: Vec<String>) -> Result<()> { | ||
let config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
|
||
let temp = Path::new(".regolith").join("tmp"); | ||
let temp_bp = temp.join("BP"); | ||
let temp_rp = temp.join("RP"); | ||
|
||
empty_dir(&temp)?; | ||
try_symlink(config.get_behavior_pack(), temp_bp)?; | ||
try_symlink(config.get_resource_pack(), temp_rp)?; | ||
try_symlink(config.get_data_path(), temp.join("data"))?; | ||
|
||
if let Ok(filter) = config.get_filter(filter_name) { | ||
info!("Running local filter <b>{filter_name}</>"); | ||
let context = FilterContext::new(filter.get_type(), filter_name)?; | ||
filter.run(&context, &temp, &run_args)?; | ||
} else { | ||
info!("Running global filter <b>{filter_name}</>"); | ||
let context = FilterContext::new(FilterType::Tool, filter_name)?; | ||
let config_path = context.filter_dir.join("filter.json"); | ||
let config = read_json::<RemoteFilterConfig>(config_path).context(format!( | ||
"Failed to load config for tool <b>{filter_name}</>" | ||
))?; | ||
|
||
for filter in config.filters { | ||
filter.run(&context, &temp, &run_args)?; | ||
/// Executes a filter and apply changes to the current project | ||
#[derive(Args)] | ||
#[clap(alias = "x")] | ||
pub struct Exec { | ||
filter: String, | ||
run_args: Vec<String>, | ||
} | ||
|
||
impl Command for Exec { | ||
fn dispatch(&self) -> Result<()> { | ||
let config = Config::load()?; | ||
let mut session = Session::lock()?; | ||
|
||
let bp = config.get_behavior_pack(); | ||
let rp = config.get_resource_pack(); | ||
|
||
let temp = Path::new(".regolith").join("tmp"); | ||
let temp_bp = temp.join("BP"); | ||
let temp_rp = temp.join("RP"); | ||
|
||
empty_dir(&temp)?; | ||
copy_dir(&bp, &temp_bp)?; | ||
copy_dir(&rp, &temp_rp)?; | ||
try_symlink(config.get_data_path(), temp.join("data"))?; | ||
|
||
if let Ok(filter) = config.get_filter(&self.filter) { | ||
info!("Running local filter <b>{}</>", self.filter); | ||
let context = FilterContext::new(filter.get_type(), &self.filter)?; | ||
filter.run(&context, &temp, &self.run_args)?; | ||
} else { | ||
info!("Running global filter <b>{}</>", self.filter); | ||
let context = FilterContext::new(FilterType::Global, &self.filter)?; | ||
let config_path = context.filter_dir.join("filter.json"); | ||
let config = read_json::<RemoteFilterConfig>(config_path).context(format!( | ||
"Failed to load config for filter <b>{}</>", | ||
self.filter | ||
))?; | ||
for filter in config.filters { | ||
filter.run(&context, &temp, &self.run_args)?; | ||
} | ||
} | ||
} | ||
|
||
session.unlock() | ||
info!( | ||
"Applying changes to source directory: \n\ | ||
\tBP: {} \n\ | ||
\tRP: {}", | ||
bp.display(), | ||
rp.display() | ||
); | ||
sync_dir(temp_bp, bp)?; | ||
sync_dir(temp_rp, rp)?; | ||
|
||
info!("Successfully executed filter <b>{}</>", self.filter); | ||
session.unlock() | ||
} | ||
fn error_context(&self) -> String { | ||
format!("Error executing filter <b>{}</>", self.filter) | ||
} | ||
} |
Oops, something went wrong.