Skip to content

Commit 90920ec

Browse files
authored
Merge pull request #175 from rage/client-flags
moved client-name and client-version to top level
2 parents afba55b + 29e4a42 commit 90920ec

File tree

2 files changed

+97
-91
lines changed

2 files changed

+97
-91
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ pub struct Opt {
2929
/// Pretty-prints all output
3030
#[structopt(long)]
3131
pub pretty: bool,
32+
/// Name used to differentiate between different TMC clients.
33+
#[structopt(long)]
34+
pub client_name: Option<String>,
35+
/// Client version.
36+
#[structopt(long)]
37+
pub client_version: Option<String>,
3238
#[structopt(subcommand)]
3339
pub cmd: Command,
3440
}
@@ -114,9 +120,6 @@ pub enum Command {
114120
/// Returns a list of local exercises for the given course
115121
#[structopt(long_about = schema_leaked::<Vec<LocalExercise>>())]
116122
ListLocalCourseExercises {
117-
/// The client for which exercises should be listed.
118-
#[structopt(long)]
119-
client_name: String,
120123
/// The course slug the local exercises of which should be listed.
121124
#[structopt(long)]
122125
course_slug: String,
@@ -209,7 +212,7 @@ pub enum Command {
209212
wait_for_secret: bool,
210213
},
211214

212-
Settings(SettingsCommand),
215+
Settings(Settings),
213216

214217
/// Produces a description of an exercise using the appropriate language plugin
215218
#[structopt(long_about = schema_leaked::<ExerciseDesc>())]
@@ -223,22 +226,10 @@ pub enum Command {
223226
},
224227
}
225228

226-
#[derive(StructOpt)]
227229
/// Various commands that communicate with the TMC server
228-
pub struct Core {
229-
/// Name used to differentiate between different TMC clients.
230-
#[structopt(long)]
231-
pub client_name: String,
232-
/// Client version.
233-
#[structopt(long)]
234-
pub client_version: String,
235-
#[structopt(subcommand)]
236-
pub command: CoreCommand,
237-
}
238-
239230
#[derive(StructOpt)]
240231
#[structopt(setting = AppSettings::SubcommandRequiredElseHelp)]
241-
pub enum CoreCommand {
232+
pub enum Core {
242233
/// Checks for updates to any exercises that exist locally.
243234
#[structopt(long_about = schema_leaked::<Vec<UpdatedExercise>>())]
244235
CheckExerciseUpdates,
@@ -494,19 +485,10 @@ pub enum CoreCommand {
494485
},
495486
}
496487

497-
#[derive(StructOpt)]
498488
/// Configure the CLI
499-
pub struct SettingsCommand {
500-
/// The name of the client.
501-
#[structopt(long)]
502-
pub client_name: String,
503-
#[structopt(subcommand)]
504-
pub command: SettingsSubCommand,
505-
}
506-
507489
#[derive(StructOpt)]
508490
#[structopt(setting = AppSettings::SubcommandRequiredElseHelp)]
509-
pub enum SettingsSubCommand {
491+
pub enum Settings {
510492
/// Retrieves a value from the settings
511493
Get {
512494
/// The name of the setting.
@@ -610,7 +592,18 @@ mod base_test {
610592
use super::*;
611593

612594
fn get_matches(args: &[&str]) {
613-
Opt::from_iter(&["tmc-langs-cli"].iter().chain(args).collect::<Vec<_>>());
595+
Opt::from_iter(
596+
&[
597+
"tmc-langs-cli",
598+
"--client-name",
599+
"client",
600+
"--client-version",
601+
"version",
602+
]
603+
.iter()
604+
.chain(args)
605+
.collect::<Vec<_>>(),
606+
);
614607
}
615608

616609
#[test]
@@ -696,13 +689,7 @@ mod base_test {
696689

697690
#[test]
698691
fn list_local_course_exercises() {
699-
get_matches(&[
700-
"list-local-course-exercises",
701-
"--client-name",
702-
"client",
703-
"--course-slug",
704-
"slug",
705-
]);
692+
get_matches(&["list-local-course-exercises", "--course-slug", "slug"]);
706693
}
707694

708695
#[test]
@@ -800,11 +787,11 @@ mod core_test {
800787
Opt::from_iter(
801788
&[
802789
"tmc-langs-cli",
803-
"core",
804790
"--client-name",
805791
"client",
806792
"--client-version",
807793
"version",
794+
"core",
808795
]
809796
.iter()
810797
.chain(args)
@@ -1042,7 +1029,7 @@ mod settings_test {
10421029

10431030
fn get_matches_settings(args: &[&str]) {
10441031
Opt::from_iter(
1045-
&["tmc-langs-cli", "settings", "--client-name", "client"]
1032+
&["tmc-langs-cli", "--client-name", "client", "settings"]
10461033
.iter()
10471034
.chain(args)
10481035
.collect::<Vec<_>>(),

0 commit comments

Comments
 (0)