Skip to content

Commit

Permalink
fix: typos, add optional wait_input
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Jul 21, 2024
1 parent ec08496 commit 475bd7b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
15 changes: 7 additions & 8 deletions fsociety/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,15 @@ def print_menu_items():
console.print(Columns(cols, equal=True, expand=True))

for key in BUILTIN_FUNCTIONS:
print()
console.command(key)
console.command(f"\n{key}")


def agreement():
while not config.getboolean("fsociety", "agreement"):
clear_screen()
console.warning(TERMS)
agree = input("You must agree to our terms and conditions first (Y/n) ")
if agree.lower()[0] == "y":
console.input_error(TERMS)
agree = input("You must agree to our terms and conditions first (y/N) ")
if len(agree) and agree[0].lower() == "y":
config.set("fsociety", "agreement", "true")


Expand Down Expand Up @@ -145,10 +144,10 @@ def sub_command_has(sbc):
if subcommand is not None:
# execute parent cli, pass subcmd.name -> cli
return run_tool(subcommand["tool"], subcommand["name"])
return console.warning("Invalid Command")
return console.input_error("Invalid Command", True)
except StopIteration:
# looks like we didn't find a subcommand, either
return console.warning("Invalid Command")
return console.input_error("Invalid Command", True)
except Exception as error:
return console.handle_error(error)
if selected_command in BUILTIN_FUNCTIONS:
Expand Down Expand Up @@ -185,7 +184,7 @@ def interactive():
set_readline(commands)
mainloop()
except KeyboardInterrupt:
console.print("\nExitting...")
console.print("\nExiting...")
write_config(config)
sys.exit(0)

Expand Down
30 changes: 17 additions & 13 deletions fsociety/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,36 @@ class Console(RichConsole):

def __init__(self, log_level: ConsoleLogLevel = ConsoleLogLevel.ERROR):
super().__init__(theme=fsociety_theme)
self.log_level = ConsoleLogLevel(log_level)

def set_log_level(self, level: ConsoleLogLevel):
self.log_level = level
def set_log_level(self, level: str):
self.log_level = ConsoleLogLevel(level)

def debug(self, message: str, error: Exception = None):
def debug(self, message: str, error: Exception = None, wait_input: bool = False):
if self.log_level == ConsoleLogLevel.DEBUG:
self.print(message, style="debug")
if error:
self.print_exception()
if wait_input:
input_wait()

def info(self, message: str):
def info(self, message: str, wait_input: bool = False):
if self.log_level in [ConsoleLogLevel.DEBUG, ConsoleLogLevel.INFO]:
self.print(message, style="info")
if wait_input:
input_wait()

def warning(self, message: str):
if self.log_level in [
ConsoleLogLevel.DEBUG,
ConsoleLogLevel.INFO,
ConsoleLogLevel.WARNING,
]:
self.print(message, style="warning")
def input_error(self, message: str, wait_input: bool = False):
self.print(message, style="warning")
if wait_input:
input_wait()

def error(self, message: str):
def error(self, message: str, wait_input: bool = False):
self.print(message, style="error")
if self.log_level == ConsoleLogLevel.DEBUG:
self.print_exception()
if wait_input:
input_wait()

def handle_error(self, error: Exception):
self.error(str(error))
Expand All @@ -85,4 +89,4 @@ def command(self, message: str):

default_log_level = config.get("fsociety", "log_level")

console = Console(default_log_level)
console = Console(ConsoleLogLevel(default_log_level))
2 changes: 1 addition & 1 deletion fsociety/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"os": CURRENT_PLATFORM,
"host_file": "hosts.txt",
"usernames_file": "usernames.txt",
"log_level": "error",
"log_level": "info",
}


Expand Down
8 changes: 3 additions & 5 deletions fsociety/core/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ def tools_cli(name, tools, links=True):
return
if selected_tool == "exit":
raise KeyboardInterrupt
console.warn("Invalid Command")
console.warn("Invalid Command", True)
return tools_cli(name, tools, links)
tool = tools_dict.get(selected_tool)
return run_tool(tool, selected_tool)


def confirm(message="Do you want to?"):
response = input(f"{message} (y/n): ").lower()
if response:
return response[0] == "y"
return False
agree = input(f"{message} (y/N): ")
return len(agree) and agree[0].lower() == "y"

0 comments on commit 475bd7b

Please sign in to comment.