import re
import os
def fix_visibility(content):
lines = content.split('\n')
result = []
for line in lines:
stripped = line.strip()
if not stripped or stripped.startswith('//') or stripped.startswith('use ') or stripped.startswith('pub '):
result.append(line)
continue
if re.match(r'^struct\s+\w+', stripped):
line = line.replace('struct ', 'pub struct ', 1)
elif re.match(r'^enum\s+\w+', stripped):
line = line.replace('enum ', 'pub enum ', 1)
elif re.match(r'^(async\s+)?fn\s+\w+', stripped):
if stripped.startswith('async '):
line = line.replace('async fn ', 'pub async fn ', 1)
else:
line = line.replace('fn ', 'pub fn ', 1)
elif re.match(r'^const\s+\w+', stripped):
line = line.replace('const ', 'pub const ', 1)
elif re.match(r'^impl\s+', stripped):
line = line.replace('impl ', 'pub impl ', 1)
result.append(line)
return '\n'.join(result)
def process_file(filepath):
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
fixed_content = fix_visibility(content)
with open(filepath, 'w', encoding='utf-8') as f:
f.write(fixed_content)
print(f"Fixed visibility in {filepath}")
def main():
src_dir = '/home/user/aicommit/src'
modules = ['types.rs', 'version.rs', 'git.rs', 'providers.rs', 'models.rs', 'utils.rs']
for module in modules:
filepath = os.path.join(src_dir, module)
if os.path.exists(filepath):
process_file(filepath)
main_path = os.path.join(src_dir, 'main.rs')
with open(main_path, 'r', encoding='utf-8') as f:
content = f.read()
lines = content.split('\n')
seen_logging = False
fixed_lines = []
for line in lines:
if 'use logging::' in line:
if not seen_logging:
seen_logging = True
fixed_lines.append(line)
else:
fixed_lines.append(line)
with open(main_path, 'w', encoding='utf-8') as f:
f.write('\n'.join(fixed_lines))
print("Fixed main.rs")
print("\nAll visibility modifiers fixed!")
if __name__ == '__main__':
main()