Skip to content

Commit b4e8d9a

Browse files
authored
Merge pull request #4 from KTS-o7/dev
Complete Over Haul- Bumped package version to 1.1.0
2 parents 2c03640 + 8832bab commit b4e8d9a

8 files changed

Lines changed: 365 additions & 330 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SnapShell is a powerful command-line utility designed to enhance your Linux term
1313

1414
### Prerequisites
1515

16-
- Python 3.7 or higher
16+
- Python 3.10 or higher
1717
- `pip` package manager
1818

1919
### Installing via pip

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from setuptools import setup, find_packages
2-
import os
32

43
setup(
54
name='snapshell',
6-
version='1.0.0',
5+
version='1.1.0',
76
author='Krishnatejaswi S',
87
author_email='shentharkrishnatejaswi@gmail.com',
98
description='An AI-powered tool to suggest Linux commands based on user input',

snapshell/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# snapshell/__init__.py
2+
from .cli import main
3+
from .llm_api import LLMClient
4+
from .utils import create_database, update_database, save_command_suggestion, fetch_system_info ,print_color , view_history, clear_history
5+
from .package_managers import detect_package_manager
6+
7+
__all__ = [
8+
'main', 'LLMClient',
9+
'create_database', 'update_database', 'save_command_suggestion',
10+
'fetch_system_info', 'detect_package_manager', 'print_color',
11+
'view_history', 'clear_history'
12+
]

snapshell/cli.py

Lines changed: 35 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,22 @@
11
import argparse
2-
import os
32
import sqlite3
4-
from snapshell.database import create_database, update_database, DB_PATH
5-
from .llm_api import suggest_command, set_api_key, load_api_key
3+
from snapshell.utils import update_database, DB_PATH, print_color , clear_history, view_history
4+
from .llm_api import LLMClient
65

7-
# ANSI escape codes for colors
8-
RESET = "\033[0m"
9-
CYAN = "\033[36m"
10-
GREEN = "\033[32m"
11-
WHITE = "\033[37m"
12-
BLUE = "\033[34m"
13-
YELLOW = "\033[33m"
14-
RED = "\033[31m"
15-
16-
def initial_setup():
6+
def initial_setup(llm_client):
177
# Prompt user for GROQ API key
18-
print(GREEN + "Please enter your GROQ API key:" + RESET)
19-
groq_api_key = input(YELLOW + "> " + RESET)
8+
print_color("Please enter your GROQ API key:", "GREEN")
9+
groq_api_key = input("> " )
2010

2111
# Set the API key
22-
set_api_key(groq_api_key)
12+
llm_client.set_api_key(groq_api_key)
13+
14+
print_color(f"Setting up the database... at {DB_PATH}", "YELLOW")
15+
llm_client.init_client()
16+
print_color("Database successfully created\n", "GREEN")
17+
print_color("Use the tool as snapshell\n", "GREEN")
2318

24-
print(YELLOW + f"Setting up the database... at {DB_PATH}" + RESET)
25-
create_database()
26-
update_database()
27-
print(GREEN + "Database successfully created\n" + RESET)
28-
print(GREEN + "Use the tool as snapshell\n" + RESET)
29-
30-
def view_history():
31-
conn = sqlite3.connect(DB_PATH)
32-
cursor = conn.cursor()
33-
cursor.execute('SELECT user_input, command, explanation, timestamp FROM command_suggestions ORDER BY timestamp DESC')
34-
results = cursor.fetchall()
35-
conn.close()
36-
37-
if not results:
38-
print(f"{YELLOW}No history found.{RESET}")
39-
return
40-
41-
print(f"{CYAN}Command History:{RESET}")
42-
for entry in results:
43-
user_input, command, explanation, timestamp = entry
44-
print(f"{GREEN}User Input: {user_input}{RESET}")
45-
print(f"{WHITE}Command: {command}{RESET}")
46-
print(f"{BLUE}Explanation: {explanation}{RESET}")
47-
print(f"{YELLOW}Timestamp: {timestamp}{RESET}")
48-
print("-" * 40)
4919

50-
def clear_history():
51-
conn = sqlite3.connect(DB_PATH)
52-
cursor = conn.cursor()
53-
cursor.execute('DELETE FROM command_suggestions')
54-
conn.commit()
55-
conn.close()
56-
print(f"{GREEN}Command history cleared successfully.{RESET}")
5720

5821
def main():
5922
parser = argparse.ArgumentParser(description="Auto-complete Linux commands using an LLM.")
@@ -63,23 +26,23 @@ def main():
6326
parser.add_argument('--set-api-key', type=str, help="Set the GROQ API key")
6427
args = parser.parse_args()
6528

29+
llm_client = LLMClient()
30+
6631
if args.set_api_key:
67-
set_api_key(args.set_api_key)
68-
print(GREEN + "API key set successfully." + RESET)
32+
llm_client.set_api_key(args.set_api_key)
33+
print_color("API key set successfully.", "GREEN")
6934
return
7035

7136
# Load the API key from the configuration file
72-
API_KEY = load_api_key()
73-
37+
API_KEY = llm_client.load_api_key()
7438

7539
if not API_KEY:
76-
print("This is working")
77-
initial_setup()
40+
initial_setup(llm_client)
7841

7942
if args.update_db:
80-
print(f"{YELLOW}Updating database...{RESET}")
43+
print_color("Updating database...", "YELLOW")
8144
update_database()
82-
print(f"{GREEN}Database updated successfully.{RESET}")
45+
print_color("Database updated successfully.", "GREEN")
8346

8447
if args.view_history:
8548
view_history()
@@ -89,24 +52,27 @@ def main():
8952
clear_history()
9053
return
9154

92-
print(f"{CYAN}Welcome to the Linux Command Tool. Type 'exit' to quit.{RESET}")
93-
55+
print_color("Welcome to the SnapShell. Type 'exit' to quit.", "CYAN")
56+
57+
llm_client.init_client()
58+
9459
conversation_history = []
95-
60+
9661
while True:
97-
user_input = input(f"{CYAN}Enter your command query: {RESET}")
62+
user_input = input(f"Enter your command query: ")
9863

9964
if user_input.lower() == 'exit':
100-
print(f"{CYAN}Exiting the Linux Command Tool. Goodbye!{RESET}")
65+
print_color("Exiting the SnapShell. Goodbye!", "CYAN")
10166
break
10267

10368
try:
104-
print(f"{CYAN}Fetching command suggestion...{RESET}")
105-
suggestion = suggest_command(user_input, conversation_history)
106-
print(f"{GREEN}Suggested Command: \n {RESET}")
107-
print(f"{WHITE}{suggestion.command}{RESET}\n")
108-
print(f"{BLUE}Explanation: {suggestion.explanation}{RESET}\n")
109-
print(f"{YELLOW}Warning: This is a suggestion. Review and execute at your own risk.{RESET}")
69+
print_color("Fetching command suggestion...", "CYAN")
70+
suggestion = llm_client.suggest_command(user_input, conversation_history)
71+
print_color("Suggested Command:", "GREEN")
72+
print_color(suggestion.command, "WHITE")
73+
print_color("Explanation: \n", "BLUE")
74+
print_color(suggestion.explanation, "BLUE")
75+
print_color("Warning: This is a suggestion. Review and execute at your own risk.", "YELLOW")
11076

11177
# Update conversation history
11278
conversation_history.append({"role": "user", "content": user_input})
@@ -117,8 +83,8 @@ def main():
11783
conversation_history = conversation_history[-16:]
11884

11985
except ValueError as e:
120-
print(f"{RED}{e}{RESET}")
121-
print("-" * 40,"\n")
86+
print_color(str(e), "RED")
87+
print("-" * 40, "\n")
12288

12389
if __name__ == "__main__":
12490
main()

snapshell/database.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)