Skip to content

Commit

Permalink
Merge pull request #24 from ink0rr/dev
Browse files Browse the repository at this point in the history
rgl v0.10.0
  • Loading branch information
ink0rr authored Jul 5, 2024
2 parents e551967 + afce7f0 commit 5119240
Show file tree
Hide file tree
Showing 32 changed files with 675 additions and 757 deletions.
372 changes: 122 additions & 250 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
[package]
name = "rgl"
version = "0.9.0"
version = "0.10.0"
edition = "2021"

[[bin]]
name = "rgl"

[dependencies]
anyhow = "1.0.86"
clap = { version = "4.5.6", features = ["cargo", "derive"] }
clap = { version = "4.5.8", features = ["cargo", "derive"] }
dialoguer = "0.11.0"
dunce = "1.0.4"
enum_dispatch = "0.3.13"
fslock = "0.2.1"
indexmap = { version = "2.2.6", features = ["serde"] }
md5 = "0.7.0"
notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
once_cell = "1.19.0"
paris = { version = "1.5.15", features = ["macros"] }
rayon = "1.10.0"
semver = "1.0.23"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
serde_json = "1.0.120"
tempfile = "3.10.1"
ureq = "2.9.7"
uuid = { version = "1.8.0", features = ["v4"] }
uuid = { version = "1.9.1", features = ["v4"] }
walkdir = "2.5.0"
zip = "2.1.3"
zip = "0.6.6"
12 changes: 6 additions & 6 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Command;
use crate::info;
use crate::rgl::{Config, FilterInstaller, FilterType, Session};
use crate::rgl::{Config, RemoteFilter, Session};
use anyhow::Result;
use clap::Args;

Expand All @@ -20,11 +20,11 @@ impl Command for Add {
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)?;
}
let (name, remote) = RemoteFilter::parse(arg)?;
remote.install(&name, Some(&data_path), self.force)?;

info!("Filter <b>{name}</> successfully added");
config.add_filter(&name, &remote.into())?;
}
config.save()?;
session.unlock()
Expand Down
23 changes: 9 additions & 14 deletions src/commands/exec.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::Command;
use crate::fs::{copy_dir, empty_dir, read_json, sync_dir, try_symlink};
use crate::fs::{copy_dir, empty_dir, sync_dir, try_symlink};
use crate::info;
use crate::rgl::{Config, Filter, FilterContext, FilterType, RemoteFilterConfig, Session};
use anyhow::{Context, Result};
use crate::rgl::{Config, Filter, FilterContext, GlobalFilters, Session};
use anyhow::Result;
use clap::Args;
use std::path::Path;

Expand Down Expand Up @@ -32,20 +32,15 @@ impl Command for Exec {
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)?;
info!("Running filter <b>{}</>", self.filter);
let context = FilterContext::new(&self.filter, &filter)?;
filter.run(&context, &temp, &self.run_args)?;
} else {
let global_filters = GlobalFilters::load()?;
let filter = global_filters.get(&self.filter)?.into();
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)?;
}
let context = FilterContext::new(&self.filter, &filter)?;
filter.run(&context, &temp, &self.run_args)?;
}

info!(
Expand Down
21 changes: 7 additions & 14 deletions src/commands/get.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use super::Command;
use crate::info;
use crate::rgl::{
Config, Filter, FilterContext, FilterDefinition, FilterInstaller, FilterType, Session,
};
use crate::rgl::{Config, Filter, FilterContext, FilterDefinition, Session};
use anyhow::Result;
use clap::Args;
use semver::Version;

/// Fetch filters defined in the `config.json` file
#[derive(Args)]
Expand All @@ -21,19 +18,15 @@ impl Command for Get {
let data_path = config.get_data_path();
for (name, value) in config.get_filters() {
match FilterDefinition::from_value(value)? {
FilterDefinition::Local(filter) => {
FilterDefinition::Remote(remote) => {
info!("Downloading filter <b>{name}</>...");
remote.install(&name, Some(&data_path), false)?;
}
filter => {
info!("Installing dependencies for <b>{name}</>...");
let context = FilterContext::new(FilterType::Local, &name)?;
let context = FilterContext::new(&name, &filter)?;
filter.install_dependencies(&context)?;
}
FilterDefinition::Remote(filter) => {
info!("Getting filter <b>{name}</>...");
let git_ref = Version::parse(&filter.version)
.map(|version| format!("{name}-{version}"))
.unwrap_or(filter.version);
let filter = FilterInstaller::new(&name, filter.url, git_ref);
filter.install(FilterType::Remote, Some(&data_path), self.force)?;
}
};
}
info!("Success getting filters!");
Expand Down
25 changes: 25 additions & 0 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::rgl::{get_cache_dir, get_global_filters_path, get_user_config_path};
use crate::Command;
use anyhow::Result;
use clap::{crate_version, Args};

#[derive(Args)]
pub struct Info {}
impl Command for Info {
fn dispatch(&self) -> Result<()> {
println!("rgl version: {}", crate_version!());
println!("RGL_DIR location: {}", get_cache_dir()?.display());
println!(
"User config location: {}",
get_user_config_path()?.display()
);
println!(
"Global filters location: {}",
get_global_filters_path()?.display()
);
Ok(())
}
fn error_context(&self) -> String {
"Error getting rgl info".to_owned()
}
}
14 changes: 8 additions & 6 deletions src/commands/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Command;
use crate::info;
use crate::rgl::{FilterInstaller, FilterType};
use crate::rgl::{GlobalFilters, RemoteFilter};
use anyhow::Result;
use clap::Args;

Expand All @@ -16,14 +16,16 @@ pub struct Install {

impl Command for Install {
fn dispatch(&self) -> Result<()> {
let mut global_filters = GlobalFilters::load()?;
for arg in &self.filters {
info!("Installing filter <b>{}</>...", arg);
let filter = FilterInstaller::from_arg(arg)?;
if filter.install(FilterType::Global, None, self.force)? {
info!("Filter <b>{}</> successfully installed", filter.name);
}
let (name, remote) = RemoteFilter::parse(arg)?;
remote.install(&name, None, self.force)?;

info!("Filter <b>{name}</> successfully installed");
global_filters.add(&name, remote);
}
Ok(())
global_filters.save()
}
fn error_context(&self) -> String {
"Error installing filter".to_owned()
Expand Down
67 changes: 44 additions & 23 deletions src/commands/list.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
use super::Command;
use crate::log;
use crate::rgl::{Config, FilterDefinition};
use crate::rgl::{Config, FilterDefinition, GlobalFilters};
use anyhow::{Context, Result};
use clap::Args;

/// List filters defined in the `config.json` file
#[derive(Args)]
#[clap(alias = "ls")]
pub struct List;
pub struct List {
#[arg(short, long)]
global: bool,
}

impl Command for List {
fn dispatch(&self) -> Result<()> {
let config = Config::load()?;

let mut local_filters = vec![];
let mut remote_filters = vec![];
for (name, value) in config.get_filters() {
let filter = FilterDefinition::from_value(value.to_owned())?;
match filter {
FilterDefinition::Local(_) => {
let run_with = value["runWith"]
.as_str()
.context("Invalid filter definition")?
.to_owned();
local_filters.push((name, run_with));
}
FilterDefinition::Remote(filter) => {
remote_filters.push((name, filter.version));
}
}
match self.global {
false => list_project(),
true => list_global(),
}
print("Local filters:", &local_filters);
print("Remote filters:", &remote_filters);
Ok(())
}
fn error_context(&self) -> String {
"Error listing installed filters".to_owned()
}
}

fn list_project() -> Result<()> {
let config = Config::load()?;

let mut local_filters = vec![];
let mut remote_filters = vec![];
for (name, value) in config.get_filters() {
let filter = FilterDefinition::from_value(value.to_owned())?;
match filter {
FilterDefinition::Local(_) => {
let run_with = value["runWith"]
.as_str()
.context("Invalid filter definition")?
.to_owned();
local_filters.push((name, run_with));
}
FilterDefinition::Remote(filter) => {
remote_filters.push((name, filter.version));
}
}
}
print("Local filters:", &local_filters);
print("Remote filters:", &remote_filters);
Ok(())
}

fn list_global() -> Result<()> {
let global_filters = GlobalFilters::load()?;

let mut filters = vec![];
for (name, filter) in global_filters.iter() {
filters.push((name.to_owned(), filter.version.to_owned()));
}
print("Global filters:", &filters);
Ok(())
}

fn print(label: &str, filters: &Vec<(String, String)>) {
if filters.is_empty() {
return;
Expand Down
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod apply;
mod clean;
mod exec;
mod get;
mod info;
mod init;
mod install;
mod list;
Expand All @@ -17,6 +18,7 @@ pub use self::apply::*;
pub use self::clean::*;
pub use self::exec::*;
pub use self::get::*;
pub use self::info::*;
pub use self::init::*;
pub use self::install::*;
pub use self::list::*;
Expand Down
5 changes: 1 addition & 4 deletions src/commands/remove.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::Command;
use crate::fs::rimraf;
use crate::rgl::{Config, FilterType, Session};
use crate::rgl::{Config, Session};
use crate::{info, warn};
use anyhow::Result;
use clap::Args;
Expand All @@ -19,8 +18,6 @@ impl Command for Remove {
let mut session = Session::lock()?;
for name in &self.filters {
if config.remove_filter(name).is_some() {
let filter_dir = FilterType::Remote.cache_dir(name)?;
rimraf(filter_dir)?;
info!("Removed filter <b>{name}</>");
} else {
warn!("Filter <b>{name}</> not found");
Expand Down
12 changes: 5 additions & 7 deletions src/commands/uninstall.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::Command;
use crate::fs::rimraf;
use crate::rgl::FilterType;
use crate::rgl::GlobalFilters;
use crate::{info, warn};
use anyhow::Result;
use clap::Args;

/// Uninstall globally installed filter(s)
/// Uninstall filter(s)
#[derive(Args)]
pub struct Uninstall {
#[arg(required = true)]
Expand All @@ -14,16 +13,15 @@ pub struct Uninstall {

impl Command for Uninstall {
fn dispatch(&self) -> Result<()> {
let mut global_filters = GlobalFilters::load()?;
for name in &self.filters {
let filter_dir = FilterType::Global.cache_dir(name)?;
if filter_dir.exists() {
rimraf(filter_dir)?;
if global_filters.remove(name).is_some() {
info!("Uninstalled filter <b>{name}</>");
} else {
warn!("Filter <b>{name}</> not found");
}
}
Ok(())
global_filters.save()
}
fn error_context(&self) -> String {
"Error uninstalling filter".to_owned()
Expand Down
4 changes: 3 additions & 1 deletion src/commands/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ pub struct Watch {

impl Command for Watch {
fn dispatch(&self) -> Result<()> {
run_or_watch(&self.profile, true, !self.no_cache)
loop {
run_or_watch(&self.profile, true, !self.no_cache)?;
}
}
fn error_context(&self) -> String {
format!("Error running <b>{}</> profile", self.profile)
Expand Down
Loading

0 comments on commit 5119240

Please sign in to comment.