| from agicli.printplus import pr, inp |
| import os |
|
|
| def is_first_time_user(path="agicli/user/user_status.txt"): |
| os.makedirs(os.path.dirname(path), exist_ok=True) |
| |
| if not os.path.exists(path): |
| with open(path, 'w') as f: |
| f.write('not_first_time') |
| return True |
|
|
| with open(path, 'r') as f: |
| status = f.read().strip().lower() |
|
|
| if status == 'first_time': |
| with open(path, 'w') as f: |
| f.write('not_first_time') |
| return True |
|
|
| return False |
|
|
| def save_detail(detail_name, detail_value, path="agicli/user/user_details.txt"): |
| os.makedirs(os.path.dirname(path), exist_ok=True) |
| |
| details = {} |
| if os.path.exists(path): |
| with open(path, 'r') as f: |
| for line in f: |
| if '=' in line: |
| key, value = line.strip().split('=', 1) |
| details[key] = value |
|
|
| details[detail_name] = detail_value |
|
|
| with open(path, 'w') as f: |
| for key, value in details.items(): |
| f.write(f"{key}={value}\n") |
|
|
| def get_detail(detail_name, path="agicli/user/user_details.txt"): |
| if not os.path.exists(path): |
| return None |
|
|
| with open(path, 'r') as f: |
| for line in f: |
| if '=' in line: |
| key, value = line.strip().split('=', 1) |
| if key == detail_name: |
| return value |
| return None |
|
|
| def initialize(): |
| from agicli.home import home |
| |
| pr("AGI CLI", color="red", big_text=True) |
| if is_first_time_user(): |
| pr("✦ Welcome to AG Corp's AGI CLI!", color="red") |
| user_name = inp("What is your name? > ", color="green", margin=1) |
| |
| while not (user_name.isalpha() and len(user_name) < 20): |
| pr("Invalid name. Please enter a name with only letters and less than 20 characters.", color="red") |
| user_name = inp("What is your name? > ", color="green", margin=1) |
| save_detail("user_name", user_name) |
| pr(f"Nice to meet you, {user_name}!", color="green") |
| home() |
| else: |
| home() |