import os
import re
def fix_execute_method(file_path):
with open(file_path, 'r') as f:
content = f.read()
original_content = content
lines = content.split('\n')
new_lines = []
i = 0
in_execute = False
execute_start_line = -1
url_pattern = re.compile(r'^\s+let url = ["\'].*["\'];?\s*$')
request_pattern = re.compile(r'^\s+let request = \w+\s*\{[^}]*\};?\s*$')
while i < len(lines):
line = lines[i]
if 'pub async fn execute(self)' in line and 'execute_with_options' not in line:
in_execute = True
execute_start_line = i
if in_execute:
if 'self.execute_with_options(RequestOption::default())' in line or \
'self.execute_with_options(openlark_core::req_option::RequestOption::default())' in line:
in_execute = False
j = i - 1
removed_count = 0
while j >= 0 and removed_count < 4:
prev_line = lines[j]
if url_pattern.match(prev_line) or request_pattern.match(prev_line):
lines[j] = ''
removed_count += 1
elif prev_line.strip() == '' and removed_count > 0:
lines[j] = ''
elif prev_line.strip() and not url_pattern.match(prev_line) and not request_pattern.match(prev_line):
break
j -= 1
new_lines.append(line)
else:
new_lines.append(line)
else:
new_lines.append(line)
i += 1
new_content = '\n'.join(line for line in new_lines if line is not None)
if new_content != original_content:
with open(file_path, 'w') as f:
f.write(new_content)
return True
return False
def main():
base_dir = "/Users/zool/RustroverProjects/open-lark/crates/openlark-platform/src"
fixed_count = 0
for root, dirs, files in os.walk(base_dir):
for file in files:
if file.endswith('.rs'):
file_path = os.path.join(root, file)
try:
if fix_execute_method(file_path):
print(f"Fixed: {file_path}")
fixed_count += 1
except Exception as e:
print(f"Error processing {file_path}: {e}")
print(f"\nTotal files fixed: {fixed_count}")
if __name__ == "__main__":
main()