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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"lact-cli",
|
||||||
"lact-daemon",
|
"lact-daemon",
|
||||||
"lact-gui",
|
"lact-gui",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -3,21 +3,21 @@ use lact_client::DaemonClient;
|
|||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about)]
|
#[command(author, version, about)]
|
||||||
pub struct Args {
|
pub struct CliArgs {
|
||||||
pub gpu_id: Option<String>,
|
pub gpu_id: Option<String>,
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub subcommand: Command,
|
pub subcommand: CliCommand,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
pub enum Command {
|
pub enum CliCommand {
|
||||||
/// List GPUs
|
/// List GPUs
|
||||||
ListGpus,
|
ListGpus,
|
||||||
/// Show GPU info
|
/// Show GPU info
|
||||||
Info,
|
Info,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl CliArgs {
|
||||||
pub fn gpu_ids(&self, client: &DaemonClient) -> Vec<String> {
|
pub fn gpu_ids(&self, client: &DaemonClient) -> Vec<String> {
|
||||||
match self.gpu_id {
|
match self.gpu_id {
|
||||||
Some(ref id) => vec![id.clone()],
|
Some(ref id) => vec![id.clone()],
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
mod args;
|
pub mod args;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use args::{Args, Command};
|
use args::{CliArgs, CliCommand};
|
||||||
use clap::Parser;
|
|
||||||
use lact_client::DaemonClient;
|
use lact_client::DaemonClient;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
pub fn run(args: CliArgs) -> Result<()> {
|
||||||
let args = Args::parse();
|
|
||||||
let client = DaemonClient::connect()?;
|
let client = DaemonClient::connect()?;
|
||||||
|
|
||||||
let f = match args.subcommand {
|
let f = match args.subcommand {
|
||||||
Command::ListGpus => list_gpus,
|
CliCommand::ListGpus => list_gpus,
|
||||||
Command::Info => info,
|
CliCommand::Info => info,
|
||||||
};
|
};
|
||||||
f(&args, &client)
|
f(&args, &client)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_gpus(_: &Args, client: &DaemonClient) -> Result<()> {
|
fn list_gpus(_: &CliArgs, client: &DaemonClient) -> Result<()> {
|
||||||
let buffer = client.list_devices()?;
|
let buffer = client.list_devices()?;
|
||||||
for entry in buffer.inner()? {
|
for entry in buffer.inner()? {
|
||||||
let id = entry.id;
|
let id = entry.id;
|
||||||
@@ -29,7 +27,7 @@ fn list_gpus(_: &Args, client: &DaemonClient) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn info(args: &Args, client: &DaemonClient) -> Result<()> {
|
fn info(args: &CliArgs, client: &DaemonClient) -> Result<()> {
|
||||||
for id in args.gpu_ids(client) {
|
for id in args.gpu_ids(client) {
|
||||||
let info_buffer = client.get_device_info(&id)?;
|
let info_buffer = client.get_device_info(&id)?;
|
||||||
let info = info_buffer.inner()?;
|
let info = info_buffer.inner()?;
|
||||||
@@ -8,6 +8,7 @@ default = ["lact-gui"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lact-daemon = { path = "../lact-daemon" }
|
lact-daemon = { path = "../lact-daemon" }
|
||||||
|
lact-cli = { path = "../lact-cli" }
|
||||||
lact-gui = { path = "../lact-gui", optional = true }
|
lact-gui = { path = "../lact-gui", optional = true }
|
||||||
anyhow = "1.0.68"
|
anyhow = "1.0.68"
|
||||||
clap = { version = "4.1.4", features = ["derive"] }
|
clap = { version = "4.1.4", features = ["derive"] }
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use lact_cli::args::CliArgs;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
@@ -12,4 +13,5 @@ pub enum Command {
|
|||||||
Daemon,
|
Daemon,
|
||||||
/// Run the GUI
|
/// Run the GUI
|
||||||
Gui,
|
Gui,
|
||||||
|
Cli(CliArgs),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
match command {
|
match command {
|
||||||
Command::Daemon => lact_daemon::run(),
|
Command::Daemon => lact_daemon::run(),
|
||||||
Command::Gui => run_gui(),
|
Command::Gui => run_gui(),
|
||||||
|
Command::Cli(cli_args) => lact_cli::run(cli_args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user