Skip to content

Commit

Permalink
fix: refactor out __name__ override, mypy lower version
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Jul 21, 2024
1 parent b2e3dcb commit 9b62a2f
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 36 deletions.
24 changes: 5 additions & 19 deletions fsociety/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def agreement():
items[module_name(item)] = item
for tool in item.__tools__:
subcommands.append(
{"parent": item.__name__, "tool": tool, "name": tool.__str__()}
{
"parent": item.__name__.split(".")[-1],
"tool": tool,
"name": tool.__str__(),
}
)
commands = list(items.keys()) + list(BUILTIN_FUNCTIONS.keys())

Expand All @@ -140,24 +144,6 @@ def doexcept(error: Exception, style: Optional[Union[str, Style]] = "red") -> No
errorhandle(e, style=style)


"""
# we know it's not a command, let's see if it's a subcommand
try:
subcmd = next((subcommand for subcommand in subcommands if subcommand["name"] == selected_command))
if subcmd:
# execute parent cli, pass subcmd.name -> cli
return subcmd["tool"].run()
# looks like we didn't find a subcommand, either
return errorhandle(Exception("Invalid Command"), style="bold yellow")
except Exception as error:
return errorhandle(error)
"""

"""old
return errorhandle(Exception("Invalid Command"), style="bold yellow")
"""


def mainloop():
agreement()
console.print(choice(BANNERS), style="red", highlight=False)
Expand Down
6 changes: 5 additions & 1 deletion fsociety/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
config = get_config()


def input_wait():
input("\nPress [ENTER] to continue... ")


def errorhandle(error: Exception, style: Optional[Union[str, Style]] = "red") -> None:
console.print(str(error), style=style)
if config.getboolean("fsociety", "development"):
console.print_exception()
input("Press [Enter/Return] to return to menu... ")
input_wait()
return


Expand Down
10 changes: 2 additions & 8 deletions fsociety/core/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ def prompt(path="", base_path="~"):
return f"\nfsociety {encoded_path}# "


def input_wait():
input("\nPress [ENTER] to continue... ")


def run_tool(tool, selected_tool: str):
if hasattr(tool, "install") and not tool.installed():
tool.install()
Expand Down Expand Up @@ -116,7 +112,7 @@ def tools_cli(name, tools, links=True):
console.print(table)
console.print("back", style="command")
set_readline(list(tools_dict.keys()) + BACK_COMMANDS)
selected_tool = input(prompt(name.split(".")[-1])).strip()
selected_tool = input(prompt(name.split(".")[-2])).strip()
if selected_tool not in tools_dict:
if selected_tool in BACK_COMMANDS:
return
Expand All @@ -125,9 +121,7 @@ def tools_cli(name, tools, links=True):
console.print("Invalid Command", style="bold yellow")
return tools_cli(name, tools, links)
tool = tools_dict.get(selected_tool)
run_tool(tool, selected_tool)

return input_wait()
return run_tool(tool, selected_tool)


def confirm(message="Do you want to?"):
Expand Down
2 changes: 1 addition & 1 deletion fsociety/core/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def uninstall(self) -> None:
target_os = config.get("fsociety", "os")
command = "exit 1"
if isinstance(install, dict):
if target_os == "macos" and "brew" in install and which("brew"):
if "brew" in install and which("brew"):
brew_opts = install.get("brew")
command = f"brew uninstall {brew_opts}"
elif target_os == "windows" and "winget" in install and which("winget"):
Expand Down
1 change: 0 additions & 1 deletion fsociety/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,3 @@ def cli():
tools_cli(__name__, __tools__, links=False)


__name__ = "utilities"
1 change: 0 additions & 1 deletion fsociety/information_gathering/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ def cli():
tools_cli(__name__, __tools__)


__name__ = "information_gathering"
1 change: 0 additions & 1 deletion fsociety/networking/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ def cli():
tools_cli(__name__, __tools__)


__name__ = "networking"
1 change: 0 additions & 1 deletion fsociety/obfuscation/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ def cli():
tools_cli(__name__, __tools__)


__name__ = "obfuscation"
1 change: 0 additions & 1 deletion fsociety/passwords/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ def cli():
tools_cli(__name__, __tools__)


__name__ = "passwords"
1 change: 0 additions & 1 deletion fsociety/web_apps/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ def cli():
tools_cli(__name__, __tools__)


__name__ = "web_apps"
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[mypy]
python_version = 3.13
python_version = 3.8
files = fsociety

[mypy-git.*]
Expand Down

0 comments on commit 9b62a2f

Please sign in to comment.