-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit prepares the terrain to bridge the gap in configurability between the CLI and Javy, the crate. The intention behind introducing a new crate is to: * Reduce code duplication and sync the options between the CLI and the core crate. * Make it easy to pass the options into WebAssemlby by using bitflags. This PR doesn't introduce any new functionality. A follow up PR will include new commands in the CLI which will make use of the share configuration.
- Loading branch information
1 parent
0b8cc19
commit 3450dd6
Showing
10 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
use anyhow::Result; | ||
use javy::{Config, Runtime}; | ||
use javy_config::Config as SharedConfig; | ||
|
||
pub(crate) fn new_runtime() -> Result<Runtime> { | ||
pub(crate) fn new(shared_config: SharedConfig) -> Result<Runtime> { | ||
let mut config = Config::default(); | ||
let config = config | ||
.text_encoding(true) | ||
.redirect_stdout_to_stderr(true) | ||
.javy_stream_io(true) | ||
.override_json_parse_and_stringify(true) | ||
.javy_json(true); | ||
.text_encoding(shared_config.contains(SharedConfig::TEXT_ENCODING)) | ||
.redirect_stdout_to_stderr(shared_config.contains(SharedConfig::REDIRECT_STDOUT_TO_STDERR)) | ||
.javy_stream_io(shared_config.contains(SharedConfig::JAVY_STREAM_IO)) | ||
.override_json_parse_and_stringify( | ||
shared_config.contains(SharedConfig::OVERRIDE_JSON_PARSE_AND_STRINGIFY), | ||
) | ||
.javy_json(shared_config.contains(SharedConfig::JAVY_JSON)); | ||
|
||
Runtime::new(std::mem::take(config)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "javy-config" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bitflags = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Shared Configuration for Javy | ||
|
||
See `src/lib.rs` for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Shared Configuration for Javy. | ||
//! | ||
//! This crate serves as a central place to facilitate configuration sharing | ||
//! between the Javy CLI and the Javy crate. It addresses the challenge of | ||
//! passing configuration settings in environments where the Javy CLI commands | ||
//! predominantly execute WebAssembly. | ||
//! | ||
//! The purpose of this crate is to consolidate configuration parameters, | ||
//! ensuring consistent and accessible settings across both the CLI and the | ||
//! crate. This approach simplifies the management of configuration settings and | ||
//! enhances the integration between different components of the Javy ecosystem. | ||
//! | ||
//! Currently, this crate includes only a subset of the available configuration | ||
//! options. The objective is to eventually encompass all configurable | ||
//! parameters found in [javy::Config]. | ||
//! | ||
//! The selection of the current configuration options was influenced by the | ||
//! need to override non-standard defaults typically set during CLI invocations. | ||
//! These defaults often do not align with the preferences of the CLI users. | ||
//! | ||
//! In gneneral this crate should be treated as an internal detail and | ||
//! a contract between the CLI and the Javy crate. | ||
use bitflags::bitflags; | ||
|
||
bitflags! { | ||
pub struct Config: u32 { | ||
const OVERRIDE_JSON_PARSE_AND_STRINGIFY = 1; | ||
const JAVY_JSON = 1 << 1; | ||
const JAVY_STREAM_IO = 1 << 1; | ||
const REDIRECT_STDOUT_TO_STDERR = 1 << 2; | ||
const TEXT_ENCODING = 1 << 3; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters