Skip to content
Merged
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
21 changes: 21 additions & 0 deletions crates/bashkit-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BashKit CLI - Command line interface for bashkit
# Run bash scripts in a sandboxed environment

[package]
name = "bashkit-cli"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
description = "Command line interface for BashKit sandboxed bash interpreter"

[[bin]]
name = "bashkit"
path = "src/main.rs"

[dependencies]
bashkit = { path = "../bashkit" }
tokio.workspace = true
clap.workspace = true
anyhow.workspace = true
66 changes: 66 additions & 0 deletions crates/bashkit-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//! BashKit CLI - Command line interface for sandboxed bash execution
//!
//! Usage:
//! bashkit -c 'echo hello' # Execute a command string
//! bashkit script.sh # Execute a script file
//! bashkit # Interactive REPL (not yet implemented)

use anyhow::{Context, Result};
use clap::Parser;
use std::path::PathBuf;

/// BashKit - Sandboxed bash interpreter
#[derive(Parser, Debug)]
#[command(name = "bashkit")]
#[command(author, version, about, long_about = None)]
struct Args {
/// Execute the given command string
#[arg(short = 'c')]
command: Option<String>,

/// Script file to execute
#[arg()]
script: Option<PathBuf>,

/// Arguments to pass to the script
#[arg(trailing_var_arg = true)]
args: Vec<String>,
}

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();

let mut bash = bashkit::Bash::new();

// Execute command string if provided
if let Some(cmd) = args.command {
let result = bash.exec(&cmd).await.context("Failed to execute command")?;
print!("{}", result.stdout);
if !result.stderr.is_empty() {
eprint!("{}", result.stderr);
}
std::process::exit(result.exit_code);
}

// Execute script file if provided
if let Some(script_path) = args.script {
let script = std::fs::read_to_string(&script_path)
.with_context(|| format!("Failed to read script: {}", script_path.display()))?;

let result = bash
.exec(&script)
.await
.context("Failed to execute script")?;
print!("{}", result.stdout);
if !result.stderr.is_empty() {
eprint!("{}", result.stderr);
}
std::process::exit(result.exit_code);
}

// Interactive REPL (not yet implemented)
eprintln!("bashkit: interactive mode not yet implemented");
eprintln!("Usage: bashkit -c 'command' or bashkit script.sh");
std::process::exit(1);
}
3 changes: 2 additions & 1 deletion crates/bashkit/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Error types for BashKit

use crate::limits::LimitExceeded;
use thiserror::Error;

/// Result type alias using BashKit's Error.
Expand All @@ -26,5 +27,5 @@ pub enum Error {

/// Resource limit exceeded.
#[error("resource limit exceeded: {0}")]
ResourceLimit(String),
ResourceLimit(#[from] LimitExceeded),
}
9 changes: 8 additions & 1 deletion crates/bashkit/src/fs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
//! Virtual filesystem for BashKit
//!
//! Provides an async filesystem trait and implementations.
//! Provides an async filesystem trait and implementations:
//! - `InMemoryFs`: Simple in-memory filesystem
//! - `OverlayFs`: Copy-on-write overlay with whiteouts
//! - `MountableFs`: Multiple filesystems at mount points

mod memory;
mod mountable;
mod overlay;
mod traits;

pub use memory::InMemoryFs;
pub use mountable::MountableFs;
pub use overlay::OverlayFs;
#[allow(unused_imports)]
pub use traits::{DirEntry, FileSystem, FileType, Metadata};
Loading
Loading