Some input improvements: -m for 'string message', -i for files input

This commit is contained in:
g1n 2021-07-08 17:37:41 +00:00
parent 8237793260
commit 53d5817973
2 changed files with 17 additions and 5 deletions

20
laconia
View File

@ -10,10 +10,16 @@ error_exit() {
usage() {
printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME"
printf "Simple client for spartan protocol\n"
printf "Options:
-h, --help - display this help
-p, --port - change port number (default is 300)
-m, --message - input as string
-i, --input-file - input as file
-u, --url - url to the capsule\n"
}
request(){
page=$(printf "$host /$path $post_len\r\n$post\r\n" | nc $host $port)
page=$(printf "$host /$path 0\r\n" | nc $host $port)
status=$(echo $page | awk 'NR == 1 {print $1}')
meta=$(echo $page | awk 'NR == 1 {$1=="";print}')
if [[ $status == 2 ]]; then
@ -28,15 +34,19 @@ request(){
fi
}
while getopts ":h:p:i:u:" arg; do
while getopts ":h:p:m:i:u:" arg; do
case $arg in
h | --help)
usage; exit ;;
p | --port)
export port=$OPTARG
;;
i | --input)
export post=$OPTARG
i | --input-file)
export post=$(cat $OPTARG)
export post_len=$(echo $post | wc -c )
;;
m | --message)
export post=$( echo $OPTARG)
export post_len=$( echo $post | wc -c )
;;
u | --url)
@ -55,7 +65,7 @@ while getopts ":h:p:i:u:" arg; do
echo $url_unparsed is not a Spartan URL
fi
;;
* | -* | --*)
*)
usage; error_exit "unknown option $1" ;;
esac
done

2
message.txt Normal file
View File

@ -0,0 +1,2 @@
2.One more test sorry
-- g1n