-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_start.py
More file actions
executable file
·105 lines (84 loc) · 4.17 KB
/
quick_start.py
File metadata and controls
executable file
·105 lines (84 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
"""
Quick Start Guide for Recator Library
"""
from recator import Recator
import sys
def quick_example():
"""Quick example of using Recator"""
print("""
╔════════════════════════════════════════════╗
║ RECATOR - Quick Start Example ║
╚════════════════════════════════════════════╝
""")
# Get project path from command line or use current directory
if len(sys.argv) > 1:
project_path = sys.argv[1]
else:
project_path = "."
print("💡 Tip: You can specify a project path as argument")
print(f" Using current directory: {project_path}\n")
# Configure Recator
config = {
'min_lines': 4, # Minimum duplicate size
'min_tokens': 30, # Minimum tokens
'similarity_threshold': 0.85, # 85% similarity threshold
'languages': ['python', 'javascript', 'java'], # Languages to analyze
'safe_mode': True # Don't modify original files
}
try:
# Initialize Recator
print(f"🔍 Initializing Recator for: {project_path}")
recator = Recator(project_path, config)
# Analyze for duplicates
print("📊 Analyzing for code duplicates...")
results = recator.analyze()
# Display results
print("\n📈 Analysis Results:")
print(f" ├─ Files scanned: {results['total_files']}")
print(f" ├─ Files analyzed: {results['parsed_files']}")
print(f" └─ Duplicates found: {results['duplicates_found']}")
if results['duplicates_found'] > 0:
# Show top 3 duplicates
print("\n🔝 Top duplicates found:")
for i, dup in enumerate(results['duplicates'][:3], 1):
print(f"\n [{i}] {dup.get('type', 'Unknown').replace('_', ' ').title()}")
if 'files' in dup:
print(f" Files involved: {len(dup['files'])}")
for file in dup['files'][:2]:
print(f" • {file}")
if len(dup['files']) > 2:
print(f" • ... and {len(dup['files']) - 2} more")
if 'confidence' in dup:
print(f" Confidence: {dup['confidence']:.0%}")
if 'lines' in dup:
print(f" Size: {dup['lines']} lines")
# Preview refactoring
print("\n🔧 Generating refactoring suggestions...")
preview = recator.refactor_duplicates(dry_run=True)
print("\n💡 Refactoring Suggestions:")
print(f" ├─ Suggested actions: {preview.get('total_actions', 0)}")
print(f" ├─ Potential LOC reduction: {preview.get('estimated_loc_reduction', 0)} lines")
print(f" └─ Files to modify: {len(preview.get('affected_files', []))}")
if preview.get('actions'):
print("\n📝 Recommended actions:")
for i, action in enumerate(preview['actions'][:3], 1):
print(f" {i}. {action['description']}")
print("\n💬 Next steps:")
print(" 1. Review the detected duplicates")
print(" 2. Use 'recator --refactor' to see detailed refactoring plan")
print(" 3. Use 'recator --refactor --apply' to apply changes (creates .refactored files)")
else:
print("\n✨ Great! No code duplicates found in your project.")
print(" Your code is clean and DRY (Don't Repeat Yourself)!")
except FileNotFoundError:
print(f"❌ Error: Directory '{project_path}' not found")
sys.exit(1)
except Exception as e:
print(f"❌ Error: {e}")
sys.exit(1)
print("\n" + "="*50)
print("For more information, run: recator --help")
print("="*50)
if __name__ == "__main__":
quick_example()