workspacer_cli/
format_all_imports.rs

1// ---------------- [ File: workspacer-cli/src/format_all_imports.rs ]
2crate::ix!();
3
4/// Subcommand data for `ws format all-imports --path <dir> [--skip-git-check]`
5#[derive(Debug, StructOpt)]
6pub struct FormatAllImportsCommand {
7    /// If provided, we use this directory as the workspace root instead of the current dir
8    #[structopt(long = "path")]
9    workspace_path: Option<PathBuf>,
10
11    /// Skip checking for a clean Git state if true
12    #[structopt(long = "skip-git-check")]
13    skip_git_check: bool,
14}
15
16impl FormatAllImportsCommand {
17    pub async fn run(&self) -> Result<(), WorkspaceError> {
18        let ws_path = self.workspace_path.clone();
19        let skip_flag = self.skip_git_check;
20
21        // Use our standard "run_with_workspace" helper that doesn't need a crate name
22        run_with_workspace(ws_path, skip_flag, move |ws| {
23            Box::pin(async move {
24                // The `SortAndFormatImports` trait is also implemented for Workspaces
25                ws.sort_and_format_imports().await.map_err(|err| {
26                    error!("Failed to format imports in entire workspace: {:?}", err);
27                    err
28                })?;
29
30                info!("Successfully formatted imports in the entire workspace!");
31                Ok(())
32            })
33        })
34        .await
35    }
36}