Some input improvements: -m for 'string message', -i for files input
This commit is contained in:
parent
8237793260
commit
53d5817973
20
laconia
20
laconia
|
@ -10,10 +10,16 @@ error_exit() {
|
||||||
usage() {
|
usage() {
|
||||||
printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME"
|
printf "usage: %s [OPTIONS] URI [ARGS]\n" "$PROGNAME"
|
||||||
printf "Simple client for spartan protocol\n"
|
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(){
|
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}')
|
status=$(echo $page | awk 'NR == 1 {print $1}')
|
||||||
meta=$(echo $page | awk 'NR == 1 {$1=="";print}')
|
meta=$(echo $page | awk 'NR == 1 {$1=="";print}')
|
||||||
if [[ $status == 2 ]]; then
|
if [[ $status == 2 ]]; then
|
||||||
|
@ -28,15 +34,19 @@ request(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts ":h:p:i:u:" arg; do
|
while getopts ":h:p:m:i:u:" arg; do
|
||||||
case $arg in
|
case $arg in
|
||||||
h | --help)
|
h | --help)
|
||||||
usage; exit ;;
|
usage; exit ;;
|
||||||
p | --port)
|
p | --port)
|
||||||
export port=$OPTARG
|
export port=$OPTARG
|
||||||
;;
|
;;
|
||||||
i | --input)
|
i | --input-file)
|
||||||
export post=$OPTARG
|
export post=$(cat $OPTARG)
|
||||||
|
export post_len=$(echo $post | wc -c )
|
||||||
|
;;
|
||||||
|
m | --message)
|
||||||
|
export post=$( echo $OPTARG)
|
||||||
export post_len=$( echo $post | wc -c )
|
export post_len=$( echo $post | wc -c )
|
||||||
;;
|
;;
|
||||||
u | --url)
|
u | --url)
|
||||||
|
@ -55,7 +65,7 @@ while getopts ":h:p:i:u:" arg; do
|
||||||
echo $url_unparsed is not a Spartan URL
|
echo $url_unparsed is not a Spartan URL
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
* | -* | --*)
|
*)
|
||||||
usage; error_exit "unknown option $1" ;;
|
usage; error_exit "unknown option $1" ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
2.One more test sorry
|
||||||
|
-- g1n
|
Loading…
Reference in New Issue