Skip to content

Commit

Permalink
[CLI] Add a check for the validity of the argument <NAME> in `sui mov…
Browse files Browse the repository at this point in the history
…e new` (#17568)

CLI] Add a check for the validity of the argument <NAME> in `sui move
new`

## Description 

Describe the changes or additions included in this PR.

- **Before modification**
```
$ sui_1.25.0-879421a5ac5f move new 1/
No such file or directory (os error 2)

$ sui_1.25.0-879421a5ac5f move new 1/2
No such file or directory (os error 2)
```

- **After modification**
```
$ ./target/release/sui move new 1/
only package name is allowed, cannot be a path

$ ./target/release/sui move new 1/2
only package name is allowed, cannot be a path
```

<img width="359" alt="image"
src="https://github.com/MystenLabs/sui/assets/96097578/4526e850-178d-432c-bddf-5b4bed4972ea">


## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: 
- [ ] Rust SDK:

---------

Co-authored-by: bityoume <[email protected]>
Co-authored-by: Ashok Menon <[email protected]>
  • Loading branch information
3 people authored May 18, 2024
1 parent 1a51faa commit 478c0d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion external-crates/move/crates/move-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ name = "build_testsuite"
harness = false

[features]
tiered-gas = [ "move-vm-test-utils/tiered-gas" ]
tiered-gas = ["move-vm-test-utils/tiered-gas"]
10 changes: 10 additions & 0 deletions external-crates/move/crates/move-cli/src/base/new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright (c) The Move Contributors
// SPDX-License-Identifier: Apache-2.0

use anyhow::anyhow;
use clap::*;
use move_core_types::identifier::Identifier;
use move_package::source_package::layout::SourcePackageLayout;
use std::{
fmt::Display,
Expand Down Expand Up @@ -47,6 +49,14 @@ impl New {
) -> anyhow::Result<()> {
// TODO warn on build config flags
let Self { name } = self;

if !Identifier::is_valid(&name) {
return Err(anyhow!(
"Invalid package name, please use lowercase letters, numbers, and underscores, \
should start with a lowercase letter"
));
}

let p: PathBuf;
let path: &Path = match path {
Some(path) => {
Expand Down

0 comments on commit 478c0d0

Please sign in to comment.