Skip to content

Commit 8059c9a

Browse files
committed
feat: Add has_target_in_args helper
1 parent 0de4483 commit 8059c9a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/libtmux/common.py

+37
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,43 @@ def session_check_name(session_name: t.Optional[str]) -> None:
445445
raise exc.BadSessionName(reason="contains colons", session_name=session_name)
446446

447447

448+
def has_target_in_args(val: t.List[t.Any]) -> bool:
449+
"""Return True if target in args.
450+
451+
Parameters
452+
----------
453+
val : any
454+
Any value to check if target is in it.
455+
456+
Returns
457+
-------
458+
bool
459+
True if target in args.
460+
461+
Examples
462+
--------
463+
>>> has_target_in_args(['-t',])
464+
False
465+
>>> has_target_in_args(['-t', 'mytarget'])
466+
True
467+
>>> has_target_in_args(['-tmytarget'])
468+
True
469+
"""
470+
for idx, item in enumerate(val):
471+
if not isinstance(item, str):
472+
continue
473+
474+
if item == "-t":
475+
try:
476+
val[idx + 1]
477+
except IndexError:
478+
return False
479+
return True
480+
elif item.startswith("-t"):
481+
return True
482+
return False
483+
484+
448485
def handle_option_error(error: str) -> t.Type[exc.OptionError]:
449486
"""Raise exception if error in option command found.
450487

0 commit comments

Comments
 (0)