/ main.py
main.py
 1  import sys
 2  import interpriter  # Assuming this is your safe custom module
 3  
 4  def main():
 5      print("Welcome to binbash")
 6      print("The language that likes binary")
 7  
 8      # Check for minimum required args
 9      if len(sys.argv) < 3:
10          print("Usage: python script.py <command> <arg>")
11          print("Commands:")
12          print("  run <filename>")
13          print("  create-persistent-storage <size>")
14          return
15  
16      command = sys.argv[1]
17      arg = sys.argv[2]
18  
19      if command == "run":
20          # Basic validation to avoid dangerous paths, can add more checks
21          if ".." in arg or arg.startswith("/"):
22              print("Invalid filename")
23              return
24  
25          with open(arg, "r") as f:
26              code = f.read()
27  
28          interpriter.interprit(code)
29  
30  #        except FileNotFoundError:
31  #          print(f"File not found: {arg}")
32  #        except IOError as e:
33  #           print(f"Error reading file: {e}")
34  #        except Exception as e:
35  #            print(f"An error occurred while interpreting the file: {e}")
36  
37      elif command == "create-persistent-storage":
38          try:
39              size = int(arg)
40              if size <= 0:
41                  print("Size must be a positive integer")
42                  return
43  
44              interpriter.createMemoryFile(size)
45          except ValueError:
46              print("Invalid size: must be an integer")
47          except Exception as e:
48              print(f"An error occurred while creating persistent storage: {e}")
49  
50      else:
51          print(f"Unknown command: {command}")
52  
53  if __name__ == "__main__":
54      main()