Sui Move CLI
Sui CLI move 명령은 Move 소스 코드 작업을 위한 여러 명령을 제공한다. sui move 의 일반적인 사용법은 Move 코드를 컴파일하고 테스트하거나, sui move new project_name 사용하여 새 Move 프로젝트를 생성하는 것이다. 이 명령은 필요한 디렉터리와 Move.toml 파일을 생성한다.
Check Sui CLI installation
Before you can use the Sui CLI, you must install it. To check if the CLI exists on your system, open a terminal or console and type the following command:
$ sui --version
If the terminal or console responds with a version number, you already have the Sui CLI installed.
If the command is not found, follow the instructions in Install Sui to get the Sui CLI on your system.
명령
$ sui move --help
Tool to build and test Move applications
Usage: sui move [OPTIONS] <COMMAND>
Commands:
build
coverage Inspect test coverage for this package. A previous test run with the `--coverage`
flag must have previously been run
disassemble
migrate Migrate to Move 2024 for the package at `path`. If no path is provided defaults
to current directory
new Create a new Move package with name `name` at `path`. If `path` is not provided
the package will be created in the directory `name`
test Run Move unit tests in this package
summary Generate a serialized summary of a Move package (e.g., functions, structs,
annotations, etc.)
update-deps Re-pin the dependencies of this package
help Print this message or the help of the given subcommand(s)
Options:
-p, --path <PACKAGE_PATH>
Path to a package which the command should be run with respect to
--client.config <CONFIG>
Sets the file storing the state of our user accounts (an empty one will be created if
missing)
--client.env <ENV>
The Sui environment to use. This must be present in the current config file
-y, --yes
Create a new sui config without prompting if none exists
--test
Compile in 'test' mode and include the code in the 'tests' directory
--doc
Generate documentation for packages
--disassemble
Save disassembly for generated bytecode along with bytecode maps (source maps for
disassembled bytecode)
--install-dir <INSTALL_DIR>
Installation directory for compiled artifacts. Defaults to current directory
--force
Force recompilation of all packages
--allow-dirty
Allow building, even if some cached git dependencies in `~/.move` are modified
--default-move-flavor <DEFAULT_FLAVOR>
Default flavor for move compilation, if not specified in the package's config
--default-move-edition <DEFAULT_EDITION>
Default edition for move compilation, if not specified in the package's config
--silence-warnings
If set, ignore any compiler warnings
--warnings-are-errors
If set, warnings become errors
--json-errors
If set, reports errors at JSON
--no-lint
If `true`, disable linters
-q, --quiet
Display less output
--lint
If `true`, enables extra linters
--mode <MODE>
Arbitrary mode -- this will be used to enable or filter user-defined `#[mode(<MODE>)]`
annotations during compilation
-e, --build-env <ENVIRONMENT>
Environment to use for building packages
--pubfile-path <PUBFILE_PATH>
Path to ephemeral publication file. When provided, uses ephemeral addresses for
compilation instead of addresses from the lock file
-h, --help
Print help
-V, --version
Print version
예시
다음 예제에서는 가장 자주 사용되는 명령 중 일부를 보여준다.
Create a new Move project
Move.toml 파일에 필요한 종속성을 자동으로 추가하는 새로운 Move 프로젝트를 만들려면 sui move new [<PROJECT-NAME>] 를 실행한다.
$ sui move new smart_contract_test
$ ls -l smart_contract_test
Move.toml
Sources
Move.toml 파일의 내용을 표시한다.
$ cat smart_contract_test/Move.toml
[package]
name = "smart_contract_test"
version = "0.0.1"
[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
[addresses]
smart_contract_test = "0x0"
Build a Move project
Move 프로젝트의 루트에서 sui move build 사용하여 패키지를 빌드한다.
$ sui move build
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING smart_contract_test
Run tests in a Move project
sui move test 사용하여 Move 패키지에서 테스트를 실행한다.
$ sui move test
UPDATING GIT DEPENDENCY https://github.com/MystenLabs/sui.git
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING smart_contract_test
Running Move unit tests
Test result: OK. Total tests: 0; passed: 0; failed: 0
Get test coverage for a module
이 명령은 현재 CLI 디버그 빌드에서만 작동한다. 사용하기 위해서는 소스에서 CLI를 빌드하길 바란다.
이 예제에서는 first_package Move 패키지를 사용한다.
테스트 커버리지 요약을 얻으려면 먼저 sui move test --coverage 명령을 실행한 다음, sui move coverage summary --test 실행하여 예제 프로젝트의 테스트 커버리지 요약을 받아야 한다.
$ sui move test --coverage
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING first_package
Running Move unit tests
[ PASS ] 0x0::example::test_module_init
[ PASS ] 0x0::example::test_sword_transactions
Test result: OK. Total tests: 2; passed: 2; failed: 0
$ sui move coverage summary --test
+-------------------------+
| Move Coverage Summary |
+-------------------------+
Module 0000000000000000000000000000000000000000000000000000000000000000::example
>>> % Module coverage: 92.81
+-------------------------+
| % Move Coverage: 92.81 |
+-------------------------+
도움말
각 명령에는 자체 도움말 섹션이 있다. 예를 들어 sui move build --help 입력하면 다음과 같은 프롬프트가 표시된다.
$ sui move build --help
Usage: sui move build [OPTIONS]
Options:
-p, --path <PACKAGE_PATH>
Path to a package which the command should be run with respect to
--with-unpublished-dependencies
Include the contents of packages in dependencies that haven't been published (only
relevant when dumping bytecode as base64)
--dump-bytecode-as-base64
Dump the compiled bytecode as base64-encoded strings in a JSON object, together with the
digest and list of dependencies [aliases: dump]
--no-tree-shaking
By default, the CLI will drop any unused dependencies from the output and makes calls to
the RPC. This flag disables that behavior and avoids any RPC calls, keeping all
dependencies in the output (the dependency list). This is useful for offline compilation.
Only to be used with `--dump-bytecode-as-base64`
--generate-struct-layouts
If true, generate struct layout schemas for all struct types passed into `entry` functions
declared by modules in this package These layout schemas can be consumed by clients (e.g.,
the TypeScript SDK) to enable serialization/deserialization of transaction arguments and
events
--test
Compile in 'test' mode and include the code in the 'tests' directory
--doc
Generate documentation for packages
--disassemble
Save disassembly for generated bytecode along with bytecode maps (source maps for
disassembled bytecode)
--install-dir <INSTALL_DIR>
Installation directory for compiled artifacts. Defaults to current directory
--force
Force recompilation of all packages
--allow-dirty
Allow building, even if some cached git dependencies in `~/.move` are modified
--default-move-flavor <DEFAULT_FLAVOR>
Default flavor for move compilation, if not specified in the package's config
--default-move-edition <DEFAULT_EDITION>
Default edition for move compilation, if not specified in the package's config
--silence-warnings
If set, ignore any compiler warnings
--warnings-are-errors
If set, warnings become errors
--json-errors
If set, reports errors at JSON
--no-lint
If `true`, disable linters
-q, --quiet
Display less output
--lint
If `true`, enables extra linters
--mode <MODE>
Arbitrary mode -- this will be used to enable or filter user-defined `#[mode(<MODE>)]`
annotations during compilation
-e, --build-env <ENVIRONMENT>
Environment to use for building packages
--pubfile-path <PUBFILE_PATH>
Path to ephemeral publication file. When provided, uses ephemeral addresses for
compilation instead of addresses from the lock file
-h, --help
Print help
-V, --version
Print version