Skip to content

Commit ded7e33

Browse files
committed
make locale optional for all commands that access the API
1 parent 99174b1 commit ded7e33

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

tmc-langs-cli/src/main.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,12 @@ fn run() -> Result<()> {
461461
let submission_path = Path::new(submission_path);
462462
let paste_message = matches.value_of("paste-message");
463463

464-
let locale = matches.value_of("locale").unwrap();
465-
let locale = into_locale(locale)?;
464+
let locale = matches.value_of("locale");
465+
let locale = if let Some(locale) = locale {
466+
Some(into_locale(locale)?)
467+
} else {
468+
None
469+
};
466470

467471
let new_submission = core
468472
.paste(
@@ -637,8 +641,12 @@ fn run() -> Result<()> {
637641

638642
let message_for_reviewer = matches.value_of("message-for-reviewer").unwrap();
639643

640-
let locale = matches.value_of("locale").unwrap();
641-
let locale = into_locale(locale)?;
644+
let locale = matches.value_of("locale");
645+
let locale = if let Some(locale) = locale {
646+
Some(into_locale(locale)?)
647+
} else {
648+
None
649+
};
642650

643651
let new_submission = core
644652
.request_code_review(

tmc-langs-core/src/tmc_core.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -306,22 +306,22 @@ impl TmcCore {
306306
/// submission_url,
307307
/// Path::new("./exercises/python/123"),
308308
/// Some("my python solution".to_string()),
309-
/// Language::Eng).unwrap();
309+
/// Some(Language::Eng)).unwrap();
310310
/// ```
311311
pub fn paste(
312312
&self,
313313
submission_url: Url,
314314
submission_path: &Path,
315315
paste_message: Option<String>,
316-
locale: Language,
316+
locale: Option<Language>,
317317
) -> Result<NewSubmission> {
318318
// compress
319319
let compressed = task_executor::compress_project(submission_path)?;
320320
let mut file = NamedTempFile::new().map_err(CoreError::TempFile)?;
321321
file.write_all(&compressed)
322322
.map_err(|e| CoreError::FileWrite(file.path().to_path_buf(), e))?;
323323

324-
self.post_submission_to_paste(submission_url, file.path(), paste_message, Some(locale))
324+
self.post_submission_to_paste(submission_url, file.path(), paste_message, locale)
325325
}
326326

327327
/// Checks the coding style for the project.
@@ -499,20 +499,15 @@ impl TmcCore {
499499
submission_url: Url,
500500
submission_path: &Path,
501501
message_for_reviewer: String,
502-
locale: Language,
502+
locale: Option<Language>,
503503
) -> Result<NewSubmission> {
504504
// compress
505505
let compressed = task_executor::compress_project(submission_path)?;
506506
let mut file = NamedTempFile::new().map_err(CoreError::TempFile)?;
507507
file.write_all(&compressed)
508508
.map_err(|e| CoreError::FileWrite(file.path().to_path_buf(), e))?;
509509

510-
self.post_submission_for_review(
511-
submission_url,
512-
file.path(),
513-
message_for_reviewer,
514-
Some(locale),
515-
)
510+
self.post_submission_for_review(submission_url, file.path(), message_for_reviewer, locale)
516511
}
517512

518513
/// Downloads the model solution from the given url.
@@ -719,7 +714,7 @@ mod test {
719714
submission_url,
720715
Path::new("tests/data/exercise"),
721716
Some("abcdefg".to_string()),
722-
Language::from_639_3("eng").unwrap(),
717+
Some(Language::Eng),
723718
)
724719
.unwrap();
725720
assert_eq!(
@@ -978,7 +973,7 @@ mod test {
978973
submission_url,
979974
Path::new("tests/data/exercise"),
980975
"abcdefg".to_string(),
981-
Language::from_639_3("eng").unwrap(),
976+
Some(Language::Eng),
982977
)
983978
.unwrap();
984979
assert_eq!(

0 commit comments

Comments
 (0)