summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmonitor-menu.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/monitor-menu.py b/monitor-menu.py
index 8a77c41..d450ba8 100755
--- a/monitor-menu.py
+++ b/monitor-menu.py
@@ -45,6 +45,7 @@ class Profile:
name: str
monitors: list[Monitor] = dataclasses.field(default_factory=list)
+ identifier: str | None = None
xrandr_opts: list[str] = dataclasses.field(default_factory=list)
@classmethod
@@ -112,7 +113,13 @@ class MonitorMenu:
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--log-level", "--loglevel", type=LogLevel, default="info")
- parser.add_argument("--index", type=int, required=False)
+ subparser = parser.add_subparsers(dest="command")
+ subparser.add_parser("run")
+ apply_parser = subparser.add_parser("apply")
+ identifier_group = apply_parser.add_mutually_exclusive_group(required=True)
+ identifier_group.add_argument("--index", type=int)
+ identifier_group.add_argument("--id", type=str)
+
args = parser.parse_args()
logging.basicConfig(level=args.log_level.numerical_level)
@@ -121,13 +128,20 @@ def main():
data = json.load(fh)
profiles = [Profile.from_json_dict(item) for item in data]
- if args.index is None:
- MonitorMenu(profiles).run()
- else:
- try:
- profiles[args.index].apply()
- except IndexError:
- raise NoMatchingProfile from None
+ match args.command:
+ case "run" | None:
+ MonitorMenu(profiles).run()
+ case "apply":
+ if args.index is not None:
+ try:
+ profiles[args.index].apply()
+ except IndexError:
+ raise NoMatchingProfile from None
+ else:
+ try:
+ next(filter(lambda p: p.identifier == args.id, profiles)).apply()
+ except StopIteration:
+ raise NoMatchingProfile from None
if __name__ == '__main__':