Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
James Lowry
Pod backend
Commits
e74b9799
Unverified
Commit
e74b9799
authored
4 years ago
by
Vasili Novikov
Browse files
Options
Download
Email Patches
Plain Diff
Allow specifying Schema file in CLI
parent
1abd6743
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/command_line_interface.rs
+13
-6
src/command_line_interface.rs
src/constants.rs
+0
-2
src/constants.rs
src/database_migrate_schema.rs
+2
-2
src/database_migrate_schema.rs
src/main.rs
+2
-2
src/main.rs
with
17 additions
and
12 deletions
+17
-12
src/command_line_interface.rs
+
13
-
6
View file @
e74b9799
...
...
@@ -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!
{
...
...
This diff is collapsed.
Click to expand it.
src/constants.rs
+
0
-
2
View file @
e74b9799
...
...
@@ -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"
;
This diff is collapsed.
Click to expand it.
src/database_migrate_schema.rs
+
2
-
2
View file @
e74b9799
...
...
@@ -40,9 +40,9 @@ pub enum SchemaPropertyType {
lazy_static!
{
static
ref
SCHEMA_STRUCT
:
DatabaseSchema
=
{
let
file
=
crate
::
co
nstants
::
SCHEMA_JSON_FILE
;
let
file
=
&
crate
::
co
mmand_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
));
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
2
-
2
View file @
e74b9799
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets