Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions crates/openjd-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ chrono = "0.4"

[dev-dependencies]
tempfile = "3"

[target.'cfg(windows)'.dev-dependencies]
windows = { version = "0.62", features = [
"Win32_Foundation",
"Win32_System_Console",
] }
10 changes: 2 additions & 8 deletions crates/openjd-cli/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! `openjd check` command — validate a template file.

use clap::Args;
use openjd_model::template::parse::{self, DocumentType};
use openjd_model::template::parse;
use std::path::PathBuf;

#[derive(Args)]
Expand All @@ -21,15 +21,9 @@ pub struct CheckArgs {
pub fn execute(args: CheckArgs) -> Result<(), Box<dyn std::error::Error>> {
let path = &args.path;
let content = crate::common::read_input_file(path)?;
let doc_type = if path.extension().and_then(|e| e.to_str()) == Some("json") {
DocumentType::Json
} else {
DocumentType::Yaml
};

let template_value = parse::document_string_to_object(
&content,
doc_type,
crate::common::document_type(path),
&openjd_model::CallerLimits::default(),
)?;

Expand Down
11 changes: 11 additions & 0 deletions crates/openjd-cli/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use std::fmt;
use std::io::Read;
use std::path::Path;

use openjd_model::template::parse::DocumentType;

/// Maximum size, in bytes, of a `file://`-referenced input read by the CLI
/// (job parameter files, task files, path-mapping rule files).
///
Expand All @@ -19,6 +21,15 @@ use std::path::Path;
/// document and small enough to prevent runaway allocation.
pub const MAX_FILE_INPUT_SIZE: u64 = 10 * 1024 * 1024;

/// Infer the template document format from its filename extension.
pub fn document_type(path: &Path) -> DocumentType {
if path.extension().and_then(|extension| extension.to_str()) == Some("json") {
DocumentType::Json
} else {
DocumentType::Yaml
}
}

/// Read a file's contents as a UTF-8 string, mapping I/O errors to descriptive
/// CLI error messages and optionally enforcing a maximum file size.
///
Expand Down
9 changes: 2 additions & 7 deletions crates/openjd-cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! Context-aware help for `openjd run <template> --help`.

use openjd_model::template::parse::{self, DocumentType};
use openjd_model::template::parse;
use openjd_model::template::{JobParameterDefinition, JobTemplate};
use std::path::Path;

Expand Down Expand Up @@ -58,14 +58,9 @@ fn generate_template_help(
extensions_arg: Option<&str>,
) -> Result<String, Box<dyn std::error::Error>> {
let content = crate::common::read_input_file(path)?;
let doc_type = if path.extension().and_then(|e| e.to_str()) == Some("json") {
DocumentType::Json
} else {
DocumentType::Yaml
};
let template_value = parse::document_string_to_object(
&content,
doc_type,
crate::common::document_type(path),
&openjd_model::CallerLimits::default(),
)?;

Expand Down
Loading
Loading