better --help
This commit is contained in:
parent
865bc9d0e2
commit
8179aff7b2
1 changed files with 18 additions and 10 deletions
|
@ -25,7 +25,7 @@ class Pyprland:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.plugins: dict[str, Plugin] = {}
|
self.plugins: dict[str, Plugin] = {}
|
||||||
|
|
||||||
async def load_config(self):
|
async def load_config(self, init=True):
|
||||||
self.config = json.loads(
|
self.config = json.loads(
|
||||||
open(os.path.expanduser(CONFIG_FILE), encoding="utf-8").read()
|
open(os.path.expanduser(CONFIG_FILE), encoding="utf-8").read()
|
||||||
)
|
)
|
||||||
|
@ -34,12 +34,14 @@ class Pyprland:
|
||||||
modname = name if "." in name else f"pyprland.plugins.{name}"
|
modname = name if "." in name else f"pyprland.plugins.{name}"
|
||||||
try:
|
try:
|
||||||
plug = importlib.import_module(modname).Extension(name)
|
plug = importlib.import_module(modname).Extension(name)
|
||||||
|
if init:
|
||||||
await plug.init()
|
await plug.init()
|
||||||
self.plugins[name] = plug
|
self.plugins[name] = plug
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading plugin {name}: {e}")
|
print(f"Error loading plugin {name}: {e}")
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
if init:
|
||||||
await self.plugins[name].load_config(self.config)
|
await self.plugins[name].load_config(self.config)
|
||||||
|
|
||||||
async def _callHandler(self, full_name, *params):
|
async def _callHandler(self, full_name, *params):
|
||||||
|
@ -136,16 +138,22 @@ async def run_daemon():
|
||||||
|
|
||||||
async def run_client():
|
async def run_client():
|
||||||
if sys.argv[1] == "--help":
|
if sys.argv[1] == "--help":
|
||||||
|
manager = Pyprland()
|
||||||
|
await manager.load_config(init=False)
|
||||||
print(
|
print(
|
||||||
"""Commands:
|
"""Syntax: pypr [command]
|
||||||
reload
|
|
||||||
show <scratchpad name>
|
|
||||||
hide <scratchpad name>
|
|
||||||
toggle <scratchpad name>
|
|
||||||
|
|
||||||
If arguments are ommited, runs the daemon which will start every configured command.
|
If command is ommited, runs the daemon which will start every configured command.
|
||||||
"""
|
|
||||||
|
Commands:
|
||||||
|
|
||||||
|
reload"""
|
||||||
)
|
)
|
||||||
|
for plug in manager.plugins.values():
|
||||||
|
for name in dir(plug):
|
||||||
|
if name.startswith("run_") and callable(getattr(plug, name)):
|
||||||
|
print(f" {name[4:]:20} (from {plug.name})")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
_, writer = await asyncio.open_unix_connection(CONTROL)
|
_, writer = await asyncio.open_unix_connection(CONTROL)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue