22import os
33import subprocess
44import sys
5+ import tempfile
56from rich .console import Console
67from rich .panel import Panel
78from rich .table import Table
89from rich .syntax import Syntax
10+ from rich .text import Text
911from .parser import parse_hacker_file
1012from .repl import run_repl
1113
1214console = Console ()
13- VERSION = "0.4 .0"
15+ VERSION = "0.5 .0"
1416HACKER_DIR = os .path .expanduser ("~/.hacker-lang" )
1517BIN_DIR = os .path .join (HACKER_DIR , "bin" )
1618
@@ -19,13 +21,14 @@ def ensure_hacker_dir():
1921 os .makedirs (os .path .join (HACKER_DIR , "libs" ), exist_ok = True )
2022
2123def display_welcome ():
22- banner = Text ("Welcome to Hacker Lang CLI! " , style = "bold magenta" )
24+ banner = Text ("Hacker Lang CLI" , style = "bold magenta" )
2325 banner .append ("\n Simple scripting for Debian-based Linux" , style = "italic cyan" )
26+ banner .append (f"\n Version { VERSION } " , style = "bold blue" )
2427 console .print (Panel (banner , expand = False ))
2528 help_command (show_banner = False )
2629
2730def run_command (file_path , verbose = False ):
28- deps , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
31+ deps , libs , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
2932 if errors :
3033 console .print (Panel ("\n " .join (errors ), title = "Syntax Errors" , style = "bold red" ))
3134 return False
@@ -38,12 +41,12 @@ def run_command(file_path, verbose=False):
3841 temp_sh .write (f'export { var } ="{ value } "\n ' )
3942
4043 for dep in deps :
41- check_cmd = generate_check_cmd ( dep )
42- if check_cmd :
44+ check_cmd = f"command -v { dep } &> /dev/null || (sudo apt update && sudo apt install -y { dep } )"
45+ if check_cmd and dep != "sudo" :
4346 temp_sh .write (f"{ check_cmd } \n " )
4447
4548 for include in includes :
46- lib_path = os .path .join (HACKER_DIR , "libs" , f" { include } .hacker" )
49+ lib_path = os .path .join (HACKER_DIR , "libs" , include , "main .hacker" )
4750 if os .path .exists (lib_path ):
4851 temp_sh .write (f"# Included from { include } \n " )
4952 with open (lib_path , 'r' ) as lib_file :
@@ -70,7 +73,7 @@ def run_command(file_path, verbose=False):
7073 os .unlink (temp_sh_path )
7174
7275def compile_command (file_path , output , verbose = False ):
73- deps , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
76+ deps , libs , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
7477 if errors :
7578 console .print (Panel ("\n " .join (errors ), title = "Syntax Errors" , style = "bold red" ))
7679 return False
@@ -97,7 +100,7 @@ def compile_command(file_path, output, verbose=False):
97100
98101def check_command (file_path , verbose = False ):
99102 console .print (Panel (f"Checking syntax of { file_path } " , title = "Hacker Lang Check" , style = "bold cyan" ))
100- deps , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
103+ deps , libs , vars , cmds , includes , errors = parse_hacker_file (file_path , verbose )
101104 if errors :
102105 console .print (Panel ("\n " .join (errors ), title = "Syntax Errors" , style = "bold red" ))
103106 return False
@@ -110,16 +113,19 @@ def init_command(file_path, verbose=False):
110113 return False
111114
112115 template = """! Hacker Lang template script
113- // sudo ! Required for privileged commands
114- // apt ! Package manager
115- @USER=admin ! Set USER variable
116- =2 > echo "Hello from $USER" ! Print twice
117- ? [ -d /tmp ] > echo "/tmp exists" ! Conditional
116+ // sudo ! System dependency for privileged commands
117+ # bit-jump ! Custom library to be installed
118+ @USER=admin ! Set environment variable
119+ @LOG_DIR=/var/log/hacker
120+ =2 > echo "Hello from $USER" ! Loop twice
121+ ? [ -d /tmp ] > echo "/tmp exists" ! Conditional check
122+ & sleep 10 ! Run command in background
118123# util ! Include util library
119- > sudo apt update ! Update packages
124+ > sudo apt update ! Update system packages
120125[
121126Configuration
122127Author: Hacker Lang User
128+ Purpose: System update automation
123129]
124130"""
125131 try :
@@ -152,7 +158,7 @@ def clean_command(verbose=False):
152158def install_command (libname , verbose = False ):
153159 bin_path = os .path .join (BIN_DIR , "hacker-library" )
154160 if not os .path .exists (bin_path ):
155- console .print ("[bold red]hacker-library not found.[/bold red]" )
161+ console .print ("[bold red]hacker-library not found in ~/.hacker-lang/bin/ .[/bold red]" )
156162 return False
157163
158164 cmd = ['node' , bin_path , 'install' , libname ]
@@ -169,7 +175,7 @@ def install_command(libname, verbose=False):
169175def update_command (verbose = False ):
170176 bin_path = os .path .join (BIN_DIR , "hacker-library" )
171177 if not os .path .exists (bin_path ):
172- console .print ("[bold red]hacker-library not found.[/bold red]" )
178+ console .print ("[bold red]hacker-library not found in ~/.hacker-lang/bin/ .[/bold red]" )
173179 return False
174180
175181 cmd = ['node' , bin_path , 'update' ]
@@ -201,7 +207,7 @@ def help_command(show_banner=True):
201207 ("check" , "Check syntax" , "file" ),
202208 ("init" , "Create template .hacker file" , "file" ),
203209 ("clean" , "Remove temp .sh files" , "" ),
204- ("install" , "Install a library" , "libname" ),
210+ ("install" , "Install a custom library" , "libname" ),
205211 ("update" , "Check for library updates" , "" ),
206212 ("repl" , "Start interactive REPL" , "" ),
207213 ("version" , "Show CLI version" , "" ),
@@ -215,9 +221,11 @@ def help_command(show_banner=True):
215221 console .print ("\n Syntax Example:" )
216222 console .print (Syntax (
217223 """// sudo
224+ # bit-jump
218225@USER=admin
219226=2 > echo $USER
220227? [ -d /tmp ] > echo OK
228+ & sleep 10
221229# util
222230> sudo apt update
223231[
0 commit comments