Skip to content

Commit

Permalink
feat: rocks check
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Dec 30, 2024
1 parent 043335e commit fd3a50f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
42 changes: 42 additions & 0 deletions rocks-bin/src/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use eyre::{OptionExt, Result};
use rocks_lib::{
build::BuildBehaviour,
config::{Config, LuaVersion},
lockfile::PinnedState::Pinned,
operations::{self, install},
progress::MultiProgress,
project::Project,
remote_package_db::RemotePackageDB,
};

pub async fn check(config: Config) -> Result<()> {
let project = Project::current()?.ok_or_eyre("Not in a project!")?;

let db = RemotePackageDB::from_config(&config).await?;

install(
vec![(BuildBehaviour::NoForce, "luacheck".parse()?)],
Pinned,
&db,
&config,
MultiProgress::new_arc(),
)
.await?;

operations::run(
"luacheck",
vec![
project.root().to_string_lossy().into(),
"--exclude-files".into(),
project
.tree(LuaVersion::from(&config)?)?
.root()
.to_string_lossy()
.to_string(),
],
config,
)
.await?;

Ok(())
}
3 changes: 3 additions & 0 deletions rocks-bin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use update::Update;
use upload::Upload;

pub mod build;
pub mod check;
pub mod debug;
pub mod download;
pub mod fetch;
Expand Down Expand Up @@ -110,6 +111,8 @@ pub enum Commands {
Add,
/// Build/compile a rock.
Build(Build),
/// Runs `luacheck` in the current project.
Check,
/// [UNIMPLEMENTED] Query information about Rocks's configuration.
Config,
/// Various debugging utilities.
Expand Down
4 changes: 4 additions & 0 deletions rocks-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{path::PathBuf, time::Duration};
use clap::{Parser, Subcommand};
use rocks::{
build::{self, Build},
check,
debug::Debug,
download::{self, Download},
fetch, format,
Expand Down Expand Up @@ -95,6 +96,8 @@ pub enum Commands {
Add,
/// Build/compile a rock.
Build(Build),
/// Runs `luacheck` in the current project.
Check,
/// [UNIMPLEMENTED] Query information about Rocks's configuration.
Config,
/// Various debugging utilities.
Expand Down Expand Up @@ -211,6 +214,7 @@ async fn main() {
Commands::Pin(pin_data) => pin::set_pinned_state(pin_data, config, Pinned).unwrap(),
Commands::Unpin(pin_data) => pin::set_pinned_state(pin_data, config, Unpinned).unwrap(),
Commands::Upload(upload_data) => upload::upload(upload_data, config).await.unwrap(),
Commands::Check => check::check(config).await.unwrap(),
Commands::Add => unimplemented!(),
Commands::Config => unimplemented!(),
Commands::Doc => unimplemented!(),
Expand Down
2 changes: 1 addition & 1 deletion rocks-lib/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Project {
}

pub fn tree(&self, lua_version: LuaVersion) -> io::Result<Tree> {
Tree::new(self.root.clone(), lua_version)
Tree::new(self.root.join(".rocks"), lua_version)
}
}

Expand Down

0 comments on commit fd3a50f

Please sign in to comment.