MCPcopy Index your code
hub / github.com/cirosantilli/linux-kernel-module-cheat / get_cli

Method get_cli

cli_function.py:250–298  ·  view source on GitHub ↗

:rtype: List[Type(str)] :return: the canonical command line arguments arguments that would generate this Python function call. (--key, value) option pairs are grouped into tuples, and all other values are grouped in their own tuple

(self, **kwargs)

Source from the content-addressed store, hash-verified

248 sys.exit(exit_status)
249
250 def get_cli(self, **kwargs):
251 '''
252 :rtype: List[Type(str)]
253 :return: the canonical command line arguments arguments that would
254 generate this Python function call.
255
256 (--key, value) option pairs are grouped into tuples, and all
257 other values are grouped in their own tuple (positional_arg,)
258 or (--bool-arg,).
259
260 Arguments with default values are not added, but arguments
261 that are set by the config are also given.
262
263 The optional arguments are sorted alphabetically, followed by
264 positional arguments.
265
266 The long option name is used if both long and short versions
267 are given.
268 '''
269 options = []
270 positional_dict = {}
271 kwargs = self._get_args(kwargs)
272 for key in kwargs:
273 if not key in ('_args_given',):
274 argument = self._arguments[key]
275 default = argument.default
276 value = kwargs[key]
277 if value != default:
278 if argument.is_option:
279 if argument.is_bool:
280 vals = [(argument.longname,)]
281 elif 'action' in argument.kwargs and argument.kwargs['action'] == 'append':
282 vals = [(argument.longname, str(val)) for val in value]
283 else:
284 vals = [(argument.longname, str(value))]
285 for val in vals:
286 bisect.insort(options, val)
287 else:
288 if type(value) is list:
289 positional_dict[key] = [tuple([v]) for v in value]
290 else:
291 positional_dict[key] = [(str(value),)]
292 # Python built-in data structures suck.
293 # https://stackoverflow.com/questions/27726245/getting-the-key-index-in-a-python-ordereddict/27726534#27726534
294 positional = []
295 for key in self._arguments.keys():
296 if key in positional_dict:
297 positional.extend(positional_dict[key])
298 return options + positional
299
300 @staticmethod
301 def get_key(*args, **kwargs):

Callers 2

__call__Method · 0.80
cli_function.pyFile · 0.80

Calls 1

_get_argsMethod · 0.95

Tested by

no test coverage detected