Add REPL commands to print contract constants, data variables, and map entries #1845
+294
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the feature request in issue #1722, enhancing the Clarinet REPL with new commands to inspect contract state directly from the console.
Description
This PR introduces three new commands to the Clarinet REPL:
::print-constant [<contract-identifier>.]<constant-name>
: Displays the value of a defined constant within a specified contract. If the contract identifier is omitted, it defaults to the current contract context.::print-data-var [<contract-identifier>.]<var-name>
: Displays the value of a data variable within a specified contract. If the contract identifier is omitted, it defaults to the current contract context.::print-map-val [<contract-identifier>.]<map-name> <key-expression>
: Evaluates the<key-expression>
and displays the value of the corresponding entry in the specified map. If the contract identifier is omitted, it defaults to the current contract context.These commands provide developers with a more convenient way to query and verify contract state during interactive development and debugging sessions in the Clarinet console.
The implementation involves:
repl/session.rs
to recognize the new commands.Session
struct to parse arguments, retrieve data from the Clarity VM (constants from AST, vars and map entries from VM state), and format the output.::print-map-val
command uses the existingeval()
mechanism to safely evaluate the provided key expression.::help
command output to include documentation for these new commands.Breaking change?
No breaking changes are introduced by this PR.
Checklist