fn make_new_crate_op()

in tools/hakari/src/cli_ops/initialize.rs [123:170]


    fn make_new_crate_op(&self) -> WorkspaceOp<'g, 'a> {
        let files = CRATE_TEMPLATE_DIR
            .find("**/*")
            .expect("pattern **/* is valid")
            .flat_map(|entry| {
                match entry {
                    DirEntry::File(file) => {
                        let path: &Utf8Path = file
                            .path()
                            .try_into()
                            .expect("embedded path is valid UTF-8");
                        // .toml-in files need a bit of processing.
                        if path.extension() == Some("toml-in") {
                            let contents = file
                                .contents_utf8()
                                .expect("embedded .toml-in is valid UTF-8");
                            let contents = contents.replace("%PACKAGE_NAME%", self.package_name);
                            let contents =
                                contents.replace("%CARGO_TOML_COMMENT%\n", self.cargo_toml_comment);
                            Some((
                                Cow::Owned(path.with_extension("toml")),
                                Cow::Owned(contents.into_bytes()),
                            ))
                        } else {
                            Some((Cow::Borrowed(path), Cow::Borrowed(file.contents())))
                        }
                    }
                    DirEntry::Dir(_) => None,
                }
            })
            .collect();

        let root_files = self
            .config
            .into_iter()
            .map(|(path, comment)| {
                let contents = CONFIG_TEMPLATE.replace("%PACKAGE_NAME%", self.package_name);
                let contents = contents.replace("%CONFIG_COMMENT%\n", comment);
                (Cow::Borrowed(path), Cow::Owned(contents.into_bytes()))
            })
            .collect();

        WorkspaceOp::NewCrate {
            crate_path: self.crate_path,
            files,
            root_files,
        }
    }