MCPcopy Create free account
hub / github.com/ceph/ceph / argdesc

Class argdesc

src/pybind/ceph_argparse.py:771–908  ·  view source on GitHub ↗

argdesc(typename, name='name', n=numallowed|N, req=False, positional=True, helptext=helptext, **kwargs (type-specific)) validation rules: typename: type(**kwargs) will be constructed later, type.valid(w) will be called with a word in that position name

Source from the content-addressed store, hash-verified

769
770
771class argdesc(object):
772 """
773 argdesc(typename, name='name', n=numallowed|N,
774 req=False, positional=True,
775 helptext=helptext, **kwargs (type-specific))
776
777 validation rules:
778 typename: type(**kwargs) will be constructed
779 later, type.valid(w) will be called with a word in that position
780
781 name is used for parse errors and for constructing JSON output
782 n is a numeric literal or 'n|N', meaning "at least one, but maybe more"
783 req=False means the argument need not be present in the list
784 positional=False means the argument name must be specified, e.g. "--myoption value"
785 helptext is the associated help for the command
786 anything else are arguments to pass to the type constructor.
787
788 self.instance is an instance of type t constructed with typeargs.
789
790 valid() will later be called with input to validate against it,
791 and will store the validated value in self.instance.val for extraction.
792 """
793 def __init__(self, t, name=None, n=1, req=True, positional=True, **kwargs) -> None:
794 if isinstance(t, basestring):
795 self.t = CephPrefix
796 self.typeargs = {'prefix': t}
797 self.req = True
798 self.positional = True
799 else:
800 self.t = t
801 self.typeargs = kwargs
802 self.req = req in (True, 'True', 'true')
803 self.positional = positional in (True, 'True', 'true')
804 if not positional:
805 assert not req
806
807 self.name = name
808 self.N = (n in ['n', 'N'])
809 if self.N:
810 self.n = 1
811 else:
812 self.n = int(n)
813
814 self.numseen = 0
815
816 self.instance = self.t(**self.typeargs)
817
818 def __repr__(self):
819 r = 'argdesc(' + str(self.t) + ', '
820 internals = ['N', 'typeargs', 'instance', 't']
821 for (k, v) in self.__dict__.items():
822 if k.startswith('__') or k in internals:
823 pass
824 else:
825 # undo modification from __init__
826 if k == 'n' and self.N:
827 v = 'N'
828 r += '{0}={1}, '.format(k, v)

Callers 1

parse_funcsigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected