Skip to content

Commit

Permalink
Updated the autocomplete file and disable command
Browse files Browse the repository at this point in the history
  • Loading branch information
boltgolt committed May 4, 2018
1 parent b9866d7 commit 5ac5070
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
33 changes: 31 additions & 2 deletions autocomplete/howdy
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,40 @@
_howdy() {
local cur prev opts
COMPREPLY=()
# The argument typed so far
cur="${COMP_WORDS[COMP_CWORD]}"
# The previous argument
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="help list add remove clear"

COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
# Go though all cases we support
case "${prev}" in
# After the main command, show the commands
"howdy")
opts="add clear config disable list remove clear test"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
# For disable, grab the current "disabled" config option and give the reverse
"disable")
local status=$(cut -d'=' -f2 <<< $(cat /lib/security/howdy/config.ini | grep 'disabled =') | xargs echo -n)

[ "$status" == "false" ] && COMPREPLY="true" || COMPREPLY="false"
return 0
;;
# List the users availible
"-U")
COMPREPLY=( $(compgen -u -- ${cur}) )
return 0
;;
"--user")
COMPREPLY=( $(compgen -u -- ${cur}) )
return 0
;;
*)
;;
esac

# Nothing matched, so return nothing
return 0
}

Expand Down
11 changes: 8 additions & 3 deletions src/cli/disable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
sys.exit(1)

# Translate the argument to the right string
if builtins.howdy_args.argument == "1":
if builtins.howdy_args.argument == "1" or builtins.howdy_args.argument.lower() == "true":
out_value = "true"
elif builtins.howdy_args.argument == "0":
elif builtins.howdy_args.argument == "0" or builtins.howdy_args.argument.lower() == "false":
out_value = "false"
else:
# Of it's not a 0 or a 1, it's invalid
print("Please only use a 0 (enable) or a 1 (disable) as an argument")
print("Please only use false (enable) or true (disable) as an argument")
sys.exit(1)

# Don't do anything when the state is already the requested one
if out_value == config.get("core", "disabled"):
print("The disable option has already been set to " + out_value)
sys.exit(1)

# Loop though the config file and only replace the line containing the disable config
Expand Down

0 comments on commit 5ac5070

Please sign in to comment.