-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathcheck.rs
More file actions
80 lines (69 loc) · 2.31 KB
/
check.rs
File metadata and controls
80 lines (69 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::cli_options::CliOptions;
use crate::{CliDiagnostic, Execution, TraversalMode};
use biome_deserialize::Merge;
use pglt_configuration::PartialConfiguration;
use pglt_console::Console;
use pglt_fs::FileSystem;
use pglt_workspace::{DynRef, Workspace, WorkspaceError, configuration::LoadedConfiguration};
use std::ffi::OsString;
use super::{CommandRunner, get_files_to_process_with_cli_options};
pub(crate) struct CheckCommandPayload {
pub(crate) configuration: Option<PartialConfiguration>,
pub(crate) paths: Vec<OsString>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
}
impl CommandRunner for CheckCommandPayload {
const COMMAND_NAME: &'static str = "check";
fn merge_configuration(
&mut self,
loaded_configuration: LoadedConfiguration,
_fs: &DynRef<'_, dyn FileSystem>,
_console: &mut dyn Console,
) -> Result<PartialConfiguration, WorkspaceError> {
let LoadedConfiguration {
configuration: mut fs_configuration,
..
} = loaded_configuration;
if let Some(configuration) = self.configuration.clone() {
// overwrite fs config with cli args
fs_configuration.merge_with(configuration);
}
Ok(fs_configuration)
}
fn get_files_to_process(
&self,
fs: &DynRef<'_, dyn FileSystem>,
configuration: &PartialConfiguration,
) -> Result<Vec<OsString>, CliDiagnostic> {
let paths = get_files_to_process_with_cli_options(
self.since.as_deref(),
self.changed,
self.staged,
fs,
configuration,
)?
.unwrap_or(self.paths.clone());
Ok(paths)
}
fn get_stdin_file_path(&self) -> Option<&str> {
self.stdin_file_path.as_deref()
}
fn should_write(&self) -> bool {
false
}
fn get_execution(
&self,
cli_options: &CliOptions,
console: &mut dyn Console,
_workspace: &dyn Workspace,
) -> Result<Execution, CliDiagnostic> {
Ok(Execution::new(TraversalMode::Check {
stdin: self.get_stdin(console)?,
vcs_targeted: (self.staged, self.changed).into(),
})
.set_report(cli_options))
}
}