Unverified Commit e74b9799 authored by Vasili Novikov's avatar Vasili Novikov
Browse files

Allow specifying Schema file in CLI

parent 1abd6743
No related merge requests found
Showing with 17 additions and 12 deletions
+17 -12
......@@ -96,13 +96,20 @@ pub struct CLIOptions {
#[structopt(long)]
pub shared_server: bool,
/// Validate a schema file, and exit.
/// This allows testing whether a given schema is suitable for use in Pod.
/// See README.md#schema on the general definition of a valid schema.
/// Schema file to use.
#[structopt(
long,
name = "SCHEMA_FILE",
parse(from_os_str),
default_value = "res/autogenerated_database_schema.json"
)]
pub schema_file: PathBuf,
/// Validate the schema file, and exit. Useful in combination with the --schema-file CLI key.
/// Note that running project tests or starting the Pod will also automatically validate
/// the schema in `res/autogenerated_database_schema.json`.
#[structopt(short = "v", long, name = "SCHEMA_FILE", parse(from_os_str))]
pub validate_schema: Option<PathBuf>,
/// the schema.
#[structopt(long)]
pub validate_schema: bool,
}
lazy_static! {
......
......@@ -3,5 +3,3 @@
pub const DATABASE_DIR: &str = "./data/db";
pub const MEDIA_DIR: &str = "./data/media";
pub const SCHEMA_JSON_FILE: &str = "res/autogenerated_database_schema.json";
......@@ -40,9 +40,9 @@ pub enum SchemaPropertyType {
lazy_static! {
static ref SCHEMA_STRUCT: DatabaseSchema = {
let file = crate::constants::SCHEMA_JSON_FILE;
let file = &crate::command_line_interface::PARSED.schema_file;
let file = std::fs::read(file)
.unwrap_or_else(|err| panic!("Failed to read schema file {}, {}", file, err));
.unwrap_or_else(|err| panic!("Failed to read schema file {:?}, {}", file, err));
let schema: DatabaseSchema = serde_json::from_slice(&file)
.expect("Failed to parse autogenerated_database_schema to JSON");
validate_schema(&schema).unwrap_or_else(|err| panic!("Schema validation failed, {}", err));
......
......@@ -37,8 +37,8 @@ async fn main() {
})
.init();
let cli_options: &CLIOptions = &*command_line_interface::PARSED;
if let Some(file) = &cli_options.validate_schema {
if let Err(err) = database_migrate_schema::validate_schema_file(&file) {
if cli_options.validate_schema {
if let Err(err) = database_migrate_schema::validate_schema_file(&cli_options.schema_file) {
log::error!("Schema validation failed: {}", err);
std::process::exit(1)
} else {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment