11#![ allow( clippy:: disallowed_macros) ]
22
3+ use chrono:: { Datelike , Local } ;
34use clap:: { Arg , Command } ;
45use duct:: cmd;
56use regex:: Regex ;
@@ -10,12 +11,24 @@ use std::path::PathBuf;
1011
1112fn process_license_file ( upgrade_version : & str ) {
1213 let path = "LICENSE.txt" ;
13- let file = fs:: read_to_string ( path) . unwrap ( ) ;
14- let re = Regex :: new ( r"(?m)^(Licensed Work:\s+SpacetimeDB )([\d\.]+)$" ) . unwrap ( ) ;
15- let file = re. replace_all ( & file, |caps : & regex:: Captures | {
14+ let contents = fs:: read_to_string ( path) . unwrap ( ) ;
15+
16+ let version_re = Regex :: new ( r"(?m)^(Licensed Work:\s+SpacetimeDB )([\d\.]+)$" ) . unwrap ( ) ;
17+ let date_re = Regex :: new ( r"(?m)^Change Date:\s+\d{4}-\d{2}-\d{2}$" ) . unwrap ( ) ;
18+
19+ let updated = version_re. replace_all ( & contents, |caps : & regex:: Captures | {
1620 format ! ( "{}{}" , & caps[ 1 ] , upgrade_version)
1721 } ) ;
18- fs:: write ( path, & * file) . unwrap ( ) ;
22+
23+ let new_date = Local :: now ( )
24+ . with_year ( Local :: now ( ) . year ( ) + 5 )
25+ . unwrap ( )
26+ . format ( "Change Date: %Y-%m-%d" )
27+ . to_string ( ) ;
28+
29+ let final_text = date_re. replace_all ( & updated, new_date. as_str ( ) ) ;
30+
31+ fs:: write ( path, final_text. as_ref ( ) ) . unwrap ( ) ;
1932}
2033
2134fn edit_toml ( path : impl AsRef < Path > , f : impl FnOnce ( & mut toml_edit:: DocumentMut ) ) -> anyhow:: Result < ( ) > {
0 commit comments