Skip to content

Commit

Permalink
Add optional argument to output option
Browse files Browse the repository at this point in the history
Indicate that change in the help and manual, and add tests for it.
Change visual order of options in help message, and manual entry.
Add explanation about tests in README.
  • Loading branch information
HacKanCuBa committed Apr 26, 2017
1 parent ab320c0 commit bee54ed
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*~
*.swp
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ These come by default in most modern distros.

## Installing

Clone this repository or download a [release](https://github.com/HacKanCuBa/b2rsum/releases), then run `make install` as privileged user (probably `sudo make install`). You can optionally do `make lint` to check for errors (it uses [shellcheck](https://github.com/koalaman/shellcheck)).
Clone this repository or download a [release](https://github.com/HacKanCuBa/b2rsum/releases), then run `make install` as privileged user (probably `sudo make install`).

### Verifying

You can optionally do `make lint && make test` to check for errors (it requires [shellcheck](https://github.com/koalaman/shellcheck) for linting), specially if you are cloning the repository.

Tests can also be run individually with `make tests/tXXXX-description.sh` and debugged with `./tests/tXXXX-description.sh -v`. [Sharness](https://github.com/chriscool/sharness) is used as framework.

## Examples of use

Expand Down
80 changes: 53 additions & 27 deletions man/b2rsum.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH B2RSUM "1" "April 2017" "b2rsum Copyright (C) 2017 HacKan (https://hackan.net)" "BLAKE2 Recursive Sum"
.TH B2RSUM "1" "April 2017" "b2rsum v0.1.2" "BLAKE2 Recursive Sum"

.SH NAME
b2rsum \- compute and check BLAKE2 message digest recursively
Expand All @@ -15,55 +15,75 @@ wrapper that adds the capability of processing an entire directory, so the sums

When FILE or DIRECTORY is empty or a dot (.), compute current directory. When FILE is -, read standard input.

The default mode is to compute checksums. Check mode is indicated with --check.

.SH OPTIONS
.TP
\fB\-b\fR, \fB\-\-binary\fR
read in binary mode
.TP
\fB\-c\fR, \fB\-\-check\fR
read BLAKE2 sums from the FILEs and check them

.TP
\fB\-l\fR, \fB\-\-length\fR
digest length in bits; must not exceed the maximum for
the blake2 algorithm and must be a multiple of 8
.TP
\fB\-\-tag\fR
create a BSD\-style checksum
.TP
\fB\-t\fR, \fB\-\-text\fR
read in text mode (default)
.TP
\fB\-o\fR, \fB\-\-output\fR
output to a file named BLAKE2SUMS in the
current directory instead of standard output
\fB\-o\fR[\fI\,FILE\/\fR], \fB\-\-output\fR[=\fI\,FILE\/\fR]
output to FILE instead of standard output, or a
file named BLAKE2SUMS in the current
directory if FILE is not specified

.TP
\fB\-q\fR, \fB\-\-quiet\fR
quiet mode: don't print messages, only hashes; during
check mode, don't print OK for each successfully
verified file

.TP
\fB\-s\fR, \fB\-\-status\fR
very quiet mode: output only hashes, no messages; status
code shows success

.TP
\fB\-\-license\fR
show license and exit

.TP
\fB\-\-version\fR
show version information and exit

.TP
\fB\-h\fR, \fB\-\-help\fR
show this text and exit

.SS "The following four options are useful only when computing checksums:"

.TP
\fB\-t\fR, \fB\-\-text\fR
read in text mode (default)

.TP
\fB\-b\fR, \fB\-\-binary\fR
read in binary mode

.TP
\fB\-\-tag\fR
create a BSD\-style checksum

.TP
\fB\-l\fR, \fB\-\-length\fR
digest length in bits; must not exceed the maximum for
the blake2 algorithm and must be a multiple of 8

.SS "The following three options are useful only when verifying checksums:"

.TP
\fB\-\-ignore\-missing\fR
don't fail or report status for missing files

.TP
\fB\-\-strict\fR
exit non\-zero for improperly formatted checksum lines

.TP
\fB\-w\fR, \fB\-\-warn\fR
warn about improperly formatted checksum lines
.TP
\fB\-h\fR, \fB\-\-help\fR
show this text and exit
.TP
\fB\-\-license\fR
show license and exit
.TP
\fB\-\-version\fR
show version information and exit

.PP
The sums are computed as described in RFC 7693. When checking, the input
should be a former output of this program. The default mode is to print a
Expand All @@ -74,7 +94,7 @@ line with checksum, a space, a character indicating input mode ('*' for binary,
.BR b2sum (1)

.SH AUTHOR
.B b2sum
.B b2rsum
was written by
.MT [email protected]
HacKan
Expand All @@ -85,6 +105,12 @@ repository
.UE
for additional information.

.SH REPORTING BUGS
Please create an issue at the
.UR https://\:github.com/HacKanCuBa/b2rsum/issues
repository
.UE .

.SH COPYING
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
60 changes: 36 additions & 24 deletions src/b2rsum.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@
# Changelog
#=====================
#
# v0.1.2
# - Some changes in the order of info in help message.
# - Output option now accepts optional argument.
#
# v0.1.1
# - Fix check mode not reading inline data
# - Fix length option being improperly parsed
# - Bail out on wrong option
# - Fix check mode not reading inline data.
# - Fix length option being improperly parsed.
# - Bail out on wrong option.
#
# v0.1.0
# - First release
# - First release.
#
# v0.0.1
# - Developing based on sharsum.
#
#------------------------------------------------------------------------

# Config
declare -r VERSION="0.1.1"
declare -r VERSION="0.1.2"
declare -r OUTPUT_FILENAME_DEFAULT="BLAKE2SUMS"
declare -r QUIET_DEFAULT=false
#--------------------------#
Expand Down Expand Up @@ -146,34 +150,39 @@ cmd_help() {
cat <<-_EOF
Usage: ${PROGRAM} [OPTION]... [FILE or DIRECTORY]...
Print or check BLAKE2 (512-bit) checksums recursively.
If no FILE or DIRECTORY is indicated, or it's a dot (.), then the current
directory is processed.
The default mode is to compute checksums. Check mode is indicated with --check.
Options:
-b, --binary read in binary mode
-c, --check read BLAKE2 sums from the FILEs and check them
-l, --length digest length in bits; must not exceed the maximum for
the blake2 algorithm and must be a multiple of 8
--tag create a BSD-style checksum
-t, --text read in text mode (default)
-o, --output output to a file named $OUTPUT_FILENAME_DEFAULT in the
current directory instead of standard output
-q, --quiet quiet mode: don't print messages, only hashes; during
check mode, don't print OK for each successfully
verified file
-s, --status very quiet mode: output only hashes, no messages; status
code shows success
-c, --check read BLAKE2 sums from the FILEs and check them
-o[FILE], --output[=FILE] output to FILE instead of standard output, or a
file named $OUTPUT_FILENAME_DEFAULT in the current
directory if FILE is not specified
-q, --quiet quiet mode: don't print messages, only hashes;
during check mode, don't print OK for each
successfully verified file
-s, --status very quiet mode: output only hashes, no messages;
status code shows success
--license show license and exit
--version show version information and exit
-h, --help show this text and exit
The following four options are useful only when computing checksums:
-t, --text read in text mode (default)
-b, --binary read in binary mode
--tag create a BSD-style checksum
-l, --length digest length in bits; must not exceed the maximum
for the blake2 algorithm and must be a multiple
of 8
The following three options are useful only when verifying checksums:
--ignore-missing don't fail or report status for missing files
--strict exit non-zero for improperly formatted checksum lines
-w, --warn warn about improperly formatted checksum lines
-h, --help show this text and exit
--license show license and exit
--version show version information and exit
Sums are made using 'b2sum'. Full documentation at:
<http://www.gnu.org/software/coreutils/b2sum>.
The sums are computed as described in RFC 7693. When checking, the input
Expand Down Expand Up @@ -273,7 +282,7 @@ declare OUTPUT_FILE=''
check_dependencies || die "Dependencies not met, can't continue"

# Arguments
OPTS="$(getopt -o hbctwosql: -l help,version,license,binary,check,length:,text,tag,ignore-missing,quiet,status,strict,warn,output -n "$PROGRAM" -- "$@")"
OPTS="$(getopt -o hbctwsql:o:: -l help,version,license,binary,check,length:,text,tag,ignore-missing,quiet,status,strict,warn,output:: -n "$PROGRAM" -- "$@")"
[[ $? -ne 0 ]] && die "Wrong option. Try '$PROGRAM --help' for more information."

eval set -- "$OPTS"
Expand All @@ -291,7 +300,10 @@ while true; do case $1 in
-s|--status) VERY_QUIET=true; B2SUM_OPTS_CHECK+=( '--status' ); shift;;
--strict) B2SUM_OPTS_CHECK+=( '--strict' ); shift;;
-w|--warn) B2SUM_OPTS_CHECK+=( '--warn' ); shift;;
-o|--output) OUTPUT_FILE="$OUTPUT_FILENAME_DEFAULT"; check_output_file; shift;;
-o|--output) OUTPUT_FILE="${2:-$OUTPUT_FILENAME_DEFAULT}"
check_output_file
shift 2
;;
--) shift; break ;;
esac done

Expand Down
24 changes: 20 additions & 4 deletions tests/t0010-basic-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@ test_expect_success 'Verify license' '
"$B2RSUM" --license | grep "under the terms of the GNU General Public License"
'

test_expect_success 'Verify default behaviour' '
"$B2RSUM" && "$B2RSUM" | grep "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce "
'

test_expect_success 'Verify invalid parameter: --invalid' '
! "$B2RSUM" --invalid
'

test_expect_success 'Verify parameter w/o argument: --output' '
"$B2RSUM" --output && [[ -r BLAKE2SUMS ]]
'

test_expect_success 'Verify parameter w/right argument: --output' '
"$B2RSUM" --output=B2SUMS && [[ -r B2SUMS ]]
'

test_expect_success 'Verify parameter w/wrong argument: --output' '
! "$B2RSUM" --output WRONG
'

test_expect_success 'Verify parameter w/o argument: --length' '
! "$B2RSUM" --length
'

test_expect_success 'Verify parameter w/wrong argument: --length' '
! "$B2RSUM" --length 7
test_expect_success 'Verify parameter w/right argument: --length' '
"$B2RSUM" --length 8
'

test_expect_success 'Verify default behaviour' '
"$B2RSUM"
test_expect_success 'Verify parameter w/wrong argument: --length' '
! "$B2RSUM" --length 7
'

test_expect_success 'Verify --quiet during creation' '
Expand Down

0 comments on commit bee54ed

Please sign in to comment.