From cff0fba5e5fb4a5de470bf923b93b0bdd89d9efb Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 9 Aug 2020 23:47:02 +0700 Subject: apply format --- .../src/codegen/gen_unstable_future_descriptor.rs | 49 +++++++++++++--------- 1 file changed, 29 insertions(+), 20 deletions(-) (limited to 'xtask/src/codegen') diff --git a/xtask/src/codegen/gen_unstable_future_descriptor.rs b/xtask/src/codegen/gen_unstable_future_descriptor.rs index 6dce8ba0a..75b603d7d 100644 --- a/xtask/src/codegen/gen_unstable_future_descriptor.rs +++ b/xtask/src/codegen/gen_unstable_future_descriptor.rs @@ -1,23 +1,27 @@ //! Generates descriptors structure for unstable feature from Unstable Book -use crate::{ - codegen::{self, project_root, Mode, Result}, -}; -use std::process::Command; +use crate::codegen::update; +use crate::codegen::{self, project_root, Mode, Result}; +use quote::quote; use std::fs; +use std::process::Command; use walkdir::WalkDir; -use quote::quote; -use crate::codegen::update; pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { let path = project_root().join(codegen::STORAGE); fs::create_dir_all(path.clone())?; Command::new("git").current_dir(path.clone()).arg("init").output()?; - Command::new("git").current_dir(path.clone()).args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]).output()?; - Command::new("git").current_dir(path.clone()).args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]).output()?; + Command::new("git") + .current_dir(path.clone()) + .args(&["remote", "add", "-f", "origin", codegen::REPOSITORY_URL]) + .output()?; + Command::new("git") + .current_dir(path.clone()) + .args(&["sparse-checkout", "set", "/src/doc/unstable-book/src/"]) + .output()?; Command::new("git").current_dir(path.clone()).args(&["pull", "origin", "master"]).output()?; - //TODO: check git, and do pull + //TODO: check git, and do pull let src_dir = path.join("src/doc/unstable-book/src"); let files = WalkDir::new(src_dir.join("language-features")) @@ -26,18 +30,23 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { .filter_map(|e| e.ok()) .filter(|entry| { // Get all `.md ` files - entry.file_type().is_file() && entry.path().extension().map(|ext| ext == "md").unwrap_or(false) + entry.file_type().is_file() + && entry.path().extension().map(|ext| ext == "md").unwrap_or(false) + }) + .collect::>(); + + let definitions = files + .iter() + .map(|entry| { + let path = entry.path(); + let feature_ident = + format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_")); + let doc = format!("{}", std::fs::read_to_string(path).unwrap()); + + quote! { LintCompletion { label: #feature_ident, description: #doc } } }) .collect::>(); - let definitions = files.iter().map(|entry| { - let path = entry.path(); - let feature_ident = format!("{}", path.file_stem().unwrap().to_str().unwrap().replace("-", "_")); - let doc = format!("{}", std::fs::read_to_string(path).unwrap() ); - - quote!{ LintCompletion { label: #feature_ident, description: #doc } } - }).collect::>(); - let ts = quote! { use crate::completion::LintCompletion; @@ -45,10 +54,10 @@ pub fn generate_unstable_future_descriptor(mode: Mode) -> Result<()> { #(#definitions),* ]; }; - + let destination = project_root().join(codegen::UNSTABLE_FEATURE); let contents = crate::reformat(ts.to_string())?; update(destination.as_path(), &contents, mode)?; Ok(()) -} \ No newline at end of file +} -- cgit v1.2.3