Skip to content

Commit fc0ca0f

Browse files
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.
1 parent 67f1283 commit fc0ca0f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"args": [
2828
"build",
2929
"--bin=clarity-cli",
30-
"--package=stackslib"
30+
"--package=clarity-cli"
3131
],
3232
"filter": {
3333
"name": "clarity-cli",

contrib/clarity-cli/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,26 @@ impl HeadersDB for CLIHeadersDB {
790790
fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput {
791791
if args.len() < 3 || args.len() > 4 {
792792
eprintln!(
793-
"Usage: {invoked_by} {} [--costs] [--epoch E] [--clarity_version N] [contract-identifier] (program.clar) [vm-state.db]",
793+
"Usage: {invoked_by} {} [--costs] [--epoch E] [--clarity_version N] contract-identifier [program.clar] vm-state.db",
794794
args[0]
795795
);
796+
eprintln!();
797+
eprintln!(" If a program file name is not provided, the program is read from stdin.");
796798
panic_test!();
797799
}
798800

799801
let vm_filename = if args.len() == 3 { &args[2] } else { &args[3] };
800802

803+
let contract_identifier = friendly_expect(
804+
QualifiedContractIdentifier::parse(&args[1]),
805+
"Failed to parse contract identifier.",
806+
);
807+
808+
let marf_kv = friendly_expect(
809+
MarfedKV::open(vm_filename, None, None),
810+
"Failed to open VM database.",
811+
);
812+
801813
let content: String = {
802814
if args.len() == 3 {
803815
let mut buffer = String::new();
@@ -814,16 +826,6 @@ fn get_eval_input(invoked_by: &str, args: &[String]) -> EvalInput {
814826
}
815827
};
816828

817-
let contract_identifier = friendly_expect(
818-
QualifiedContractIdentifier::parse(&args[1]),
819-
"Failed to parse contract identifier.",
820-
);
821-
822-
let marf_kv = friendly_expect(
823-
MarfedKV::open(vm_filename, None, None),
824-
"Failed to open VM database.",
825-
);
826-
// return (marf_kv, contract_identifier, vm_filename, content);
827829
EvalInput {
828830
marf_kv,
829831
contract_identifier,

0 commit comments

Comments
 (0)