From 43cc89a39c1e86022110f6aaef529b8b312f10b9 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 10 Jun 2020 22:36:56 +0000 Subject: [PATCH] option errors show usage --- README.md | 2 +- pb | 16 ++++++++++++---- pb.1 | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 97856c8..91134c9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -pb ![calver](https://img.shields.io/badge/calver-2020.01.20-22bfda.svg?style=flat-square) ![status](https://img.shields.io/badge/status-working-green.svg?style=flat-square) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square) +pb ![calver](https://img.shields.io/badge/calver-2020.06.10-22bfda.svg?style=flat-square) ![status](https://img.shields.io/badge/status-working-green.svg?style=flat-square) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square) ------ **pb** is a helper utility for using 0x0 pastebin services diff --git a/pb b/pb index 14a3d05..164a41d 100755 --- a/pb +++ b/pb @@ -1,9 +1,9 @@ #!/bin/sh # init variables -version="v2020.01.20" +version="v2020.06.10" ENDPOINT="https://ttm.sh" -flag_options="hvcufs::x" +flag_options=":hvcufs::x" flag_version=0 flag_help=0 flag_file=0 @@ -31,6 +31,12 @@ OPTIONAL FLAGS: END } +show_usage() { + cat > /dev/stdout << END +usage: pb [-hfvcux] [-s server_address] filename +END +} + # helper for program exit, supports error codes and messages die () { msg="$1" @@ -59,14 +65,16 @@ fi # attempt to parse options or die if ! parsed=$(getopt ${flag_options} "$@"); then - die "Invalid input" 2 + printf "pb: unknown option\\n" + show_usage + exit 2 fi # handle options eval set -- "${parsed}" while true; do case "$1" in - -h) + -h|?) flag_help=1 ;; -v) diff --git a/pb.1 b/pb.1 index 93222ef..bb8ac2d 100644 --- a/pb.1 +++ b/pb.1 @@ -1,4 +1,4 @@ -.TH PB 1 "20 January 2020" "v2020.01.20" +.TH PB 1 "10 June 2020" "v2020.06.10" .SH NAME pb \- a helper utility for using 0x0 pastebin services