forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CLI/PTB] Check for help flags after lexing (MystenLabs#16435)
## Description Make help flag detection more robust by doing it after tokenisation, so that the help flag is treated consistently like other `--commands` or `-f`lags. This PR also introduces a new notion of a `-f`lag to the lexer (which is only used for `-h` at the moment). ## Test Plan New unit tests: ``` crates/sui$ cargo nextest run -- lexer ``` Trying the command: ``` sui$ cargo run --bin sui -- --help sui$ cargo run --bin sui -- -h ```
- Loading branch information
Showing
7 changed files
with
176 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
crates/sui/src/client_ptb/snapshots/sui__client_ptb__lexer__tests__tokenize_commands.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
source: crates/sui/src/client_ptb/lexer.rs | ||
expression: lex(cmds) | ||
--- | ||
[ | ||
Spanned { | ||
span: Span { | ||
start: 0, | ||
end: 5, | ||
}, | ||
value: Lexeme( | ||
Command, | ||
"f00", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 6, | ||
end: 15, | ||
}, | ||
value: Lexeme( | ||
Command, | ||
"Bar_baz", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 16, | ||
end: 25, | ||
}, | ||
value: Lexeme( | ||
Command, | ||
"qux-quy", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 25, | ||
end: 25, | ||
}, | ||
value: Lexeme( | ||
Eof, | ||
"", | ||
), | ||
}, | ||
] |
56 changes: 56 additions & 0 deletions
56
crates/sui/src/client_ptb/snapshots/sui__client_ptb__lexer__tests__tokenize_flags.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
source: crates/sui/src/client_ptb/lexer.rs | ||
expression: lex(flags) | ||
--- | ||
[ | ||
Spanned { | ||
span: Span { | ||
start: 0, | ||
end: 2, | ||
}, | ||
value: Lexeme( | ||
Flag, | ||
"h", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 3, | ||
end: 5, | ||
}, | ||
value: Lexeme( | ||
Flag, | ||
"a", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 6, | ||
end: 8, | ||
}, | ||
value: Lexeme( | ||
Flag, | ||
"Z", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 9, | ||
end: 11, | ||
}, | ||
value: Lexeme( | ||
Flag, | ||
"1", | ||
), | ||
}, | ||
Spanned { | ||
span: Span { | ||
start: 11, | ||
end: 11, | ||
}, | ||
value: Lexeme( | ||
Eof, | ||
"", | ||
), | ||
}, | ||
] |
6 changes: 3 additions & 3 deletions
6
crates/sui/src/client_ptb/snapshots/sui__client_ptb__lexer__tests__unexpected_dash_dash.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
--- | ||
source: crates/sui/src/client_ptb/lexer.rs | ||
expression: tokens | ||
expression: lex(unexpected) | ||
--- | ||
[ | ||
Spanned { | ||
span: Span { | ||
start: 0, | ||
end: 2, | ||
end: 1, | ||
}, | ||
value: Lexeme( | ||
Unexpected, | ||
"--", | ||
"-", | ||
), | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters