docpie icon indicating copy to clipboard operation
docpie copied to clipboard

Suggestion: make "usage" and "options" section keywords configurable

Open thorstenkampe opened this issue 8 years ago • 2 comments

Would it be possible to make the "usage" and "options" section keywords configurable? Like in

docpie(__doc__, usage = 'Aufruf', options = 'Optionen')

This would make the help text fully translatable (localized). Right now the keywords "Usage:" and "Options:" need to be English, otherwise docpie won't recognize them.

thorstenkampe avatar Dec 28 '17 17:12 thorstenkampe

Hi,

Currently, there is no api for docpie function. As I don't know whether this is a common need, I put it here, and a quick example is:

"""
Aufruf
    naval_fate --ship <shipname>

Optionen
    --ship
"""

from docpie import Docpie


class MyPie(Docpie):
    usage_name = 'Aufruf'
    option_name = 'Optionen'

pie = MyPie(__doc__).docpie()
print(pie)

or like this:

"""
Aufruf
    naval_fate --ship <shipname>

Optionen
    --ship
"""

from docpie import Docpie


class MyPie(Docpie):

    def __init__(self, doc=None, usage_name='Usage:', option_name='Options:'):
        assert doc is not None
        self.usage_name = usage_name
        self.option_name = option_name
        super(MyPie, self).__init__(doc)

pie = MyPie(__doc__, usage_name='Aufruf', option_name='Optionen').docpie()
print(pie)

I'd consider adding it as docpie function if it's a common need.

TylerTemp avatar Dec 28 '17 20:12 TylerTemp

Thanks for the quick response. Your solution works pretty well. One issue: when the Usage keyword is not found I get an error:

TypeError: must be str, not NoneType

but in Docopt:

docopt.DocoptLanguageError: "usage:" (case-insensitive) not found.

...which is much more informative

thorstenkampe avatar Dec 30 '17 12:12 thorstenkampe