14 from textwrap import TextWrapper |
14 from textwrap import TextWrapper |
15 from time import strftime, strptime |
15 from time import strftime, strptime |
16 |
16 |
17 from VirtualMailManager import ENCODING |
17 from VirtualMailManager import ENCODING |
18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
18 from VirtualMailManager.cli import get_winsize, prog, w_err, w_std |
19 from VirtualMailManager.cli.clihelp import help_msgs |
|
20 from VirtualMailManager.common import human_size, size_in_bytes, \ |
19 from VirtualMailManager.common import human_size, size_in_bytes, \ |
21 version_str, format_domain_default |
20 version_str, format_domain_default |
22 from VirtualMailManager.constants import __copyright__, __date__, \ |
21 from VirtualMailManager.constants import __copyright__, __date__, \ |
23 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
22 __version__, ACCOUNT_EXISTS, ALIAS_EXISTS, ALIASDOMAIN_ISDOMAIN, \ |
24 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, \ |
23 DOMAIN_ALIAS_EXISTS, INVALID_ARGUMENT, EX_MISSING_ARGS, \ |
47 |
46 |
48 |
47 |
49 class Command(object): |
48 class Command(object): |
50 """Container class for command information.""" |
49 """Container class for command information.""" |
51 __slots__ = ('name', 'alias', 'func', 'args', 'descr') |
50 __slots__ = ('name', 'alias', 'func', 'args', 'descr') |
52 FMT_HLP_USAGE = """ |
|
53 usage: %(prog)s %(name)s %(args)s |
|
54 %(prog)s %(alias)s %(args)s |
|
55 """ |
|
56 |
51 |
57 def __init__(self, name, alias, func, args, descr): |
52 def __init__(self, name, alias, func, args, descr): |
58 """Create a new Command instance. |
53 """Create a new Command instance. |
59 |
54 |
60 Arguments: |
55 Arguments: |
78 |
73 |
79 @property |
74 @property |
80 def usage(self): |
75 def usage(self): |
81 """the command's usage info.""" |
76 """the command's usage info.""" |
82 return u'%s %s %s' % (prog, self.name, self.args) |
77 return u'%s %s %s' % (prog, self.name, self.args) |
83 |
|
84 def help_(self): |
|
85 old_ii = txt_wrpr.initial_indent |
|
86 old_si = txt_wrpr.subsequent_indent |
|
87 |
|
88 txt_wrpr.subsequent_indent = (len(self.name) + 2) * ' ' |
|
89 w_std(txt_wrpr.fill('%s: %s' % (self.name, self.descr))) |
|
90 |
|
91 info = Command.FMT_HLP_USAGE % dict(alias=self.alias, args=self.args, |
|
92 name=self.name, prog=prog) |
|
93 w_std(info) |
|
94 |
|
95 txt_wrpr.initial_indent = txt_wrpr.subsequent_indent = ' ' |
|
96 try: |
|
97 [w_std(txt_wrpr.fill(_(para)) + '\n') for para |
|
98 in help_msgs[self.name]] |
|
99 except KeyError: |
|
100 w_err(1, "'help %s' not yet documented." % self.name, |
|
101 'see also: vmm(1)') |
|
102 |
78 |
103 |
79 |
104 class RunContext(object): |
80 class RunContext(object): |
105 """Contains all information necessary to run a subcommand.""" |
81 """Contains all information necessary to run a subcommand.""" |
106 __slots__ = ('argc', 'args', 'cget', 'hdlr', 'scmd') |
82 __slots__ = ('argc', 'args', 'cget', 'hdlr', 'scmd') |
465 topic = scmd.name |
441 topic = scmd.name |
466 break |
442 break |
467 else: |
443 else: |
468 usage(INVALID_ARGUMENT, _(u"Unknown help topic: '%s'") % |
444 usage(INVALID_ARGUMENT, _(u"Unknown help topic: '%s'") % |
469 ctx.args[2], ctx.scmd) |
445 ctx.args[2], ctx.scmd) |
470 if topic != u'help': |
446 # FIXME |
471 return cmd_map[topic].help_() |
447 w_err(1, "'help %s' not yet implemented." % topic, 'see also: vmm(1)') |
472 |
448 |
473 old_ii = txt_wrpr.initial_indent |
449 old_ii = txt_wrpr.initial_indent |
474 old_si = txt_wrpr.subsequent_indent |
450 old_si = txt_wrpr.subsequent_indent |
475 txt_wrpr.initial_indent = ' ' |
451 txt_wrpr.initial_indent = ' ' |
476 # len(max(_overview.iterkeys(), key=len)) #Py25 |
452 # len(max(_overview.iterkeys(), key=len)) #Py25 |