| 1 |
// Copyright 2023 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::fmt::Debug; |
| 16 |
use std::io::Write as _; |
| 17 |
|
| 18 |
use jj_lib::fileset; |
| 19 |
use jj_lib::fileset::FilesetDiagnostics; |
| 20 |
|
| 21 |
use crate::cli_util::CommandHelper; |
| 22 |
use crate::command_error::CommandError; |
| 23 |
use crate::command_error::print_parse_diagnostics; |
| 24 |
use crate::ui::Ui; |
| 25 |
|
| 26 |
/// Parse fileset expression |
| 27 |
#[derive(clap::Args, Clone, Debug)] |
| 28 |
pub struct DebugFilesetArgs { |
| 29 |
#[arg(value_hint = clap::ValueHint::AnyPath)] |
| 30 |
path: String, |
| 31 |
} |
| 32 |
|
| 33 |
pub async fn cmd_debug_fileset( |
| 34 |
ui: &mut Ui, |
| 35 |
command: &CommandHelper, |
| 36 |
args: &DebugFilesetArgs, |
| 37 |
) -> Result<(), CommandError> { |
| 38 |
let workspace_command = command.workspace_helper(ui).await?; |
| 39 |
|
| 40 |
let mut diagnostics = FilesetDiagnostics::new(); |
| 41 |
let context = workspace_command.env().fileset_parse_context(); |
| 42 |
let expression = fileset::parse_maybe_bare(&mut diagnostics, &args.path, &context)?; |
| 43 |
print_parse_diagnostics(ui, "In fileset expression", &diagnostics)?; |
| 44 |
writeln!(ui.stdout(), "-- Parsed:")?; |
| 45 |
writeln!(ui.stdout(), "{expression:#?}")?; |
| 46 |
writeln!(ui.stdout())?; |
| 47 |
|
| 48 |
let matcher = expression.to_matcher(); |
| 49 |
writeln!(ui.stdout(), "-- Matcher:")?; |
| 50 |
writeln!(ui.stdout(), "{matcher:#?}")?; |
| 51 |
Ok(()) |
| 52 |
} |