Skip to content

Commit fb83b2f

Browse files
authored
Merge pull request #53 from chadrockey/fields
Add field options and field option helper
2 parents b96c984 + f0dd962 commit fb83b2f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

nmcli/_device.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import List, Tuple
33

44
from ._exception import ConnectionActivateFailedException
5-
from ._helper import add_wait_option_if_needed
5+
from ._helper import add_wait_option_if_needed, add_fields_option_if_needed
66
from ._system import SystemCommand, SystemCommandInterface
77
from .data.device import Device, DeviceDetails, DeviceWifi
88
from .data.hotspot import Hotspot
@@ -42,10 +42,10 @@ def __call__(self) -> List[Device]:
4242
def status(self) -> List[Device]:
4343
raise NotImplementedError
4444

45-
def show(self, ifname: str) -> DeviceDetails:
45+
def show(self, ifname: str, fields: str) -> DeviceDetails:
4646
raise NotImplementedError
4747

48-
def show_all(self) -> List[DeviceDetails]:
48+
def show_all(self, fields: str) -> List[DeviceDetails]:
4949
raise NotImplementedError
5050

5151
def connect(self, ifname: str, wait: int = None) -> None:
@@ -101,8 +101,9 @@ def status(self) -> List[Device]:
101101
results.append(Device.parse(row))
102102
return results
103103

104-
def show(self, ifname: str) -> DeviceDetails:
105-
r = self._syscmd.nmcli(['device', 'show', ifname])
104+
def show(self, ifname: str, fields: str = None) -> DeviceDetails:
105+
cmd = add_fields_option_if_needed(fields) + ['device', 'show', ifname]
106+
r = self._syscmd.nmcli(cmd)
106107
results = {}
107108
for row in r.split('\n'):
108109
m = re.search(r'^(\S+):\s*([\S\s]+)\s*', row)
@@ -111,8 +112,9 @@ def show(self, ifname: str) -> DeviceDetails:
111112
results[key] = None if value in ('--', '""') else value
112113
return results
113114

114-
def show_all(self) -> List[DeviceDetails]:
115-
r = self._syscmd.nmcli(['device', 'show'])
115+
def show_all(self, fields: str = None) -> List[DeviceDetails]:
116+
cmd = add_fields_option_if_needed(fields) + ['device', 'show']
117+
r = self._syscmd.nmcli(cmd)
116118
results = []
117119
details: DeviceDetails = {}
118120
for row in r.split('\n'):

nmcli/_helper.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
def add_wait_option_if_needed(wait: int = None) -> List[str]:
55
return [] if wait is None else ['--wait', str(wait)]
6+
7+
def add_fields_option_if_needed(fields: str = None) -> List[str]:
8+
return [] if fields is None else ['-f', fields]

0 commit comments

Comments
 (0)