MCPcopy Create free account
hub / github.com/apenwarr/sshuttle / _gen_usage

Method _gen_usage

options.py:91–150  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

89 self._usagestr = self._gen_usage()
90
91 def _gen_usage(self):
92 out = []
93 lines = self.optspec.strip().split('\n')
94 lines.reverse()
95 first_syn = True
96 while lines:
97 l = lines.pop()
98 if l == '--': break
99 out.append('%s: %s\n' % (first_syn and 'usage' or ' or', l))
100 first_syn = False
101 out.append('\n')
102 last_was_option = False
103 while lines:
104 l = lines.pop()
105 if l.startswith(' '):
106 out.append('%s%s\n' % (last_was_option and '\n' or '',
107 l.lstrip()))
108 last_was_option = False
109 elif l:
110 (flags, extra) = l.split(' ', 1)
111 extra = extra.strip()
112 if flags.endswith('='):
113 flags = flags[:-1]
114 has_parm = 1
115 else:
116 has_parm = 0
117 g = re.search(r'\[([^\]]*)\]$', extra)
118 if g:
119 defval = g.group(1)
120 else:
121 defval = None
122 flagl = flags.split(',')
123 flagl_nice = []
124 for _f in flagl:
125 f,dvi = _remove_negative_kv(_f, _intify(defval))
126 self._aliases[f] = _remove_negative_k(flagl[0])
127 self._hasparms[f] = has_parm
128 self._defaults[f] = dvi
129 if len(f) == 1:
130 self._shortopts += f + (has_parm and ':' or '')
131 flagl_nice.append('-' + f)
132 else:
133 f_nice = re.sub(r'\W', '_', f)
134 self._aliases[f_nice] = _remove_negative_k(flagl[0])
135 self._longopts.append(f + (has_parm and '=' or ''))
136 self._longopts.append('no-' + f)
137 flagl_nice.append('--' + _f)
138 flags_nice = ', '.join(flagl_nice)
139 if has_parm:
140 flags_nice += ' ...'
141 prefix = ' %-20s ' % flags_nice
142 argtext = '\n'.join(textwrap.wrap(extra, width=_tty_width(),
143 initial_indent=prefix,
144 subsequent_indent=' '*28))
145 out.append(argtext + '\n')
146 last_was_option = True
147 else:
148 out.append('\n')

Callers 1

__init__Method · 0.95

Calls 4

_remove_negative_kvFunction · 0.85
_intifyFunction · 0.85
_remove_negative_kFunction · 0.85
_tty_widthFunction · 0.85

Tested by

no test coverage detected