sysll
Advanced tools
| en: | ||
| sysll: | ||
| status: | ||
| clear: "Cleared the screen successfully." | ||
| list_files: "Listing files in the current directory..." | ||
| network_info: "Fetching network configuration..." | ||
| process_info: "Retrieving running processes..." | ||
| kill_process: "Trying to kill process %{pid}..." | ||
| sys: "Getting system information..." | ||
| errors: | ||
| list_files_failed: | ||
| code: "SYSLL - E001" | ||
| message: "Failed to list files. Check permissions or flags." | ||
| type: "PermissionError" | ||
| network_info_failed: | ||
| code: "SYSLL - E002" | ||
| message: "Could not retrieve network info." | ||
| type: "NetworkError" | ||
| process_info_failed: | ||
| code: "SYSLL - E003" | ||
| message: "Error retrieving process information." | ||
| type: "ProcessError" | ||
| kill_process_failed: | ||
| code: "SYSLL - E004" | ||
| message: "Could not kill process %{pid}." | ||
| type: "ProcessError" | ||
| sys_failed: | ||
| code: "SYSLL - E005" | ||
| message: "Could not retrieve system information." | ||
| type: "SystemError" | ||
| clear_failed: | ||
| code: "SYSLL - E006" | ||
| message: "Failed to clear the terminal screen." | ||
| type: "SystemCommandError" | ||
| unknown_error: | ||
| code: "SYSLL - E999" | ||
| message: "An unknown error occurred." | ||
| type: "UnknownError" |
| pt: | ||
| sysll: | ||
| status: | ||
| clear: "Tela limpa com sucesso." | ||
| list_files: "Listando arquivos no diretório atual..." | ||
| network_info: "Obtendo informações da rede..." | ||
| process_info: "Recuperando processos em execução..." | ||
| kill_process: "Tentando encerrar o processo %{pid}..." | ||
| sys: "Obtendo informações do sistema..." | ||
| errors: | ||
| list_files_failed: | ||
| code: "SYSLL - E001" | ||
| message: "Falha ao listar os arquivos. Verifique permissões ou flags." | ||
| type: "ErroDePermissao" | ||
| network_info_failed: | ||
| code: "SYSLL - E002" | ||
| message: "Não foi possível obter informações da rede." | ||
| type: "ErroDeRede" | ||
| process_info_failed: | ||
| code: "SYSLL - E003" | ||
| message: "Erro ao recuperar informações dos processos." | ||
| type: "ErroDeProcesso" | ||
| kill_process_failed: | ||
| code: "SYSLL - E004" | ||
| message: "Não foi possível encerrar o processo %{pid}." | ||
| type: "ErroDeProcesso" | ||
| sys_failed: | ||
| code: "SYSLL - E005" | ||
| message: "Não foi possível obter informações do sistema." | ||
| type: "ErroDeSistema" | ||
| clear_failed: | ||
| code: "SYSLL - E006" | ||
| message: "Falha ao limpar a tela do terminal." | ||
| type: "ErroDeComandoDoSistema" | ||
| unknown_error: | ||
| code: "SYSLL - E999" | ||
| message: "Ocorreu um erro desconhecido." | ||
| type: "ErroDesconhecido" |
+64
-106
| require_relative 'sysverify' | ||
| module CMD | ||
| module Utils | ||
| def execute_command(command, error_key, args = {}) | ||
| success = system(command) | ||
| unless success | ||
| error = I18n.t("errors.#{error_key}", **args) | ||
| print_error(error) | ||
| end | ||
| end | ||
| def print_error(error) | ||
| puts "Error Code: #{error[:code]}" | ||
| puts "Error Type: #{error[:type]}" | ||
| puts "Message: #{error[:message]}" | ||
| end | ||
| end | ||
| class CALL | ||
| extend CMD::Utils | ||
| def self.clear | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| system('cls') | ||
| else | ||
| system('clear') | ||
| end | ||
| cmd_clear = SYSll::VERIFY.os == :windows ? 'cls' : 'clear' | ||
| execute_command(cmd_clear, "clear_failed") | ||
| end | ||
| def self.list_files(flags = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| system('dir') | ||
| else | ||
| if flags.nil? | ||
| system("ls") | ||
| else | ||
| system("ls #{flags}") | ||
| end | ||
| end | ||
| cmd_lf = if SYSll::VERIFY.os == :windows | ||
| 'dir' | ||
| else | ||
| flags.nil? ? "ls" : "ls #{flags}" | ||
| end | ||
| execute_command(cmd_lf, "list_files_failed") | ||
| end | ||
| def self.network_info | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| system('ipconfig') | ||
| else | ||
| system('ifconfig') | ||
| end | ||
| cmd_netinf = SYSll::VERIFY.os == :windows ? 'ipconfig' : 'ifconfig' | ||
| execute_command(cmd_netinf, "network_info_failed") | ||
| end | ||
| def self.process_info | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| system("tasklist") | ||
| else | ||
| system("ps aux") | ||
| end | ||
| cmd_process = SYSll::VERIFY.os == :windows ? 'tasklist' : 'ps aux' | ||
| execute_command(cmd_process, "process_info_failed") | ||
| end | ||
| def self.kill_process(pid, flag = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| if flags.nil? | ||
| system("taskkill /PID #{pid}") | ||
| else | ||
| system("taskkill /PID #{pid} #{flag}") | ||
| end | ||
| else | ||
| if flags.nil? | ||
| system("kill #{pid}") | ||
| else | ||
| system("kill #{flag} #{pid}") | ||
| end | ||
| end | ||
| cmd_kill = if SYSll::VERIFY.os == :windows | ||
| flag.nil? ? "taskkill /PID #{pid}" : "taskkill /PID #{pid} #{flag}" | ||
| else | ||
| flag.nil? ? "kill #{pid}" : "kill #{flag} #{pid}" | ||
| end | ||
| execute_command(cmd_kill, "kill_process_failed", pid: pid) | ||
| end | ||
| def self.sys(flags = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| system("systeminfo") | ||
| else | ||
| if flags.nil? | ||
| system("uname") | ||
| else | ||
| system("uname #{flags}") | ||
| end | ||
| end | ||
| cmd_sys = SYSll::VERIFY.os == :windows ? "systeminfo" : flags.nil? ? "uname" : "uname #{flags}" | ||
| execute_command(cmd_sys, "sys_failed") | ||
| end | ||
@@ -77,76 +62,49 @@ end | ||
| class KERNEL | ||
| extend CMD::Utils | ||
| DELIMITERS = ["\n"] | ||
| REGSPLIT = Regexp.union(DELIMITERS) | ||
| def self.clear | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| return Kernel.`("cls") | ||
| else | ||
| return Kernel.`("clear") | ||
| end | ||
| krn_clear = SYSll::VERIFY.os == :windows ? Kernel.`("cls") : Kernel.`("clear") | ||
| return krn_clear | ||
| end | ||
| def self.list_files(flags = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| return Kernel.`("dir").split(REGSPLIT) | ||
| else | ||
| if flags.nil? | ||
| return Kernel.`("ls").split(REGSPLIT) | ||
| else | ||
| return Kernel.`("ls #{flags}").split(REGSPLIT) | ||
| end | ||
| end | ||
| krn_lf = SYSll::VERIFY.os == :windows ? Kernel.`("dir").split(REGSPLIT) : flags.nil? ? Kernel.`("ls").split(REGSPLIT) : Kernel.`("ls #{flags}").split(REGSPLIT) | ||
| return krn_lf | ||
| end | ||
| def self.network_info | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| return Kernel.`("ipconfig").split(REGSPLIT) | ||
| else | ||
| return Kernel.`("ifconfig").split(REGSPLIT) | ||
| end | ||
| krn_netinf = SYSll::VERIFY.os == :windows ? Kernel.`("ipconfig").split(REGSPLIT) : Kernel.`("ifconfig").split(REGSPLIT) | ||
| return krn_netinf | ||
| end | ||
| def self.process_info | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| return Kernel.`("tasklist") | ||
| else | ||
| return Kernel.`("ps aux").split(REGSPLIT) | ||
| end | ||
| krn_process = SYSll::VERIFY.os == :windows ? Kernel.`("tasklist") : Kernel.`("ps aux").split(REGSPLIT) | ||
| return krn_process | ||
| end | ||
| def self.kill_process(pid, flag = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| if flags.nil? | ||
| return Kernel.`("taskill /PID #{pid}").split(REGSPLIT) | ||
| else | ||
| return Kernel.`("taskill /PID #{pid} #{flag}").split(REGSPLIT) | ||
| end | ||
| else | ||
| if flags.nil? | ||
| return Kernel.`("kill #{pid}").split(REGSPLIT) | ||
| else | ||
| return Kernel.`("kill #{flag} #{pid}").split(REGSPLIT) | ||
| end | ||
| end | ||
| krn_kill = if SYSll::VERIFY.os == :windows | ||
| flags.nil? ? Kernel.`("taskill /PID #{pid}").split(REGSPLIT) : Kernel.`("taskill /PID #{pid} #{flag}").split(REGSPLIT) | ||
| else | ||
| flags.nil? ? Kernel.`("kill #{pid}").split(REGSPLIT) : Kernel.`("kill #{flag} #{pid}").split(REGSPLIT) | ||
| end | ||
| return krn_kill | ||
| end | ||
| def self.sys(flags = nil) | ||
| case SYSll::VERIFY.os | ||
| when :windows | ||
| return Kernel.`("systeminfo") | ||
| else | ||
| if flags.nil? | ||
| return Kernel.`("uname").split(REGSPLIT) | ||
| else | ||
| uname_delimiters = ["\n", " "] | ||
| reguname = Regexp.union(uname_delimiters) | ||
| return Kernel.`("uname #{flags}").split(reguname) | ||
| end | ||
| end | ||
| krn_sys = if SYSll::VERIFY.os == :windows | ||
| Kernel.`("systeminfo") | ||
| else | ||
| if flags.nil? | ||
| Kernel.`("uname").split(REGSPLIT) | ||
| else | ||
| uname_delimiters = ["\n", " "] | ||
| reguname = Regexp.union(uname_delimiters) | ||
| return Kernel.`("uname #{flags}").split(reguname) | ||
| end | ||
| end | ||
| return krn_sys | ||
| end | ||
| end | ||
| end |
+5
-0
| require_relative 'sysverify' | ||
| require_relative 'cmd' | ||
| require 'i18n' | ||
| local_path = File.expand_path("../../locales/*.yml", __FILE__) | ||
| I18n.load_path += Dir[local_path] | ||
| I18n.default_locale = :en | ||
| module SYSll | ||
@@ -5,0 +10,0 @@ class CALL |