Skip to content

Commit

Permalink
update cli structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nopestack committed Jan 23, 2024
1 parent e2bc605 commit d33463f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/api/routes/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ where
Ok(data_hash)
}

#[allow(unused)]
fn path_is_valid(path: &Path) -> bool {
let mut components = path.components().peekable();

Expand Down
5 changes: 5 additions & 0 deletions src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ pub async fn exec() -> anyhow::Result<()> {
commands::SubCmd::Serve(args) => {
commands::serve::exec(args).await
}

commands::SubCmd::Call(args) => {
commands::call::exec(args).await
}

_ => {
anyhow::bail!("Not supported yet");
}
Expand Down
28 changes: 28 additions & 0 deletions src/cli/commands/call.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::net::SocketAddr;

use crate::storage::FnId;

#[derive(Debug, clap::Args)]
pub struct CallCmd {
#[clap(long, default_value = "0.0.0.0:3401")]
pub server_addr: SocketAddr,

#[clap(long)]
pub fn_id: FnId,

#[clap(default_value = "")]
pub args: String,
}

pub async fn exec(args: CallCmd) -> anyhow::Result<()> {
let mut api_client = crate::api::client::Client::new()?;
let server_addr = args.server_addr;
let fn_id = args.fn_id;
let fn_args = args.args.as_bytes().to_vec();

let response = api_client.call(server_addr, &fn_id, fn_args).await?;
let response_json = serde_json::to_string_pretty(&response)?;
println!("{}", response_json);

Ok(())
}
14 changes: 1 addition & 13 deletions src/cli/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod call;
pub mod serve;

#[derive(clap::Subcommand, Debug)]
Expand All @@ -24,19 +25,6 @@ pub enum SubCmd {
Config(config::ConfigCmd),
}

mod call {
use std::net::SocketAddr;

use crate::storage::FnId;

#[derive(Debug, clap::Args)]
pub struct CallCmd {
#[clap(long, default_value = "0.0.0.0:3401")]
pub server_addr: SocketAddr,
pub fn_id: FnId,
}
}

mod config {
#[derive(Debug, clap::Args)]
pub struct ConfigCmd {
Expand Down

0 comments on commit d33463f

Please sign in to comment.