diff --git a/Cargo.lock b/Cargo.lock
index 9ba784e..417f55c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -255,6 +255,7 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
name = "frork"
version = "0.1.0"
dependencies = [
+ "clap",
"frork-lib",
"mlua",
]
diff --git a/frork-lua/Cargo.toml b/frork-lua/Cargo.toml
index 3e4b1b9..01bae2b 100644
--- a/frork-lua/Cargo.toml
+++ b/frork-lua/Cargo.toml
@@ -8,4 +8,5 @@ crate-type = ["cdylib"]
[dependencies]
frork-lib = { path = "../frork-lib" }
+clap = { version = "*", features = ["derive"] }
mlua = { version = "*", features = ["lua54", "module"] }
diff --git a/frork-lua/src/lib.rs b/frork-lua/src/lib.rs
index 83298f4..ee7fe27 100644
--- a/frork-lua/src/lib.rs
+++ b/frork-lua/src/lib.rs
@@ -1,3 +1,4 @@
+use clap::{Parser, Subcommand};
use mlua::prelude::*;
fn hello(name: Option<String>) -> String {
@@ -11,6 +12,21 @@ fn add(x: i64, y: i64) -> i64 {
x + y
}
+#[derive(Parser)]
+#[command(name = "fennel-app")]
+struct Cli {
+ #[command(subcommand)]
+ command: Option<Commands>,
+}
+
+#[derive(Subcommand)]
+enum Commands {
+ #[command(about = "Check status of resources")]
+ Status,
+ #[command(about = "Satisfy (install/fix) resources")]
+ Satisfy,
+}
+
#[mlua::lua_module]
fn frork(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table()?;
@@ -27,6 +43,21 @@ fn frork(lua: &Lua) -> LuaResult<LuaTable> {
lua.create_function(|_, (x, y): (i64, i64)| Ok(add(x, y)))?,
)?;
+ // CLI parsing function
+ exports.set(
+ "parse_args",
+ lua.create_function(|_, _: LuaMultiValue| {
+ let cli = Cli::parse();
+
+ let result = match cli.command.unwrap_or(Commands::Status) {
+ Commands::Status => "status".to_string(),
+ Commands::Satisfy => "satisfy".to_string(),
+ };
+
+ Ok(result)
+ })?,
+ )?;
+
// A table with some constants
let constants = lua.create_table()?;
constants.set("VERSION", "1.0.0")?;
@@ -34,4 +65,4 @@ fn frork(lua: &Lua) -> LuaResult<LuaTable> {
exports.set("constants", constants)?;
Ok(exports)
-}
\ No newline at end of file
+}