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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.vscode
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Make sure you have Rust installed first!
- Run `cargo run --release install package` or `cargo run --release install package@version`

**IMPORTANT ⚠️**
In order for the symlinks to work you need to use the `--preserve-symlinks` flag when running `node myfile.js`. If development continues I'll make this easier so you don't have to do this extra step!
In order for the symlinks to work you need to use the `--preserve-symlinks` flag when running `node myfile.js`. You can also use the command `click exec myfile.js`

## How fast?

Expand Down
1 change: 0 additions & 1 deletion src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
collections::HashMap,
fs::{self as fs_sync, File},
io::{ErrorKind, Read, Seek, SeekFrom},
path::Path,
str::FromStr,
};

Expand Down
5 changes: 3 additions & 2 deletions src/commands/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::errors::{
};

use super::install::InstallHandler;
use super::exec::RunFileHandler;

#[async_trait]
pub trait CommandHandler {
Expand All @@ -20,14 +21,14 @@ pub async fn handle_args(mut args: Args) -> Result<(), ParseError> {
let command = match args.next() {
Some(command) => command,
None => {
// TODO(conaticus): Implement help menu
println!("No help menu implemented yet.");
println!("Use: click <command> [options]\n click install <package_name> [semver]\n click exec <file name>");
return Ok(());
}
};

let mut command_handler: Box<dyn CommandHandler> = match command.to_lowercase().as_str() {
"install" => Box::<InstallHandler>::default(),
"exec" => Box::<RunFileHandler>::default(),
_ => return Err(CommandNotFound(command.to_string())),
};

Expand Down
40 changes: 40 additions & 0 deletions src/commands/exec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use crate::errors::{CommandError, ParseError};
use async_trait::async_trait;
use std::env::Args;
use std::process::Command;
use std::io;

use super::command_handler::CommandHandler;

#[derive(Default)]
pub struct RunFileHandler {
file_name: String,
}

#[async_trait]
impl CommandHandler for RunFileHandler {
fn parse(&mut self, args: &mut Args) -> Result<(), ParseError> {
let parsed_args = args
.next()
.ok_or(ParseError::MissingArgument(String::from("file name")))?;

self.file_name = parsed_args;

Ok(())
}
async fn execute(&self) -> Result<(), CommandError> {
let cmd = Command::new("node")
.args(["--preserve-symlinks", &self.file_name])
.status()
.map_err(CommandError::ComandFailedError)?;

if !(cmd.success()) {
let error_message = "Something went wrong";

let error = io::Error::new(io::ErrorKind::Other, error_message);
return Err(CommandError::ComandFailedError(error));
}

Ok(())
}
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod command_handler;
pub mod install;
pub mod exec;
2 changes: 2 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ pub enum CommandError {
FailedToWriteFile(Error),
#[error("failed to serialize package lock ({0})")]
FailedToSerializePackageLock(serde_json::Error),
#[error("command failed ({0})")]
ComandFailedError(Error)
}