-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
157 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -51,4 +46,3 @@ else | |
sed -E 's/^[[:blank:]]*version[[:blank:]]*=?[[:blank:]]*//' |\ | ||
sed "s/'//g" | sed 's/[[:blank:]]*$//' | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
@@ -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} . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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): | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
@@ -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 | ||
|
@@ -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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
|
Oops, something went wrong.