Skip to content

Commit 23d32f0

Browse files
committed
get-organization
1 parent e8dbe72 commit 23d32f0

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

tmc-langs-cli/src/app.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ pub fn create_app() -> App<'static, 'static> {
219219
.subcommand(SubCommand::with_name("get-organizations")
220220
.about("Get organizations."))
221221

222+
.subcommand(SubCommand::with_name("get-organization")
223+
.about("Get organization.")
224+
.arg(Arg::with_name("organization")
225+
.help("Organization slug (e.g. mooc, hy).")
226+
.long("organization")
227+
.required(true)
228+
.takes_value(true)))
229+
222230
.subcommand(SubCommand::with_name("download-or-update-exercises")
223231
.about("Download exercise.")
224232
.arg(Arg::with_name("exercise")

tmc-langs-cli/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,20 @@ fn run() -> Result<()> {
591591
data: Some(orgs),
592592
};
593593
print_output(&output)?;
594+
} else if let Some(matches) = matches.subcommand_matches("get-organization") {
595+
let organization_slug = matches.value_of("organization").unwrap();
596+
let org = core
597+
.get_organization(organization_slug)
598+
.context("Failed to get organization")?;
599+
600+
let output = Output {
601+
status: Status::Successful,
602+
message: None,
603+
result: OutputResult::RetrievedData,
604+
percent_done: 1.0,
605+
data: Some(org),
606+
};
607+
print_output(&output)?;
594608
} else if let Some(matches) = matches.subcommand_matches("download-or-update-exercises") {
595609
let mut exercise_args = matches.values_of("exercise").unwrap();
596610
let mut exercises = vec![];

tmc-langs-core/src/tmc_core.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ impl TmcCore {
229229
self.organizations()
230230
}
231231

232+
/// Fetches an organization.
233+
///
234+
/// # Errors
235+
/// Returns an error if there's some problem reaching the API, or if the API returns an error.
236+
pub fn get_organization(&self, organization_slug: &str) -> Result<Organization> {
237+
self.organization(organization_slug)
238+
}
239+
232240
/// Unimplemented.
233241
#[deprecated = "unimplemented"]
234242
pub fn send_diagnostics(&self) {

0 commit comments

Comments
 (0)