Beispiel #1
0
    def _gather_flags(self):
        """
		Gather up boolean (flag) options.
		"""

        longOpt, shortOpt = [], ''
        docs, settings, synonyms, dispatch = {}, {}, {}, {}

        flags = []
        reflect.accumulateClassList(self.__class__, 'optFlags', flags)

        for flag in flags:
            long, short, doc = util.padTo(3, flag)
            if not long:
                raise ValueError("A flag cannot be without a name.")

            docs[long] = doc
            settings[long] = 0
            if short:
                shortOpt = shortOpt + short
                synonyms[short] = long
            longOpt.append(long)
            synonyms[long] = long
            dispatch[long] = self._generic_flag

        return longOpt, shortOpt, docs, settings, synonyms, dispatch
Beispiel #2
0
	def _gather_flags(self):
		"""
		Gather up boolean (flag) options.
		"""

		longOpt, shortOpt = [], ''
		docs, settings, synonyms, dispatch = {}, {}, {}, {}

		flags = []
		reflect.accumulateClassList(self.__class__, 'optFlags', flags)

		for flag in flags:
			long, short, doc = util.padTo(3, flag)
			if not long:
				raise ValueError("A flag cannot be without a name.")

			docs[long] = doc
			settings[long] = 0
			if short:
				shortOpt = shortOpt + short
				synonyms[short] = long
			longOpt.append(long)
			synonyms[long] = long
			dispatch[long] = self._generic_flag

		return longOpt, shortOpt, docs, settings, synonyms, dispatch
Beispiel #3
0
    def _gather_parameters(self):
        """
		Gather options which take a value.
		"""
        longOpt, shortOpt = [], ''
        docs, settings, synonyms, dispatch = {}, {}, {}, {}

        parameters = []

        reflect.accumulateClassList(self.__class__, 'optStrings', parameters)
        if parameters:
            import warnings
            warnings.warn(
                "Options.optStrings is deprecated, "
                "please use optParameters instead.",
                stacklevel=2)

        reflect.accumulateClassList(self.__class__, 'optParameters',
                                    parameters)

        synonyms = {}

        for parameter in parameters:
            long, short, default, doc, paramType = util.padTo(5, parameter)
            if not long:
                raise ValueError("A parameter cannot be without a name.")

            docs[long] = doc
            settings[long] = default
            if short:
                shortOpt = shortOpt + short + ':'
                synonyms[short] = long
            longOpt.append(long + '=')
            synonyms[long] = long
            if paramType is not None:
                dispatch[long] = CoerceParameter(self, paramType)
            else:
                dispatch[long] = CoerceParameter(self, str)

        return longOpt, shortOpt, docs, settings, synonyms, dispatch
Beispiel #4
0
	def _gather_parameters(self):
		"""
		Gather options which take a value.
		"""
		longOpt, shortOpt = [], ''
		docs, settings, synonyms, dispatch = {}, {}, {}, {}

		parameters = []

		reflect.accumulateClassList(self.__class__, 'optStrings',
									parameters)
		if parameters:
			import warnings
			warnings.warn("Options.optStrings is deprecated, "
						  "please use optParameters instead.", stacklevel=2)

		reflect.accumulateClassList(self.__class__, 'optParameters',
									parameters)

		synonyms = {}

		for parameter in parameters:
			long, short, default, doc, paramType = util.padTo(5, parameter)
			if not long:
				raise ValueError("A parameter cannot be without a name.")

			docs[long] = doc
			settings[long] = default
			if short:
				shortOpt = shortOpt + short + ':'
				synonyms[short] = long
			longOpt.append(long + '=')
			synonyms[long] = long
			if paramType is not None:
				dispatch[long] = CoerceParameter(self, paramType)
			else:
				dispatch[long] = CoerceParameter(self, str)

		return longOpt, shortOpt, docs, settings, synonyms, dispatch
Beispiel #5
0
    def __init__(self, cmd_name, options, file):
        """
		@type cmd_name: C{str}
		@param cmd_name: The name of the command

		@type options: C{lib.twisted.usage.Options}
		@param options: The C{lib.twisted.usage.Options} instance defined
						for this command

		@type file: C{file}
		@param file: The C{file} to write the completion function to
		"""
        self.cmd_name = cmd_name
        self.options = options
        self.file = file

        self.altArgDescr = {}
        self.actionDescr = {}
        self.multiUse = []
        self.mutuallyExclusive = []
        self.actions = {}
        self.extras = []

        aCL = reflect.accumulateClassList
        aCD = reflect.accumulateClassDict

        aCD(options.__class__, 'zsh_altArgDescr', self.altArgDescr)
        aCD(options.__class__, 'zsh_actionDescr', self.actionDescr)
        aCL(options.__class__, 'zsh_multiUse', self.multiUse)
        aCL(options.__class__, 'zsh_mutuallyExclusive', self.mutuallyExclusive)
        aCD(options.__class__, 'zsh_actions', self.actions)
        aCL(options.__class__, 'zsh_extras', self.extras)

        optFlags = []
        optParams = []

        aCL(options.__class__, 'optFlags', optFlags)
        aCL(options.__class__, 'optParameters', optParams)

        for i, optList in enumerate(optFlags):
            if len(optList) != 3:
                optFlags[i] = util.padTo(3, optList)

        for i, optList in enumerate(optParams):
            if len(optList) != 4:
                optParams[i] = util.padTo(4, optList)

        self.optFlags = optFlags
        self.optParams = optParams

        optParams_d = {}
        for optList in optParams:
            optParams_d[optList[0]] = optList[1:]
        self.optParams_d = optParams_d

        optFlags_d = {}
        for optList in optFlags:
            optFlags_d[optList[0]] = optList[1:]
        self.optFlags_d = optFlags_d

        optAll_d = {}
        optAll_d.update(optParams_d)
        optAll_d.update(optFlags_d)
        self.optAll_d = optAll_d

        self.addAdditionalOptions()

        # makes sure none of the zsh_ data structures reference option
        # names that don't exist. (great for catching typos)
        self.verifyZshNames()

        self.excludes = self.makeExcludesDict()
Beispiel #6
0
    def __init__(self, cmd_name, options, file):
        """
		@type cmd_name: C{str}
		@param cmd_name: The name of the command

		@type options: C{lib.twisted.usage.Options}
		@param options: The C{lib.twisted.usage.Options} instance defined
						for this command

		@type file: C{file}
		@param file: The C{file} to write the completion function to
		"""
        self.cmd_name = cmd_name
        self.options = options
        self.file = file

        self.altArgDescr = {}
        self.actionDescr = {}
        self.multiUse = []
        self.mutuallyExclusive = []
        self.actions = {}
        self.extras = []

        aCL = reflect.accumulateClassList
        aCD = reflect.accumulateClassDict

        aCD(options.__class__, "zsh_altArgDescr", self.altArgDescr)
        aCD(options.__class__, "zsh_actionDescr", self.actionDescr)
        aCL(options.__class__, "zsh_multiUse", self.multiUse)
        aCL(options.__class__, "zsh_mutuallyExclusive", self.mutuallyExclusive)
        aCD(options.__class__, "zsh_actions", self.actions)
        aCL(options.__class__, "zsh_extras", self.extras)

        optFlags = []
        optParams = []

        aCL(options.__class__, "optFlags", optFlags)
        aCL(options.__class__, "optParameters", optParams)

        for i, optList in enumerate(optFlags):
            if len(optList) != 3:
                optFlags[i] = util.padTo(3, optList)

        for i, optList in enumerate(optParams):
            if len(optList) != 4:
                optParams[i] = util.padTo(4, optList)

        self.optFlags = optFlags
        self.optParams = optParams

        optParams_d = {}
        for optList in optParams:
            optParams_d[optList[0]] = optList[1:]
        self.optParams_d = optParams_d

        optFlags_d = {}
        for optList in optFlags:
            optFlags_d[optList[0]] = optList[1:]
        self.optFlags_d = optFlags_d

        optAll_d = {}
        optAll_d.update(optParams_d)
        optAll_d.update(optFlags_d)
        self.optAll_d = optAll_d

        self.addAdditionalOptions()

        # makes sure none of the zsh_ data structures reference option
        # names that don't exist. (great for catching typos)
        self.verifyZshNames()

        self.excludes = self.makeExcludesDict()