Skip to content

Commit

Permalink
after review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SRetip committed May 31, 2024
1 parent cfb95d9 commit 5105ac4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
24 changes: 12 additions & 12 deletions module/move/willbe/src/action/main_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,28 +178,28 @@ mod private
/// [![docs.rs](https://raster.shields.io/static/v1?label=docs&message=online&color=eee&logo=docsdotrs&logoColor=eee)](https://docs.rs/wtools)
/// <!--{ generate.main_header.end }-->
/// ```
pub fn readme_header_renew( path : AbsolutePath ) -> Result< MainHeaderRenewReport, ( MainHeaderRenewError, MainHeaderRenewReport ) >
pub fn readme_header_renew( path : AbsolutePath ) -> Result< MainHeaderRenewReport, ( MainHeaderRenewReport, MainHeaderRenewError ) >
{
let mut report = MainHeaderRenewReport::default();
regexes_initialize();

let mut cargo_metadata = Workspace::with_crate_dir
(
CrateDir::try_from( path )
.map_err( | e | ( e.into(), report.clone() ) )?
).map_err( | e | ( e.into(), report.clone() ) )?;
.map_err( | e | ( report.clone(), e.into() ) )?
).map_err( | e | ( report.clone(), e.into() ) )?;

let workspace_root = workspace_root( &mut cargo_metadata )
.map_err( | e | ( e.into(), report.clone() ) )?;
.map_err( | e | ( report.clone(), e.into() ) )?;

let header_param = HeaderParameters::from_cargo_toml( cargo_metadata )
.map_err( | e | ( e, report.clone() ) )?;
.map_err( | e | ( report.clone(), e.into() ) )?;

let read_me_path = workspace_root.join
(
readme_path( &workspace_root )
.ok_or_else( || format_err!( "Fail to find README.md" ) )
.map_err( | e | ( e.into(), report.clone() ) )?
.map_err( | e | ( report.clone(), e.into() ) )?
);

report.found_file = Some( read_me_path.clone() );
Expand All @@ -208,10 +208,10 @@ mod private
.read( true )
.write( true )
.open( &read_me_path )
.map_err( | e | ( e.into(), report.clone() ) )?;
.map_err( | e | ( report.clone(), e.into() ) )?;

let mut content = String::new();
file.read_to_string( &mut content ).map_err( | e | ( e.into(), report.clone() ) )?;
file.read_to_string( &mut content ).map_err( | e | ( report.clone(), e.into() ) )?;

let raw_params = TAGS_TEMPLATE
.get()
Expand All @@ -223,16 +223,16 @@ mod private

_ = query::parse( raw_params ).context( "Fail to parse arguments" );

let header = header_param.to_header().map_err( | e | ( e.into(), report.clone() ) )?;
let header = header_param.to_header().map_err( | e | ( report.clone(), e.into() ) )?;
let content : String = TAGS_TEMPLATE.get().unwrap().replace
(
&content,
&format!( "<!--{{ generate.main_header.start{raw_params} }}-->\n{header}\n<!--{{ generate.main_header.end }}-->" )
).into();

file.set_len( 0 ).map_err( | e | ( e.into(), report.clone() ) )?;
file.seek( SeekFrom::Start( 0 ) ).map_err( | e | ( e.into(), report.clone() ) )?;
file.write_all( content.as_bytes() ).map_err( | e | ( e.into(), report.clone() ) )?;
file.set_len( 0 ).map_err( | e | ( report.clone(), e.into() ) )?;
file.seek( SeekFrom::Start( 0 ) ).map_err( | e | ( report.clone(), e.into() ) )?;
file.write_all( content.as_bytes() ).map_err( | e | ( report.clone(), e.into() ) )?;
report.touched_file = read_me_path;
report.success = true;
Ok( report )
Expand Down
26 changes: 13 additions & 13 deletions module/move/willbe/src/action/readme_modules_headers_renew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,32 +180,32 @@ mod private
/// [![experimental](https://raster.shields.io/static/v1?label=&message=experimental&color=orange)](https://github.com/emersion/stability-badges#experimental) | [![rust-status](https://github.com/Username/test/actions/workflows/ModuleChainOfPackagesAPush.yml/badge.svg)](https://github.com/Username/test/actions/workflows/ModuleChainOfPackagesAPush.yml)[![docs.rs](https://img.shields.io/docsrs/_chain_of_packages_a?color=e3e8f0&logo=docs.rs)](https://docs.rs/_chain_of_packages_a)[![Open in Gitpod](https://raster.shields.io/static/v1?label=try&message=online&color=eee&logo=gitpod&logoColor=eee)](https://gitpod.io/#RUN_PATH=.,SAMPLE_FILE=sample%2Frust%2F_chain_of_packages_a_trivial%2Fsrc%2Fmain.rs,RUN_POSTFIX=--example%20_chain_of_packages_a_trivial/https://github.com/Username/test)
/// <!--{ generate.module_header.end }-->
/// ```
pub fn readme_modules_headers_renew( path : AbsolutePath ) -> Result< ModulesHeadersRenewReport, ( ModulesHeadersRenewError, ModulesHeadersRenewReport ) >
pub fn readme_modules_headers_renew( path : AbsolutePath ) -> Result< ModulesHeadersRenewReport, ( ModulesHeadersRenewReport, ModulesHeadersRenewError ) >
{
let mut report = ModulesHeadersRenewReport::default();
regexes_initialize();
let cargo_metadata = Workspace::with_crate_dir( CrateDir::try_from( path ).map_err( | e | ( e.into(), report.clone() ) )? ).map_err( | e | ( e.into(), report.clone() ) )?;
let discord_url = cargo_metadata.discord_url().map_err( | e | ( e.into(), report.clone() ) )?;
let paths = cargo_metadata.packages().map_err( | e | ( e.into(), report.clone() ) )?.into_iter().filter_map( | p | AbsolutePath::try_from( p.manifest_path() ).ok()).collect::< Vec< _ > >();
let cargo_metadata = Workspace::with_crate_dir( CrateDir::try_from( path ).map_err( | e | ( report.clone(), e.into() ) )? ).map_err( | e | ( report.clone(), e.into() ) )?;
let discord_url = cargo_metadata.discord_url().map_err( | e | ( report.clone(), e.into() ) )?;
let paths = cargo_metadata.packages().map_err( | e | ( report.clone(), e.into() ) )?.into_iter().filter_map( | p | AbsolutePath::try_from( p.manifest_path() ).ok()).collect::< Vec< _ > >();
report.found_files = paths.iter().map( | ap | ap.as_ref().to_path_buf() ).collect();
for path in paths
{
let read_me_path = path
.parent()
.unwrap()
.join( readme_path( path.parent().unwrap().as_ref() ).ok_or_else::< wError, _ >( || err!( "Fail to find README.md" ) ).map_err( | e | ( e.into(), report.clone() ) )? );
.join( readme_path( path.parent().unwrap().as_ref() ).ok_or_else::< wError, _ >( || err!( "Fail to find README.md" ) ).map_err( | e | ( report.clone(), e.into() ) )? );

let pakage = Package::try_from( path.clone() ).map_err( | e | ( e.into(), report.clone() ) )?;
let header = ModuleHeader::from_cargo_toml( pakage.into(), &discord_url ).map_err( | e | ( e.into(), report.clone() ) )?;
let pakage = Package::try_from( path.clone() ).map_err( | e | ( report.clone(), e.into() ) )?;
let header = ModuleHeader::from_cargo_toml( pakage.into(), &discord_url ).map_err( | e | ( report.clone(), e.into() ) )?;

let mut file = OpenOptions::new()
.read( true )
.write( true )
.open( &read_me_path )
.map_err( | e | ( e.into(), report.clone() ) )?;
.map_err( | e | ( report.clone(), e.into() ) )?;

let mut content = String::new();
file.read_to_string( &mut content ).map_err( | e | ( e.into(), report.clone() ) )?;
file.read_to_string( &mut content ).map_err( | e | ( report.clone(), e.into() ) )?;

let raw_params = TAGS_TEMPLATE
.get()
Expand All @@ -217,11 +217,11 @@ mod private

_ = query::parse( raw_params ).context( "Fail to parse raw params." );

let content = header_content_generate( &content, header, raw_params, cargo_metadata.workspace_root().map_err( | e | ( e.into(), report.clone() ) )?.to_str().unwrap() ).map_err( | e | ( e.into(), report.clone() ) )?;
let content = header_content_generate( &content, header, raw_params, cargo_metadata.workspace_root().map_err( | e | ( report.clone(), e.into() ) )?.to_str().unwrap() ).map_err( | e | ( report.clone(), e.into() ) )?;

file.set_len( 0 ).map_err( | e | ( e.into(), report.clone() ) )?;
file.seek( SeekFrom::Start( 0 ) ).map_err( | e | ( e.into(), report.clone() ) )?;
file.write_all( content.as_bytes() ).map_err( | e | ( e.into(), report.clone() ) )?;
file.set_len( 0 ).map_err( | e | ( report.clone(), e.into() ) )?;
file.seek( SeekFrom::Start( 0 ) ).map_err( | e | ( report.clone(), e.into() ) )?;
file.write_all( content.as_bytes() ).map_err( | e | ( report.clone(), e.into() ) )?;
report.touched_files.insert( path.as_ref().to_path_buf() );
}
Ok( report )
Expand Down
2 changes: 1 addition & 1 deletion module/move/willbe/src/command/main_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod private
println!( "{report}" );
Ok( () )
}
Err( ( e, report ) ) =>
Err( ( report, e ) ) =>
{
eprintln!( "{report}" );
Err( Error::from( e ).context( "Fail to generate main header." ) )
Expand Down
18 changes: 9 additions & 9 deletions module/move/willbe/src/command/readme_headers_renew.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
mod private
{
use std::fmt::{Display, Formatter};
use crate::*;
use _path::AbsolutePath;
use action;
use wtools::error::anyhow::Error;
use error_tools::{ Result, err };
use crate::_path::AbsolutePath;
use crate::action;
use crate::action::{MainHeaderRenewReport, ModulesHeadersRenewReport};
use crate::wtools::error::anyhow::Error;
use std::fmt::{ Display, Formatter };

#[ derive( Debug, Default ) ]
struct ReadmeHeadersRenewReport
{
main_header_renew_report : MainHeaderRenewReport,
main_header_renew_report : action::MainHeaderRenewReport,
main_header_renew_error : Option< Error >,
modules_headers_renew_report : ModulesHeadersRenewReport,
modules_headers_renew_report : action::ModulesHeadersRenewReport,
modules_headers_renew_error : Option< Error >,
}

Expand Down Expand Up @@ -77,7 +77,7 @@ mod private
{
report.main_header_renew_report = r;
}
Err( ( error, r) ) =>
Err( ( r, error ) ) =>
{
fail = true;
report.main_header_renew_report = r;
Expand All @@ -90,7 +90,7 @@ mod private
{
report.modules_headers_renew_report = r;
}
Err( ( error, r) ) =>
Err( ( r, error ) ) =>
{
fail = true;
report.modules_headers_renew_report = r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod private
println!( "{report}" );
Ok( () )
}
Err( ( e, report ) ) =>
Err( ( report, e ) ) =>
{
eprintln!( "{report}" );
Err( Error::from( e ).context( "Fail to generate modules headers." ) )
Expand Down

0 comments on commit 5105ac4

Please sign in to comment.