Debian Codegraph @

cli/src/commands/sparse/list.rs

raw
1 // Copyright 2020 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::io::Write as _;
16 use std::path::Path;
17
18 use tracing::instrument;
19
20 use crate::cli_util::CommandHelper;
21 use crate::command_error::CommandError;
22 use crate::ui::Ui;
23
24 /// List the patterns that are currently present in the working copy
25 ///
26 /// By default, a newly cloned or initialized repo will have have a pattern
27 /// matching all files from the repo root. That pattern is rendered as `.` (a
28 /// single period).
29 #[derive(clap::Args, Clone, Debug)]
30 pub struct SparseListArgs {}
31
32 #[instrument(skip_all)]
33 pub async fn cmd_sparse_list(
34 ui: &mut Ui,
35 command: &CommandHelper,
36 _args: &SparseListArgs,
37 ) -> Result<(), CommandError> {
38 let workspace_command = command.workspace_helper(ui).await?;
39 for path in workspace_command.working_copy().sparse_patterns()? {
40 writeln!(
41 ui.stdout(),
42 "{}",
43 path.to_fs_path_unchecked(Path::new("")).display()
44 )?;
45 }
46 Ok(())
47 }