diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-07-05 23:42:19 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-07-05 23:42:19 +0530 |
| commit | c3e7c1fb146d86006ce6ef13093e5fe21542cfa4 (patch) | |
| tree | 536beab9a789c2162b54d8f2eeef4e0d80164efe | |
| parent | 610c6af377f64e6eea3a2b060405d5402273dd2f (diff) | |
| download | anypinentry-c3e7c1fb146d86006ce6ef13093e5fe21542cfa4.tar.gz anypinentry-c3e7c1fb146d86006ce6ef13093e5fe21542cfa4.zip | |
Adds cli parsing
| -rwxr-xr-x | anypinentry | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/anypinentry b/anypinentry index f9aa4c9..0384287 100755 --- a/anypinentry +++ b/anypinentry @@ -12,6 +12,8 @@ prompt=""; description=""; keyinfo=""; +prompt_action=""; + ask_password() { dmenu -P -p "$prompt" 2> /dev/null; } @@ -37,12 +39,12 @@ password_prompt() { fi; } -echo "OK Pleased to meet you"; -while read line; do - cmd="$(echo "$line" | cut -d' ' -f1)"; - data="$(echo "$line" | cut -d' ' -f2-)"; +interpret_command() { + cmd="$(echo "$1" | cut -d' ' -f1)"; + data="$(echo "$1" | cut -d' ' -f2-)"; case "$cmd" in + INIT) echo "OK Pleased to meet you" ;; OPTION) save_option "$data" ;; GETINFO) get_info "$data" ;; SETTITLE) title="$data" && echo "OK" ;; @@ -53,6 +55,36 @@ while read line; do BYE) echo "OK closing connection" && exit 0; ;; *) echo "OK" ;; esac; +} + +help() { + echo "Usage: $0 [-D DISPLAY] [--prompt script] [--confirm script] [-hv]"; +} + +parse_cliargs() { + [[ $# -le 0 ]] && return 0; + + case "$1" in + -D|--display) export DISPLAY="$2"; shift 1 ;; + --prompt) prompt_action="$2"; shift 1 ;; + --confirm) confirm_action="$2"; shift 1 ;; + -v) echo "anypinentry-$VERSION" && exit 0 ;; + -h) help && exit 0 ;; + *) help && exit 1 ;; + esac; + + shift 1; + parse_cliargs "$@"; +} + +parse_cliargs "$@"; + +exit 0; + +interpret_command "INIT"; + +while read line; do + interpret_command "$line"; done; #{ "SETREPEAT", cmd_setrepeat }, |
