mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2025-02-25 18:55:26 -06:00
integrate cli into the main executable
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -723,6 +723,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"lact-cli",
|
||||
"lact-daemon",
|
||||
"lact-gui",
|
||||
]
|
||||
|
||||
@@ -3,21 +3,21 @@ use lact_client::DaemonClient;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about)]
|
||||
pub struct Args {
|
||||
pub struct CliArgs {
|
||||
pub gpu_id: Option<String>,
|
||||
#[command(subcommand)]
|
||||
pub subcommand: Command,
|
||||
pub subcommand: CliCommand,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum Command {
|
||||
pub enum CliCommand {
|
||||
/// List GPUs
|
||||
ListGpus,
|
||||
/// Show GPU info
|
||||
Info,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
impl CliArgs {
|
||||
pub fn gpu_ids(&self, client: &DaemonClient) -> Vec<String> {
|
||||
match self.gpu_id {
|
||||
Some(ref id) => vec![id.clone()],
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
mod args;
|
||||
pub mod args;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use args::{Args, Command};
|
||||
use clap::Parser;
|
||||
use args::{CliArgs, CliCommand};
|
||||
use lact_client::DaemonClient;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
pub fn run(args: CliArgs) -> Result<()> {
|
||||
let client = DaemonClient::connect()?;
|
||||
|
||||
let f = match args.subcommand {
|
||||
Command::ListGpus => list_gpus,
|
||||
Command::Info => info,
|
||||
CliCommand::ListGpus => list_gpus,
|
||||
CliCommand::Info => info,
|
||||
};
|
||||
f(&args, &client)
|
||||
}
|
||||
|
||||
fn list_gpus(_: &Args, client: &DaemonClient) -> Result<()> {
|
||||
fn list_gpus(_: &CliArgs, client: &DaemonClient) -> Result<()> {
|
||||
let buffer = client.list_devices()?;
|
||||
for entry in buffer.inner()? {
|
||||
let id = entry.id;
|
||||
@@ -29,7 +27,7 @@ fn list_gpus(_: &Args, client: &DaemonClient) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn info(args: &Args, client: &DaemonClient) -> Result<()> {
|
||||
fn info(args: &CliArgs, client: &DaemonClient) -> Result<()> {
|
||||
for id in args.gpu_ids(client) {
|
||||
let info_buffer = client.get_device_info(&id)?;
|
||||
let info = info_buffer.inner()?;
|
||||
@@ -8,6 +8,7 @@ default = ["lact-gui"]
|
||||
|
||||
[dependencies]
|
||||
lact-daemon = { path = "../lact-daemon" }
|
||||
lact-cli = { path = "../lact-cli" }
|
||||
lact-gui = { path = "../lact-gui", optional = true }
|
||||
anyhow = "1.0.68"
|
||||
clap = { version = "4.1.4", features = ["derive"] }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use clap::{Parser, Subcommand};
|
||||
use lact_cli::args::CliArgs;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct Args {
|
||||
@@ -12,4 +13,5 @@ pub enum Command {
|
||||
Daemon,
|
||||
/// Run the GUI
|
||||
Gui,
|
||||
Cli(CliArgs),
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ fn main() -> anyhow::Result<()> {
|
||||
match command {
|
||||
Command::Daemon => lact_daemon::run(),
|
||||
Command::Gui => run_gui(),
|
||||
Command::Cli(cli_args) => lact_cli::run(cli_args),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user