This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_cli): Add a new option --config-path to set the path to rom…
…e.json (#4158) * feat(rome_cli): Add a new option --config to set the path to rome.json * rename option config -> config-path * indentation * remove the website documentation for the config-path option * rename config_path -> configuration_path * refactor the base path option * debug artifacts * update comment * formatting
- Loading branch information
1 parent
eae1259
commit bb3cbc1
Showing
9 changed files
with
207 additions
and
22 deletions.
There are no files selected for viewing
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,11 +1,25 @@ | ||
use std::path::PathBuf; | ||
|
||
use crate::{CliDiagnostic, CliSession}; | ||
use rome_deserialize::Deserialized; | ||
use rome_service::{load_config, Configuration}; | ||
use rome_service::{load_config, BasePath, Configuration}; | ||
|
||
/// Load the configuration for this session of the CLI, merging the content of | ||
/// the `rome.json` file if it exists on disk with common command line options | ||
pub(crate) fn load_configuration( | ||
session: &mut CliSession, | ||
) -> Result<Deserialized<Configuration>, CliDiagnostic> { | ||
Ok(load_config(&session.app.fs, None)?.unwrap_or_default()) | ||
let config_path: Option<PathBuf> = session | ||
.args | ||
.opt_value_from_str("--config-path") | ||
.map_err(|source| CliDiagnostic::parse_error("--config-path", source))?; | ||
|
||
let base_path = match config_path { | ||
None => BasePath::default(), | ||
Some(path) => BasePath::FromUser(path), | ||
}; | ||
|
||
let config = load_config(&session.app.fs, base_path)?; | ||
|
||
Ok(config.unwrap_or_default()) | ||
} |
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
35 changes: 35 additions & 0 deletions
35
crates/rome_cli/tests/snapshots/main_commands_format/custom_config_file_path.snap
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,35 @@ | ||
--- | ||
source: crates/rome_cli/tests/snap_test.rs | ||
assertion_line: 335 | ||
expression: content | ||
--- | ||
## `/test/rome.json` | ||
|
||
```json | ||
{ | ||
"formatter": { | ||
"enabled": true, | ||
"lineWidth": 160, | ||
"indentStyle": "space", | ||
"indentSize": 6 | ||
} | ||
} | ||
|
||
``` | ||
|
||
## `file.js` | ||
|
||
```js | ||
function f() { | ||
return { a, b }; | ||
} | ||
|
||
``` | ||
|
||
# Emitted Messages | ||
|
||
```block | ||
Formatted 1 file(s) in <TIME> | ||
``` | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
crates/rome_cli/tests/snapshots/main_commands_format/invalid_config_file_path.snap
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,23 @@ | ||
--- | ||
source: crates/rome_cli/tests/snap_test.rs | ||
assertion_line: 335 | ||
expression: content | ||
--- | ||
## `file.js` | ||
|
||
```js | ||
content | ||
``` | ||
|
||
# Termination Message | ||
|
||
```block | ||
/test/rome.json internalError/fs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
× Rome couldn't read the following file, maybe for permissions reasons or it doesn't exists: /test/rome.json | ||
``` | ||
|
||
|
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