MCPcopy Create free account
hub / github.com/cloudwan/gohan / Completion

Class Completion

tools/gohan_client_bash_completion_tests.py:5–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import unittest
4
5class Completion():
6 def prepare(self, program, command):
7 self.program=program
8 self.COMP_LINE="%s %s" % (program, command)
9 self.COMP_WORDS=self.COMP_LINE.rstrip()
10
11 args=command.split()
12 self.COMP_CWORD=len(args)
13 self.COMP_POINT=len(self.COMP_LINE)
14 if (self.COMP_LINE[-1] == ' '):
15 self.COMP_WORDS += " "
16 self.COMP_CWORD += 1
17
18 def run(self, completion_file, program, command):
19 self.prepare(program, command)
20 full_cmdline=r'source {compfile}; COMP_LINE="{COMP_LINE}" COMP_WORDS=({COMP_WORDS}) COMP_CWORD={COMP_CWORD} COMP_POINT={COMP_POINT}; $(complete -p {program} | sed "s/.*-F \\([^ ]*\\) .*/\\1/") && echo ${{COMPREPLY[*]}}'.format(
21 compfile=completion_file, COMP_LINE=self.COMP_LINE, COMP_WORDS=self.COMP_WORDS, COMP_POINT=self.COMP_POINT, program=self.program, COMP_CWORD=self.COMP_CWORD
22 )
23
24 out = subprocess.Popen(['bash', '-i', '-c', full_cmdline], stdout=subprocess.PIPE)
25 return out.communicate()
26
27class CompletionTestCase(unittest.TestCase):
28

Callers 2

assertEqualCompletionMethod · 0.70
run_completeMethod · 0.70

Calls

no outgoing calls

Tested by 2

assertEqualCompletionMethod · 0.56
run_completeMethod · 0.56