diff --git a/ipalib/base.py b/ipalib/base.py index 2769efd3b..ece446cff 100644 --- a/ipalib/base.py +++ b/ipalib/base.py @@ -132,8 +132,12 @@ class Named(object): return self.__class__.__name__ name = property(__get_name) + def __get_cli(self): + return self.name.replace('_', '-') + cli = property(__get_cli) + def __get_doc(self): - return self.__class__.__doc__ + return self.__class__.__doc__.strip() doc = property(__get_doc) diff --git a/ipalib/tests/test_base.py b/ipalib/tests/test_base.py index 818b7713a..0dfd3438f 100644 --- a/ipalib/tests/test_base.py +++ b/ipalib/tests/test_base.py @@ -183,6 +183,17 @@ class test_NameSpace: assert len(kw) == len(ns) == 3 +def test_Named(): + class named_class(base.Named): + """ + This class is so introspective! + """ + i = named_class() + assert i.name == 'named_class' + assert i.cli == 'named-class' + assert i.doc == 'This class is so introspective!' + + def test_Command(): class user(object): name = 'user'