From 4dd4ed0a5cf4eeb6af269725288afe23943dc1f1 Mon Sep 17 00:00:00 2001 From: benjamin-stacks <246469650+benjamin-stacks@users.noreply.github.com> Date: Wed, 3 Dec 2025 12:25:05 +0100 Subject: [PATCH] fix(clarity-cli): Make behavior of `eval` without .clar file less confusing Closes #6496. That issue reported that `clarity-eval SPWHATEVER something.clar` hangs forever, but it turns out that that's only half true. What it's in fact doing is waiting for `stdin` input. The Clarity program file name is an optional argument, and if it's not given, the program is read from the standard input instead. In the above example command line, `something.clar` is interpreted as the VM state DB directory instead (which is obviously not the caller's intention). I made three changes: - The usage message now uses the common format where all optional args are wrapped in square brackets and required args are unwrapped: ``` Usage: clarity-cli eval [--costs] [--epoch E] [--clarity_version N] contract-identifier [program.clar] vm-state.db ``` - I also added the info to the help message that without the `program.clar`, things will be read from `stdin`. - And I changed the order of execution so that the contract ID and the VM DBs are handled first, before the program content is loaded. That way, if the user passes a `something.clar` but (incorrectly) leaves off one of the required args, it immediately causes an error, instead of waiting for the program from `stdin` and *then* erroring. I also fixed the VSCode launch settings for clarity-cli. --- .vscode/launch.json | 2 +- contrib/clarity-cli/src/lib.rs | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f645a6c87db..985a6243db8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,7 +27,7 @@ "args": [ "build", "--bin=clarity-cli", - "--package=stackslib" + "--package=clarity-cli" ], "filter": { "name": "clarity-cli", diff --git a/contrib/clarity-cli/src/lib.rs b/contrib/clarity-cli/src/lib.rs index b029bb03bd2..16f3c580894 100644 --- a/contrib/clarity-cli/src/lib.rs +++ b/contrib/clarity-cli/src/lib.rs @@ -790,14 +790,26 @@ impl HeadersDB for CLIHeadersDB { fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput { if args.len() < 3 || args.len() > 4 { eprintln!( - "Usage: {invoked_by} {} [--costs] [--epoch E] [--clarity_version N] [contract-identifier] (program.clar) [vm-state.db]", + "Usage: {invoked_by} {} [--costs] [--epoch E] [--clarity_version N] contract-identifier [program.clar] vm-state.db", args[0] ); + eprintln!(); + eprintln!(" If a program file name is not provided, the program is read from stdin."); panic_test!(); } let vm_filename = if args.len() == 3 { &args[2] } else { &args[3] }; + let contract_identifier = friendly_expect( + QualifiedContractIdentifier::parse(&args[1]), + "Failed to parse contract identifier.", + ); + + let marf_kv = friendly_expect( + MarfedKV::open(vm_filename, None, None), + "Failed to open VM database.", + ); + let content: String = { if args.len() == 3 { let mut buffer = String::new(); @@ -814,16 +826,6 @@ fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput { } }; - let contract_identifier = friendly_expect( - QualifiedContractIdentifier::parse(&args[1]), - "Failed to parse contract identifier.", - ); - - let marf_kv = friendly_expect( - MarfedKV::open(vm_filename, None, None), - "Failed to open VM database.", - ); - // return (marf_kv, contract_identifier, vm_filename, content); EvalInput { marf_kv, contract_identifier,