Skip to content

Commit

Permalink
Move thebacknd CLI definition to a library.
Browse files Browse the repository at this point in the history
  • Loading branch information
noteed committed May 13, 2024
1 parent bfba7b1 commit 62a75b8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@ readme = "README.md"
[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
regex = "1.10.4"

[[bin]]
name = "thebacknd"
path = "src/bin/thebacknd.rs"

[[bin]]
name = "thewithn"
path = "src/bin/thewithn.rs"

[lib]
name = "thebacknd"
path = "src/lib/thebacknd/lib.rs"
31 changes: 3 additions & 28 deletions src/bin/thebacknd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
//!
//! Thebacknd runs ephemeral virtual machines in the cloud in one command.
use clap::{Parser, Subcommand};
use clap::{Parser};
use std::process::{Command as ProcessCommand, exit};
use regex::Regex;

use thebacknd::client::cli::{Cli, Commands, RunCmd};

/// Thebacknd client-side binary main entry point.
fn main() {
let cli = Cli::parse();
Expand All @@ -15,33 +17,6 @@ fn main() {
}
}

#[derive(Parser)]
#[command(
version = "0.1.0",
author = "Võ Minh Thu <thu@hypered.io>",
about = "Ephemeral virtual machines in the cloud in one command"
)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
Run(RunCmd),
}

/// Run a toplevel or a binary in a cloud virtual machine
#[derive(Parser)]
struct RunCmd {
/// The full path to a binary or toplevel store path
full_path: Option<String>,

/// Enable verbose output
#[arg(short, long)]
verbose: bool,
}

fn handle_run(args: &RunCmd) {
let RunCmd{ full_path, verbose } = args;
if let Some(full_path) = full_path {
Expand Down
29 changes: 29 additions & 0 deletions src/lib/thebacknd/client/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/// Command-line definition for thebacknd client binary.
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(
version = "0.1.0",
author = "Võ Minh Thu <thu@hypered.io>",
about = "Ephemeral virtual machines in the cloud in one command"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
Run(RunCmd),
}

/// Run a toplevel or a binary in a cloud virtual machine
#[derive(Parser)]
pub struct RunCmd {
/// The full path to a binary or toplevel store path
pub full_path: Option<String>,

/// Enable verbose output
#[arg(short, long)]
pub verbose: bool,
}
1 change: 1 addition & 0 deletions src/lib/thebacknd/client/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod cli;
1 change: 1 addition & 0 deletions src/lib/thebacknd/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod client;

0 comments on commit 62a75b8

Please sign in to comment.