Skip to content

Commit a843023

Browse files
authored
chore: update CLI options (#350)
* `invoke-function`: By default, output only the invoked function's response. If `--verbose` is specified, also output details of the function call * `invoke`/`put`/`list` function(s): Make `--cache-name` optional. Default to `~/.momento/config`'s cache name
1 parent 3b4ab44 commit a843023

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

momento-cli-opts/src/lib.rs

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,34 @@ pub enum AccountCommand {
126126
pub enum FunctionCommand {
127127
#[command(about = "Create or update a Momento Function")]
128128
PutFunction {
129-
#[arg(long = "cache-name", short, help = "Cache namespace")]
130-
cache_name: String,
131-
#[arg(long = "name", short, help = "Function name")]
129+
#[arg(
130+
long = "cache-name",
131+
short,
132+
help = "Cache namespace",
133+
value_name = "CACHE"
134+
)]
135+
cache_name: Option<String>,
136+
#[arg(long = "name", short, help = "Function name", value_name = "FUNCTION")]
132137
name: String,
133138
#[arg(
134139
long = "wasm-file",
135140
short,
136-
help = ".wasm file compiled with wasm32-wasip2"
141+
help = ".wasm file compiled with wasm32-wasip2",
142+
value_name = "WASM"
137143
)]
138144
wasm_file: Option<String>,
139145
#[arg(
140146
long = "id-uploaded-wasm",
141147
short,
142-
help = "ID of a Wasm binary previously uploaded to Momento Functions"
148+
help = "ID of a Wasm binary previously uploaded to Momento Functions",
149+
value_name = "WASM"
143150
)]
144151
id_uploaded_wasm: Option<String>,
145152
#[arg(
146153
long = "version-uploaded-wasm",
147154
short,
148-
help = "Version number of a Wasm binary previously uploaded to Momento Functions"
155+
help = "Version number of a Wasm binary previously uploaded to Momento Functions",
156+
value_name = "WASM"
149157
)]
150158
version_uploaded_wasm: Option<u32>,
151159
#[arg(long = "description", short, help = "Description")]
@@ -154,7 +162,8 @@ pub enum FunctionCommand {
154162
long = "env-var",
155163
short = 'E',
156164
value_parser = parse_env::<String, String>,
157-
help = "Environment variables to provide to the Function. Example: -E KEY1=value_1 -E KEY2=value_2"
165+
help = "Environment variables to provide to the Function. Example: -E KEY1=value_1 -E KEY2=value_2",
166+
value_name = "WASM"
158167
)]
159168
environment_variables: Vec<(String, String)>,
160169
},
@@ -165,25 +174,36 @@ pub enum FunctionCommand {
165174
#[arg(
166175
long = "wasm-file",
167176
short,
168-
help = ".wasm file compiled with wasm32-wasip2"
177+
help = ".wasm file compiled with wasm32-wasip2",
178+
value_name = "WASM"
169179
)]
170180
wasm_file: String,
171181
#[arg(long = "description", short, help = "Description")]
172182
description: Option<String>,
173183
},
174184
#[command(about = "Call a Momento Function")]
175185
InvokeFunction {
176-
#[arg(long = "cache-name", short, help = "Cache namespace")]
177-
cache_name: String,
178-
#[arg(long = "name", short, help = "Function name")]
186+
#[arg(
187+
long = "cache-name",
188+
short,
189+
help = "Cache namespace",
190+
value_name = "CACHE"
191+
)]
192+
cache_name: Option<String>,
193+
#[arg(long = "name", short, help = "Function name", value_name = "FUNCTION")]
179194
name: String,
180195
#[arg(long = "data", short, help = "HTTP POST payload body")]
181196
data: Option<String>,
182197
},
183198
#[command(about = "List all Momento Functions in the given cache namespace")]
184199
ListFunctions {
185-
#[arg(long = "cache-name", short, help = "Cache namespace")]
186-
cache_name: String,
200+
#[arg(
201+
long = "cache-name",
202+
short,
203+
help = "Cache namespace",
204+
value_name = "CACHE"
205+
)]
206+
cache_name: Option<String>,
187207
},
188208
#[command(about = "List all versions of a Momento Function")]
189209
ListFunctionVersions {

momento/src/commands/functions/function_cli.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::{
1010
commands::functions::utils::read_wasm_file, error::CliError, utils::console::console_data,
1111
};
1212

13+
use log::info;
1314
use reqwest;
1415
use reqwest::StatusCode;
1516
use serde::Deserialize;
@@ -52,9 +53,9 @@ pub async fn invoke_function(
5253
let data = data.unwrap_or_default();
5354
let function_info = format!("Name: {name}, Cache Namespace: {cache_name}");
5455
if data.is_empty() {
55-
console_data!("Invoking function. {function_info}");
56+
info!("Invoking function. {function_info}");
5657
} else {
57-
console_data!("Sending data to function. {function_info}, Payload: {data}");
58+
info!("Sending data to function. {function_info}, Payload: {data}");
5859
};
5960

6061
let request_url = format!("{endpoint}/functions/{cache_name}/{name}");
@@ -67,7 +68,7 @@ pub async fn invoke_function(
6768
.await?;
6869
let status = response.status();
6970
if status.is_success() {
70-
console_data!(" Response:\n{}", response.text().await?);
71+
console_data!("{}", response.text().await?);
7172
Ok(())
7273
} else {
7374
Err(CliError {

momento/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ async fn run_momento_command(args: momento_cli_opts::Momento) -> Result<(), CliE
228228
.await?;
229229
}
230230
PreviewCommand::Function { operation } => {
231-
let (creds, _) = get_creds_and_config(&args.profile).await?;
231+
let (creds, config) = get_creds_and_config(&args.profile).await?;
232232
let credential_provider = creds.authenticate()?;
233233
let endpoint = credential_provider.cache_http_endpoint().to_string();
234234
let auth_token = credential_provider.auth_token().to_string();
@@ -247,6 +247,7 @@ async fn run_momento_command(args: momento_cli_opts::Momento) -> Result<(), CliE
247247
description,
248248
environment_variables,
249249
} => {
250+
let cache_name = cache_name.unwrap_or(config.cache);
250251
let wasm_source = determine_wasm_source(
251252
wasm_file,
252253
id_uploaded_wasm,
@@ -280,12 +281,14 @@ async fn run_momento_command(args: momento_cli_opts::Momento) -> Result<(), CliE
280281
name,
281282
data,
282283
} => {
284+
let cache_name = cache_name.unwrap_or(config.cache);
283285
commands::functions::function_cli::invoke_function(
284286
endpoint, auth_token, cache_name, name, data,
285287
)
286288
.await?
287289
}
288290
momento_cli_opts::FunctionCommand::ListFunctions { cache_name } => {
291+
let cache_name = cache_name.unwrap_or(config.cache);
289292
commands::functions::function_cli::list_functions(client, cache_name)
290293
.await?
291294
}

0 commit comments

Comments
 (0)