@@ -807,6 +807,57 @@ def _show_options_raw(
807
807
808
808
return self .cmd ("show-options" , * flags )
809
809
810
+ def _show_options_dict (
811
+ self ,
812
+ g : t .Optional [bool ] = False ,
813
+ _global : t .Optional [bool ] = False ,
814
+ scope : t .Optional [
815
+ t .Union [OptionScope , _DefaultOptionScope ]
816
+ ] = DEFAULT_OPTION_SCOPE ,
817
+ include_hooks : t .Optional [bool ] = None ,
818
+ include_inherited : t .Optional [bool ] = None ,
819
+ ) -> "UntypedOptionsDict" :
820
+ """Return dict of options for the target.
821
+
822
+ Parameters
823
+ ----------
824
+ g : str, optional
825
+ Pass ``-g`` flag for global variable, default False.
826
+
827
+ Examples
828
+ --------
829
+ >>> import typing as t
830
+ >>> from libtmux.common import tmux_cmd
831
+ >>> from libtmux.constants import OptionScope
832
+
833
+ >>> class MyServer(OptionMixin):
834
+ ... socket_name = server.socket_name
835
+ ... def cmd(self, cmd: str, *args: object):
836
+ ... cmd_args: t.List[t.Union[str, int]] = [cmd]
837
+ ... if self.socket_name:
838
+ ... cmd_args.insert(0, f"-L{self.socket_name}")
839
+ ... cmd_args.insert(0, "-f/dev/null")
840
+ ... return tmux_cmd(*cmd_args, *args)
841
+ ...
842
+ ... default_option_scope = OptionScope.Server
843
+
844
+ >>> MyServer()._show_options_dict()
845
+ {...}
846
+
847
+ >>> isinstance(MyServer()._show_options_dict(), dict)
848
+ True
849
+ """
850
+ cmd = self ._show_options_raw (
851
+ _global = _global ,
852
+ scope = scope ,
853
+ include_hooks = include_hooks ,
854
+ include_inherited = include_inherited ,
855
+ )
856
+
857
+ return parse_options_to_dict (
858
+ io .StringIO ("\n " .join (cmd .stdout )),
859
+ )
860
+
810
861
def _show_options (
811
862
self ,
812
863
g : t .Optional [bool ] = False ,
@@ -844,7 +895,7 @@ def _show_options(
844
895
>>> MyServer()._show_options()
845
896
{...}
846
897
"""
847
- cmd = self ._show_options_raw (
898
+ dict_output = self ._show_options_dict (
848
899
_global = _global ,
849
900
scope = scope ,
850
901
include_hooks = include_hooks ,
@@ -853,11 +904,7 @@ def _show_options(
853
904
854
905
output_exploded = convert_values (
855
906
explode_complex (
856
- explode_arrays (
857
- parse_options_to_dict (
858
- io .StringIO ("\n " .join (cmd .stdout )),
859
- ),
860
- ),
907
+ explode_arrays (dict_output ),
861
908
),
862
909
)
863
910
@@ -913,6 +960,12 @@ def _show_option_raw(
913
960
914
961
>>> MyServer()._show_option_raw('exit-unattached', _global=True).stdout
915
962
['exit-unattached off']
963
+
964
+ >>> isinstance(MyServer()._show_option_raw('exit-unattached', _global=True).stdout, list)
965
+ True
966
+
967
+ >>> isinstance(MyServer()._show_option_raw('exit-unattached', _global=True).stdout[0], str)
968
+ True
916
969
"""
917
970
if scope is DEFAULT_OPTION_SCOPE :
918
971
scope = self .default_option_scope
0 commit comments