Skip to content

Commit 1a84e94

Browse files
author
saying121
committed
refactor(cli): commands
1 parent 2e2c456 commit 1a84e94

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

.github/workflows/release.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ jobs:
3434
tool: cargo-binstall
3535

3636
- name: Install cargo-release
37-
run: cargo binstall cargo-release -y
37+
run: cargo binstall -y cargo-release
3838

3939
- name: Install Dbus
4040
run: sudo apt update && sudo apt install libdbus-1-dev pkg-config
4141

4242
- name: Publish crate
4343
env:
4444
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
45-
run:
46-
cargo release publish --allow-branch HEAD --no-confirm --workspace -x || echo "No crates publish."
45+
run: |
46+
cargo release publish \
47+
--allow-branch HEAD \
48+
--no-confirm \
49+
--workspace -x || echo "No crates publish."
4750
4851
create-release:
4952
# needs: [publish]

completions/_lcode

+14-14
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ _lcode() {
3333
_arguments "${_arguments_options[@]}" \
3434
'-h[Print help]' \
3535
'--help[Print help]' \
36-
':input -- Question id:' \
36+
':id -- Question id:' \
3737
":: :_lcode__edit_commands" \
3838
"*::: :->edit" \
3939
&& ret=0
@@ -48,14 +48,14 @@ _arguments "${_arguments_options[@]}" \
4848
_arguments "${_arguments_options[@]}" \
4949
'-h[Print help]' \
5050
'--help[Print help]' \
51-
':input -- Question id:' \
51+
':id -- Question id:' \
5252
&& ret=0
5353
;;
5454
(test)
5555
_arguments "${_arguments_options[@]}" \
5656
'-h[Print help]' \
5757
'--help[Print help]' \
58-
':input -- Question id:' \
58+
':id -- Question id:' \
5959
&& ret=0
6060
;;
6161
(help)
@@ -156,7 +156,7 @@ _arguments "${_arguments_options[@]}" \
156156
'--force[Force update question'\''s information]' \
157157
'-h[Print help]' \
158158
'--help[Print help]' \
159-
':id -- Force update question'\''s information:' \
159+
':id -- Question id:' \
160160
&& ret=0
161161
;;
162162
(sync)
@@ -171,27 +171,27 @@ _arguments "${_arguments_options[@]}" \
171171
_arguments "${_arguments_options[@]}" \
172172
'-h[Print help]' \
173173
'--help[Print help]' \
174-
':id:' \
174+
':id -- Question id:' \
175175
&& ret=0
176176
;;
177177
(submit)
178178
_arguments "${_arguments_options[@]}" \
179179
'-h[Print help]' \
180180
'--help[Print help]' \
181-
':id:' \
181+
':id -- Question id:' \
182182
&& ret=0
183183
;;
184184
(sublist)
185185
_arguments "${_arguments_options[@]}" \
186186
'-h[Print help]' \
187187
'--help[Print help]' \
188-
':id:' \
188+
':id -- Question id:' \
189189
&& ret=0
190190
;;
191191
(gencon)
192192
_arguments "${_arguments_options[@]}" \
193-
'-c[]' \
194-
'--cn[]' \
193+
'-c[Generate cn config]' \
194+
'--cn[Generate cn config]' \
195195
'-h[Print help]' \
196196
'--help[Print help]' \
197197
&& ret=0
@@ -336,7 +336,7 @@ esac
336336
(( $+functions[_lcode_commands] )) ||
337337
_lcode_commands() {
338338
local commands; commands=(
339-
'edit:Edit \`code\` or \`test cases\`, default edit \`code\` \[ alias\: e \]' \
339+
'edit:Edit \`code\` or \`test cases\`, \[ alias\: e \]' \
340340
'fzy:Interact select a question (fuzzy search), default view detail \[ alias\: f \]' \
341341
'detail:View a question detail \[ alias\: D \]' \
342342
'sync:Syncanhronize leetcode info \[ alias\: S \]' \
@@ -437,7 +437,7 @@ _lcode__help__fzy__edit_commands() {
437437
(( $+functions[_lcode__fzy_commands] )) ||
438438
_lcode__fzy_commands() {
439439
local commands; commands=(
440-
'detail:View detail' \
440+
'detail:View detail(default)' \
441441
'edit:Edit code' \
442442
'help:Print this message or the help of the given subcommand(s)' \
443443
)
@@ -446,7 +446,7 @@ _lcode__fzy_commands() {
446446
(( $+functions[_lcode__help__fzy_commands] )) ||
447447
_lcode__help__fzy_commands() {
448448
local commands; commands=(
449-
'detail:View detail' \
449+
'detail:View detail(default)' \
450450
'edit:Edit code' \
451451
)
452452
_describe -t commands 'lcode help fzy commands' commands "$@"
@@ -478,7 +478,7 @@ _lcode__edit__help__help_commands() {
478478
(( $+functions[_lcode__fzy__help_commands] )) ||
479479
_lcode__fzy__help_commands() {
480480
local commands; commands=(
481-
'detail:View detail' \
481+
'detail:View detail(default)' \
482482
'edit:Edit code' \
483483
'help:Print this message or the help of the given subcommand(s)' \
484484
)
@@ -492,7 +492,7 @@ _lcode__fzy__help__help_commands() {
492492
(( $+functions[_lcode__help_commands] )) ||
493493
_lcode__help_commands() {
494494
local commands; commands=(
495-
'edit:Edit \`code\` or \`test cases\`, default edit \`code\` \[ alias\: e \]' \
495+
'edit:Edit \`code\` or \`test cases\`, \[ alias\: e \]' \
496496
'fzy:Interact select a question (fuzzy search), default view detail \[ alias\: f \]' \
497497
'detail:View a question detail \[ alias\: D \]' \
498498
'sync:Syncanhronize leetcode info \[ alias\: S \]' \

crates/lcode/src/cli.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
3333
enum Commands {
3434
#[command(
3535
alias = "e",
36-
about = format!("Edit `{cd}` or `{ts}`, default edit `{cd}` {alias}",
36+
about = format!("Edit `{cd}` or `{ts}`, {alias}",
3737
cd = "code".bold(),
3838
ts = "test cases".bold(),
3939
alias = "[ alias: e ]".bold()
@@ -51,11 +51,11 @@ enum Commands {
5151
#[command(alias = "S", about = format!("Syncanhronize leetcode info {}","[ alias: S ]".bold()))]
5252
Sync(Force),
5353
#[command(alias = "t", about = format!("Test your code {}", "[ alias: t ]".bold()))]
54-
Test(SubTestArgs),
54+
Test(IdArg),
5555
#[command(alias = "st", about = format!("Submit your code {}", "[ alias: st ]".bold()))]
56-
Submit(SubTestArgs),
56+
Submit(IdArg),
5757
#[command(alias = "sl", about = format!("Get submit list {}", "[ alias: sl ]".bold()))]
58-
Sublist(SubTestArgs),
58+
Sublist(IdArg),
5959
#[command(alias = "g", about = format!("Generate a config {}", "[ alias: g ]".bold()))]
6060
Gencon(GenArgs),
6161
#[command(alias = "T", about = format!("Open Tui {}", "[ alias: T ]".bold()))]
@@ -72,14 +72,15 @@ enum Commands {
7272
#[derive(Args)]
7373
#[command(args_conflicts_with_subcommands = true)]
7474
struct GenArgs {
75-
#[arg(short, long)]
75+
#[arg(short, long, help = "Generate cn config")]
7676
cn: bool,
7777
}
7878

7979
#[derive(Debug)]
8080
#[derive(Args)]
8181
#[command(args_conflicts_with_subcommands = true)]
82-
struct SubTestArgs {
82+
struct IdArg {
83+
#[arg(help = "Question id")]
8384
id: u32,
8485
}
8586

@@ -94,7 +95,7 @@ struct InterArgs {
9495
#[derive(Debug)]
9596
#[derive(Subcommand)]
9697
enum DetailOrEdit {
97-
#[command(about = "View detail")]
98+
#[command(about = "View detail(default)")]
9899
Detail(DetailArgsFzy),
99100
#[command(about = "Edit code")]
100101
Edit,
@@ -111,7 +112,7 @@ struct DetailArgsFzy {
111112
#[derive(Args)]
112113
#[command(args_conflicts_with_subcommands = true)]
113114
struct DetailArgs {
114-
#[arg(help = "Force update question's information")]
115+
#[arg(help = "Question id")]
115116
id: u32,
116117
#[arg(short, long, help = "Force update question's information")]
117118
force: bool,
@@ -132,25 +133,17 @@ struct EditArgs {
132133
#[command(subcommand)]
133134
command: Option<CoT>,
134135

135-
#[command(flatten, help = "Id of the be edited question, default edit it")]
136-
id: Option<EditCodeArgs>,
136+
#[command(flatten, help = "Id of the be edited question")]
137+
id: Option<IdArg>,
137138
}
138139

139140
#[derive(Debug)]
140141
#[derive(Subcommand)]
141142
enum CoT {
142143
#[command(about = "Edit code(default)")]
143-
Code(EditCodeArgs),
144+
Code(IdArg),
144145
#[command(about = "Edit test case")]
145-
Test(EditCodeArgs),
146-
}
147-
148-
#[derive(Debug)]
149-
#[derive(Args)]
150-
#[command(args_conflicts_with_subcommands = true)]
151-
struct EditCodeArgs {
152-
#[arg(help = "Question id")]
153-
input: u32,
146+
Test(IdArg),
154147
}
155148

156149
/// Cli runner
@@ -211,11 +204,11 @@ pub async fn run() -> Result<()> {
211204
},
212205
Commands::Edit(args) => match args.command {
213206
Some(cmd) => match cmd {
214-
CoT::Code(id) => Editor::open(IdSlug::Id(id.input), CodeTestFile::Code).await?,
215-
CoT::Test(id) => Editor::open(IdSlug::Id(id.input), CodeTestFile::Test).await?,
207+
CoT::Code(id) => Editor::open(IdSlug::Id(id.id), CodeTestFile::Code).await?,
208+
CoT::Test(id) => Editor::open(IdSlug::Id(id.id), CodeTestFile::Test).await?,
216209
},
217210
None => match args.id {
218-
Some(id) => Editor::open(IdSlug::Id(id.input), CodeTestFile::Code).await?,
211+
Some(id) => Editor::open(IdSlug::Id(id.id), CodeTestFile::Code).await?,
219212
None => println!("please give info"),
220213
},
221214
},

0 commit comments

Comments
 (0)