Coverage for cmds/ping.py: 92%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2ping.py
4contains ping()
5"""
7import os
8import subprocess
9import error
11async def ping(message, *args):
12 # pylint:disable=unused-argument
13 """
14 ping()
16 pings website
17 """
19 # check for excess args:
20 if len(args) > 1:
21 raise error.UnknownArgumentError
23 # check for args
24 if not args:
25 raise error.ArgumentRequiredError
27 # if windows
28 if os.name == "nt":
29 output = subprocess.run(
30 ["ping", args[0]],
31 check=False,
32 stdout=subprocess.PIPE
33 ).stdout.decode()
35 # if unix
36 else:
37 output = subprocess.run(
38 ["ping", "-c", "4", args[0]],
39 check=False,
40 stdout=subprocess.PIPE
41 ).stdout.decode()
43 # return
44 return f"""```{output}```"""