tools/gdctl: Make argcomplete optional
While having automatic completions is a very nice feature of gdctl (I had suggested to use it too :)), it's not something that distros may have by default and in particular it's not a package in main in ubuntu. So, make the code less restrictive on completions, since completions is not a core functionality of the tool and it can definitely work without them. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4279>
This commit is contained in:
parent
33761eb2af
commit
cfdc63df2d
35
tools/gdctl
35
tools/gdctl
@ -1,14 +1,21 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import argcomplete
|
||||
import sys
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import NamedTuple, Any
|
||||
from typing import NamedTuple, Any, Optional
|
||||
from types import ModuleType
|
||||
from gi.repository import GLib, Gio # type: ignore
|
||||
from enum import Enum, Flag
|
||||
from argcomplete.completers import BaseCompleter, SuppressCompleter
|
||||
|
||||
argcomplete: Optional[ModuleType] = None
|
||||
BaseCompleter: Any
|
||||
try:
|
||||
import argcomplete
|
||||
from argcomplete.completers import BaseCompleter
|
||||
except ModuleNotFoundError:
|
||||
BaseCompleter = object
|
||||
|
||||
NAME = "org.gnome.Mutter.DisplayConfig"
|
||||
INTERFACE = "org.gnome.Mutter.DisplayConfig"
|
||||
@ -1447,15 +1454,19 @@ if __name__ == "__main__":
|
||||
type=str,
|
||||
).completer = MonitorCompleter() # type: ignore[attr-defined]
|
||||
|
||||
for action in [
|
||||
GroupAction,
|
||||
SubGroupAction,
|
||||
AppendToGroup,
|
||||
AppendToSubGroup,
|
||||
AppendToGlobal,
|
||||
]:
|
||||
argcomplete.safe_actions.add(action)
|
||||
argcomplete.autocomplete(parser, default_completer=SuppressCompleter) # type: ignore[arg-type]
|
||||
if argcomplete:
|
||||
for action in [
|
||||
GroupAction,
|
||||
SubGroupAction,
|
||||
AppendToGroup,
|
||||
AppendToSubGroup,
|
||||
AppendToGlobal,
|
||||
]:
|
||||
argcomplete.safe_actions.add(action)
|
||||
|
||||
argcomplete.autocomplete(
|
||||
parser, default_completer=argcomplete.SuppressCompleter
|
||||
) # type: ignore[arg-type]
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user