Skip to content

Commit

Permalink
Release Ver. 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mmassenzio committed Dec 30, 2023
2 parents 38a9c42 + 59e81ce commit 51ea5a4
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 56 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,19 @@ docs/apidocs/
# CMake files
CMakeCache.txt
CMakeFiles/
Makefile
cmake_install.cmake
gen/
cmake_install.cmake
cmake-build-debug

# Recommended build directory
build/
Debug/
.conan/

# Compiler intermediate files
.o
.so
.la

cmake-build-debug
__pycache__/

*.tar
*.gz
__pycache__/
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])

TESTDIR := tests

test:
@echo "--- Running tests in the ${TESTDIR} directory"
python -m unittest discover -s ${TESTDIR}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,20 @@ An optional trailing `modifier` changes the meaning of the argument:

- `!` : indicates a required argument, its absence will cause an error;
- `-` : designates a boolean argument, which takes no value and whose presence will result in the corresponding variable to be set);
- `+` : a positional, required, argument;
- `?` : an optional positional argument.
- `+` : a *positional*, required, argument;
- `?` : an optional *positional* argument.
- `*` : an array of *positional* arguments (possibly empty, if none is present);
should be obviously last.

> *NOTE*
>
> "Positional" arguments are those which are not preceded by a `--arg` flag and whose **order** matters when the command line is parsed. As such, obviously, an *optional* positional **must** be the last in the list.
> "Positional" arguments are those which are not preceded by a `--arg` flag and whose **order**
matters when the command line is parsed. As such, obviously, an *optional* positional
(or an array) **must** be the last in the list.
>
> It is best to avoid combining optional positionals (`?`) and positional arrays (`*`) as they may
result in unexpected behavior.


For example (see the [`parse_example`](parse_example) script):

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
Expand Down
8 changes: 1 addition & 7 deletions get-version.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
# Usage: get-version BUILD
# Extracts version from the build settings
#
# BUILD either a build.gradle file, or build.settings with a `VERSION = <version>` line
# or a JSON Manifest with a "version" field.

set -eu

Expand Down Expand Up @@ -51,4 +46,3 @@ else
sed -E 's/^[[:blank:]]*version[[:blank:]]*=?[[:blank:]]*//' |\
sed "s/'//g" | sed 's/[[:blank:]]*$//'
fi

19 changes: 19 additions & 0 deletions head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
~ Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
~
~ Licensed under the Apache License, Version 2.0
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Author: Marco Massenzio ([email protected])
-->

<html lang="en" data-bs-theme="dark">
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ"
crossorigin="anonymous">
<title>Common Utils</title>
</head>
<body>
<div style="margin-left: 50px;">
9 changes: 9 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#

set -eu

declare -r TARBALL="https://github.com/massenz/common-utils/releases/download/$VERSION/common-utils-$VERSION.tar.gz"
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version" : "0.7.5",
"version" : "0.8.0",
"metadata": {
"author": "[email protected]",
"comment": "Common utilities for Shell Scripts"
Expand Down
6 changes: 3 additions & 3 deletions package-utils.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
# Packages this project's scripts into a downloadable tarball
set -eu
source utils.sh

Expand All @@ -30,7 +29,8 @@ done
cp -r commons.cmake parse_args.py templates/ $DEST/

# Generate HTML instructions.
pandoc README.md -t html -o ${DEST}/README.html
pandoc README.md -t html -o /tmp/README.html
cat head.html /tmp/README.html >${DEST}/README.html
popd

tar cf ${TARBALL} -C ${DEST} .
Expand Down
2 changes: 1 addition & 1 deletion parse-args.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
Expand Down
27 changes: 24 additions & 3 deletions parse_args.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@

# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
Expand All @@ -12,7 +22,7 @@
from tempfile import mkstemp


MODIFIED_PATTERN = re.compile(r"(?P<opt>\w+)(?P<modifier>[-!?+])?")
MODIFIED_PATTERN = re.compile(r"(?P<opt>\w+)(?P<modifier>[-!?+*])?")


class StderrParser(argparse.ArgumentParser):
Expand Down Expand Up @@ -48,6 +58,9 @@ def make_parser(*args):
elif mod == '?':
prefix = ''
kwargs['nargs'] = '?'
elif mod == '*':
prefix = ''
kwargs['nargs'] = '*'
else:
prefix = '--'
parser.add_argument(f"{prefix}{m.group('opt')}", **kwargs)
Expand All @@ -74,7 +87,15 @@ def main(names, values):
tmpfile = mkstemp(text=True)[1]
with open(tmpfile, 'w') as dest:
for key, val in options.items():
dest.write(f"{key}={val}\n")
# Arrays in Shell scripts are declared differently
# from how Python prints them out.
if isinstance(val, list):
dest.write(f"{key}=(")
for item in val:
dest.write(f"{item} ")
dest.write(")\n")
else:
dest.write(f"{key}={val}\n")
print(tmpfile)


Expand Down
41 changes: 22 additions & 19 deletions parse_example
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
#
# Example script for the `parse-args` script
#
# Usage: parse_example [-h] [--keep] [--take TAKE] --counts COUNTS [--mount MOUNT]
#
# Use `./parse_example -h` to get a full description of the available CLI args that
# this command makes available to the script.
#
# For this to work, you need to have installed `common-utils` as detailed in README
# and added the install directory (COMMON_UTILS) to the PATH.

# This prevents `source` to be invoked at all (and most likely error out)
# when parse-args fails to parse the given arguments.
Expand All @@ -26,15 +16,22 @@ set -e
# A trailing `-` denotes a bool flag (its presence will set the associated variable, no
# value expected); use `!` for a required named option, and `+` for a required positional.
# Use `?` for an optional positional arg.
PARSED=$(parse-args keep- take counts! mount+ attach? -- $@)
PARSED=$(python ./parse_args.py keep- take counts! mount+ attach* -- $@)

# The values are stored in a temporary file called ${PARSED}
# It can be safely ignored, and will be eventually removed by the system.
# This line injects the values into this script:
source ${PARSED}

# For example:
#
# $ ./parse_example --keep --take 3 --counts 5 /dev/fpo
# Keeping mount: /dev/fpo
# Take 3, counts: 5
# attach was: []
# $ ./parse_example --keep --take 3 --counts 5 /dev/fpo /dev/sba /dev/sbb
#
# Keeping mount: /dev/fpo
# Take 3, counts: 5
# attach was: [/dev/sba /dev/sbb]
# Mount point: /dev/sba
# Mount point: /dev/sbb

# Here we are using the parsed arguments as ordinary bash variables.
if [[ -n ${keep} ]]; then
Expand All @@ -43,9 +40,15 @@ fi

echo "Take ${take}, counts: ${counts}"

# The last positional, `attach` was optional, so it may be empty or not;
# The last positional, `attach` is an array, so it may be empty or not;
# and, if empty, it won't cause an error.
echo "attach was: [${attach}]"
echo "attach was: [${attach[*]}]"

# To iterate over the array, you can use:
for mount_point in "${attach[@]}"; do
echo "Mount point: $mount_point"
done


# This is optional, and removes the temporary file.
rm ${PARSED}
# rm ${PARSED}
2 changes: 1 addition & 1 deletion runtests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
Expand Down
10 changes: 10 additions & 0 deletions tail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
</div>
</body>
</html><!--
~ Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
~
~ Licensed under the Apache License, Version 2.0
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Author: Marco Massenzio ([email protected])
-->
5 changes: 1 addition & 4 deletions templates/go-make-version-tag.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 AlertAvert.com. All rights reserved.
# Copyright (c) 2020-2023 AlertAvert.com. All rights reserved.
#
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Author: Marco Massenzio ([email protected])
#
# Given the build version extracted by the `get-version` script,
# it will build a version tag which is "idiomatic" for Golang projects.
#
set -eu

BUILD_SETTINGS=${1:-build.settings}
Expand Down
Loading

0 comments on commit 51ea5a4

Please sign in to comment.