Skip to content

Conversation

@simone-stacks
Copy link

Description

Refactors the clarity-cli command-line interface to use clap for argument parsing, replacing the previous manual argument handling.

Applicable issues

Additional info (benefits, drawbacks, caveats)

Benefits:

  • Auto-generated --help output for all commands and subcommands
  • Better error messages for invalid arguments
  • Cleaner, more maintainable argument parsing code

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

❌ Patch coverage is 14.23358% with 235 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.82%. Comparing base (44fdf84) to head (90033c3).

Files with missing lines Patch % Lines
contrib/clarity-cli/src/main.rs 14.23% 235 Missing ⚠️

❌ Your project check has failed because the head coverage (75.82%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6720      +/-   ##
===========================================
+ Coverage    73.67%   75.82%   +2.15%     
===========================================
  Files          577      577              
  Lines       357795   357961     +166     
===========================================
+ Hits        263596   271425    +7829     
+ Misses       94199    86536    -7663     
Files with missing lines Coverage Δ
contrib/clarity-cli/src/lib.rs 80.99% <ø> (+7.75%) ⬆️
contrib/stacks-inspect/src/main.rs 0.00% <ø> (ø)
contrib/clarity-cli/src/main.rs 14.49% <14.23%> (+14.49%) ⬆️

... and 284 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44fdf84...90033c3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@simone-stacks
Copy link
Author

/// Execute program in a transient environment. To be used only by CLI tools
/// for program evaluation, not by consensus critical code.
pub fn vm_execute_in_epoch(
program: &str,
clarity_version: ClarityVersion,
epoch: StacksEpochId,
) -> Result<Option<Value>, VmExecutionError> {
let contract_id = QualifiedContractIdentifier::transient();
let mut contract_context = ContractContext::new(contract_id.clone(), clarity_version);
let mut marf = MemoryBackingStore::new();
let conn = marf.as_clarity_db();
let mut global_context = GlobalContext::new(
false,
default_chain_id(false),
conn,
LimitedCostTracker::new_free(),
epoch,
);
global_context.execute(|g| {
let parsed =
ast::build_ast(&contract_id, program, &mut (), clarity_version, epoch)?.expressions;
eval_all(&parsed, &mut contract_context, g, None)
})
}
/// Execute program in a transient environment in the latest epoch.
/// To be used only by CLI tools for program evaluation, not by consensus
/// critical code.
/// TODO: Unused internally in the cli, but used in other functions - Shall we use vm_execute_in_epoch with StacksEpochId::latest() instead, so we can remove this function?
pub fn vm_execute(
program: &str,
clarity_version: ClarityVersion,
) -> Result<Option<Value>, VmExecutionError> {
let contract_id = QualifiedContractIdentifier::transient();
let mut contract_context = ContractContext::new(contract_id.clone(), clarity_version);
let mut marf = MemoryBackingStore::new();
let conn = marf.as_clarity_db();
let mut global_context = GlobalContext::new(
false,
default_chain_id(false),
conn,
LimitedCostTracker::new_free(),
StacksEpochId::latest(),
);
global_context.execute(|g| {
let parsed = ast::build_ast(
&contract_id,
program,
&mut (),
clarity_version,
StacksEpochId::latest(),
)?
.expressions;
eval_all(&parsed, &mut contract_context, g, None)
})
}

I noticed that vm_execute and vm_execute_in_epoch are basically the same function - with the only difference that vm_execute just hardcodes StacksEpochId::latest().

I think we could either remove vm_execute and update all callers to pass the epoch explicitly, or turn it into a simple wrapper that calls vm_execute_in_epoch with StacksEpochId::latest() parameter.

What do you think? If it makese sense, I'd tackle this in a separate PR.

@simone-stacks simone-stacks marked this pull request as ready for review November 28, 2025 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant