Permalink
Browse files

Implement part of the compgen builtin: compgen -A function (#174)

  • Loading branch information...
granttrec authored and andychu committed Aug 27, 2018
1 parent b2cfe67 commit 92051aee3a971d18f7338cfc51d4b8ec0d4795fc
Showing with 45 additions and 5 deletions.
  1. +23 −1 core/builtin.py
  2. +1 −4 core/cmd_exec.py
  3. +17 −0 spec/compgen.test.sh
  4. +4 −0 test/spec.sh
View
@@ -794,6 +794,28 @@ def Shopt(argv, exec_opts):
return 0
COMPGEN_SPEC = _Register('compgen')
COMPGEN_SPEC.ShortFlag('-A', args.Str)
def CompGen(argv, funcs):
arg, i = COMPGEN_SPEC.Parse(argv)
status = 0
if arg.A:
if arg.A != 'function':
status = 1
raise args.UsageError('compgen: %s: invalid action name' % arg.A)
else:
for func_name in sorted(funcs):
print(func_name)
else:
util.warn('*** command without -A not implemented ***')
status = 1
return status
UNSET_SPEC = _Register('unset')
UNSET_SPEC.ShortFlag('-v')
UNSET_SPEC.ShortFlag('-f')
@@ -877,7 +899,7 @@ def Command(argv, funcs, path_val):
# This is for -v, -V is more detailed.
print(arg)
else:
util.warn('*** command without -v not not implemented ***')
util.warn('*** command without -v not implemented ***')
status = 1
return status
View
@@ -180,9 +180,6 @@ def _Complete(self, argv):
util.error('Oil was not built with readline/completion.')
return 0
def _CompGen(self, argv):
raise NotImplementedError
def _EvalHelper(self, c_parser, source_name):
self.arena.PushSource(source_name)
try:
@@ -359,7 +356,7 @@ def _RunBuiltin(self, builtin_id, argv):
status = self._Complete(argv)
elif builtin_id == builtin_e.COMPGEN:
status = self._CompGen(argv)
status = builtin.CompGen(argv, self.funcs)
elif builtin_id == builtin_e.COLON: # special builtin like 'true'
status = 0
View
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#### Print function list
add () { expr 4 + 4; }
div () { expr 6 / 2; }
ek () { echo hello; }
__ec () { echo hi; }
_ab () { expr 10 % 3; }
compgen -A function
## status: 0
## STDOUT:
__ec
_ab
add
div
ek
## END
View
@@ -604,4 +604,8 @@ shell-grammar() {
sh-spec spec/shell-grammar.test.sh $BASH $MKSH $ZSH "$@"
}
compgen() {
sh-spec spec/compgen.test.sh $BASH $OSH "$@"
}
"$@"

0 comments on commit 92051ae

Please sign in to comment.