schema_registry_cli/command/
mod.rs1mod completion;
8mod schema;
9mod subject;
10
11use std::fs;
12use std::path::Path;
13
14use schema_registry_api::{RegisterSchema, SchemaRegistry, SchemaType};
15
16use crate::{CliError, Result, SchemaRegistrySettings};
17
18pub(crate) use self::completion::*;
19pub use self::schema::*;
20pub use self::subject::*;
21
22impl TryFrom<SchemaRegistrySettings> for SchemaRegistry {
23 type Error = CliError;
24
25 fn try_from(value: SchemaRegistrySettings) -> std::result::Result<Self, Self::Error> {
26 let result = SchemaRegistry::build_default(value.url)?;
27 Ok(result)
28 }
29}
30
31fn build_register_schema(path: &Path) -> Result<RegisterSchema> {
32 let extension = path
33 .extension()
34 .ok_or_else(|| CliError::InvalidSchemaExtension(path.to_path_buf()))?
35 .to_string_lossy();
36 let schema_type = match extension.as_ref() {
37 "avsc" | "avro" => SchemaType::Avro,
38 "json" => SchemaType::Json,
39 "proto" => SchemaType::Protobuf,
40 _ => {
41 return Err(CliError::InvalidSchemaExtension(path.to_path_buf()));
42 }
43 };
44 let schema = fs::read_to_string(path)?;
45
46 let result = RegisterSchema {
47 schema,
48 schema_type: Some(schema_type),
49 references: vec![],
50 };
51 Ok(result)
52}