Skip to content

Commit 0aa3e6c

Browse files
authored
Add design doc for new declare/script interface (#1485)
<!-- Reference any GitHub issues resolved by this PR --> ## Introduced changes <!-- A brief description of the changes --> - Opens up a discussion about sncast declare/script interfaces, first raised under this PR #1093 ## Checklist <!-- Make sure all of these are complete --> - [X] Linked relevant issue - [X] Updated relevant documentation - [X] Added relevant tests - [X] Performed self-review of the code - [X] Added changes to `CHANGELOG.md`
1 parent 7747a2d commit 0aa3e6c

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# sncast interface overhaul
2+
3+
## Context
4+
In light of needed changes on how the scripts and contract declaration work (ie adding support for scarb workspaces and various directory layouts),
5+
we need to re-think how we call the respective subcommands, and try to improve it. This design doc covers only a portion
6+
(although significant one) of sncast interface - it was decided recently we should make the interfaces as 'clap-native'
7+
as possible, but this design doc won't cover those changes in detail, as they are pretty straight forward and already have
8+
an opened issue.
9+
10+
## The 'now'
11+
Currently, when declaring a contract we require user to pass the contract name using `--contract-name` flag. This flag only
12+
takes the contract's name, so for example it is not possible to specify the package this contract was defined in (only
13+
achievable when passing `--path-to-scarb-toml`).
14+
15+
When running a script we require a positional argument, that is the script package name. Similarly to declare, we could
16+
pass `--path-to-scarb-toml` if we wanted to pick the manifest we wanted to use.
17+
18+
These approaches are a bit different to each other, and have a common flaw in the shape of having to specify a manifest
19+
file one wants to work with, when the package needs to be specified. This may seem quite quirky, as we probably could
20+
assume that we're always in some workspace/package.
21+
22+
## Proposed changes
23+
We could streamline the way we interact with scarb-related subcommands (declare, script at the moment of writing this)
24+
to look like this:
25+
26+
```bash
27+
$ # this is the same module
28+
$ sncast script path::to::script_module
29+
$ sncast script to::script_module
30+
$ sncast script script_module
31+
32+
$ # this is the same contract
33+
$ sncast declare path::to::contract
34+
$ sncast declare to::contract
35+
$ sncast declare contract
36+
37+
$ # contract is ambiguous - there are multiple contracts named 'contract' in multiple packages
38+
$ sncast declare --package packagea contract
39+
```
40+
41+
In case there is only one script module/contract with specified name in workspace, only this name can be used to target it.
42+
Otherwise, if it is ambiguous in the context of workspace, we should show all matches with full paths (along with package names),
43+
to let user decide which one to use.
44+
45+
This change would mean that from now on we will have unified interface for declare/script, always assume we're in some workspace/package,
46+
the `--path-to-scarb-toml` flag can be removed.
47+
48+
## Implementation
49+
As much things as possible should be imported from scarb-api crate. The mechanism for path matching should take under
50+
account whole words between `::`, so (having examples above in mind) `contract` should be matched, but `tract` shouldn't.

0 commit comments

Comments
 (0)