1212
1313from . import exc , formats
1414from .common import EnvironmentMixin , TmuxMappingObject , \
15- TmuxRelationalObject , session_check_name
15+ TmuxRelationalObject , session_check_name , handle_option_error
1616from .window import Window
1717
1818logger = logging .getLogger (__name__ )
@@ -132,17 +132,10 @@ def new_window(self,
132132 window_shell = None ):
133133 """Return :class:`Window` from ``$ tmux new-window``.
134134
135- .. note::
136-
137- By default, this will make the window active. For the new window
138- to be created and not set to current, pass in ``attach=False``.
135+ By default, this will make the window active. For the new window
136+ to be created and not set to current, pass in ``attach=False``.
139137
140138 :param window_name: window name.
141-
142- .. code-block:: bash
143-
144- $ tmux new-window -n <window_name> -c <start_directory>
145-
146139 :type window_name: string
147140 :param start_directory: specifies the working directory in which the
148141 new window is created.
@@ -335,6 +328,8 @@ def set_option(self, option, value, g=False):
335328 :type value: bool
336329 :param global: check for option globally across all servers (-g)
337330 :type global: bool
331+ :raises: :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
332+ :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
338333
339334 """
340335
@@ -355,13 +350,7 @@ def set_option(self, option, value, g=False):
355350 )
356351
357352 if isinstance (proc .stderr , list ) and len (proc .stderr ):
358- error = proc .stderr [0 ]
359- if 'unknown option' in error :
360- raise exc .UnknownOption (error )
361- elif 'invalid option' in error :
362- raise exc .InvalidOption (error )
363-
364- raise ValueError ('tmux set-option stderr: %s' % error )
353+ handle_option_error (proc .stderr [0 ])
365354
366355 def show_options (self , option = None , g = False ):
367356 """Return a dict of options for the window.
@@ -425,11 +414,7 @@ def show_option(self, option, g=False):
425414 )
426415
427416 if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
428- error = cmd .stderr [0 ]
429- if 'unknown option' in error :
430- raise exc .UnknownOption (error )
431- else :
432- raise exc .LibTmuxException (error )
417+ handle_option_error (cmd .stderr [0 ])
433418
434419 if not len (cmd .stdout ):
435420 return None
0 commit comments