// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617use crate::Logger;18use anyhow::{Error, anyhow};19use std::fs::OpenOptions;20use std::io::Write;21use std::path::Path;2223const SKILLS_CONTENT: &str = include_str!("resources/skills.md");2425pub fn write_skills_file(path: &Path, log: &Logger) -> Result<(), Error> {26log.debug(format!("Creating skills file at: {}", path.display()));27if path.exists() {28return Err(anyhow!(29"The file {} already exists. Please remove it or choose a different location.",30path.display()31));32}33if let Some(parent) = path.parent() {34if !parent.exists() {35log.debug(format!("Creating directory: {}", parent.display()));36std::fs::create_dir_all(parent)?;37}38}39let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;40file.write_all(SKILLS_CONTENT.as_bytes())?;41Ok(())42}434445