Skip to content

Commit 0cd4ebe

Browse files
committed
refactor: move the lang argument to the command file
1 parent e93ed08 commit 0cd4ebe

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

src/cmd/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ pub fn make_subcommand() -> Command {
1111
.arg_dest_dir()
1212
.arg_root_dir()
1313
.arg_open()
14-
.arg(Arg::new("language").short('l').long("language").num_args(1).value_parser(clap::value_parser!(String)).help("Language to render the compiled book in.{n}\
15-
Only valid if the [language] table in the config is not empty.{n}\
16-
If omitted, builds all translations and provides a menu in the generated output for switching between them."))
14+
.arg_language()
1715
}
1816

1917
// Build command implementation

src/cmd/clean.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ pub fn make_subcommand() -> Command {
1111
.about("Deletes a built book")
1212
.arg_dest_dir()
1313
.arg_root_dir()
14-
.arg(Arg::new("language").short('l').long("language").num_args(1).value_parser(clap::value_parser!(String)).help("Language to render the compiled book in.{n}\
15-
Only valid if the [language] table in the config is not empty.{n}\
16-
If omitted, builds all translations and provides a menu in the generated output for switching between them."))
14+
.arg_language()
1715
}
1816

1917
// Clean command implementation

src/cmd/command_prelude.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ pub trait CommandExt: Sized {
3636
fn arg_open(self) -> Self {
3737
self._arg(arg!(-o --open "Opens the compiled book in a web browser"))
3838
}
39+
40+
fn arg_language(self) -> Self {
41+
self._arg(
42+
Arg::new("language")
43+
.short('l')
44+
.long("language")
45+
.num_args(1)
46+
.value_parser(clap::value_parser!(String))
47+
.help("Language to render the compiled book in.{n}\
48+
Only valid if the [language] table in the config is not empty.{n}\
49+
If omitted, builds all translations and provides a menu in the generated output for switching between them.")
50+
)
51+
}
3952
}
4053

4154
impl CommandExt for Command {

src/cmd/serve.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ pub fn make_subcommand() -> Command {
4444
.help("Port to use for HTTP connections"),
4545
)
4646
.arg_open()
47-
.arg(Arg::new("language").short('l').long("language").num_args(1).value_parser(clap::value_parser!(String)).help("Language to render the compiled book in.{n}\
48-
Only valid if the [language] table in the config is not empty.{n}\
49-
If omitted, builds all translations and provides a menu in the generated output for switching between them."))
47+
.arg_language()
5048
}
5149

5250
// Serve command implementation

src/cmd/test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ pub fn make_subcommand() -> Command {
3232
search path when building tests",
3333
),
3434
)
35-
.arg(arg!(-l --language "Language to render the compiled book in.{n}\
36-
Only valid if the [language] table in the config is not empty.{n}\
37-
If omitted, builds all translations and provides a menu in the generated output for switching between them."))
35+
.arg_language()
3836
}
3937

4038
// test command implementation

src/cmd/watch.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ pub fn make_subcommand() -> Command {
1717
.arg_dest_dir()
1818
.arg_root_dir()
1919
.arg_open()
20-
.arg(arg!(
21-
-l --language "Language to render the compiled book in.{n}\
22-
Only valid if the [language] table in the config is not empty.{n}\
23-
If omitted, builds all translations and provides a menu in the generated output for switching between them.")
24-
)
20+
.arg_language()
2521
}
2622

2723
// Watch command implementation

0 commit comments

Comments
 (0)