mirror of
https://github.com/denisidoro/navi
synced 2024-11-22 03:23:05 +00:00
Validate variable names (#29)
This commit is contained in:
parent
d42d192bdd
commit
44c4d9551f
6 changed files with 45 additions and 22 deletions
|
@ -17,7 +17,7 @@ jobs:
|
|||
<<: *defaults
|
||||
steps:
|
||||
- checkout
|
||||
- run: ./test/find_cheats
|
||||
- run: ./test/run
|
||||
|
||||
workflows:
|
||||
version: 2
|
||||
|
|
|
@ -1,23 +1,21 @@
|
|||
% git
|
||||
|
||||
# Set global git user name
|
||||
git config --global user.name "<name>"
|
||||
git config --global user.name <name>
|
||||
|
||||
# Set global git user email
|
||||
git config --global user.email "<email>"
|
||||
git config --global user.email <email>
|
||||
|
||||
# Initializes a git repository
|
||||
git init
|
||||
|
||||
# Adds a remote for a git repository
|
||||
git remote add <remote name> <remote URL>
|
||||
git remote add <remote_name> <remote_url>
|
||||
|
||||
# Checkout to branch
|
||||
# Change branch
|
||||
git checkout <branch>
|
||||
|
||||
$ branch: git branch --format='%(refname:short)'
|
||||
|
||||
# Displays the current status of a git repository
|
||||
git status
|
||||
|
||||
|
@ -31,22 +29,22 @@ git add <filename>
|
|||
git add .
|
||||
|
||||
# Saves the changes to a file in a commit
|
||||
git commit -m "<commit message>"
|
||||
git commit -m "<message>"
|
||||
|
||||
# Pushes committed changes to remote repository
|
||||
git push -u <remote name> <branch name>
|
||||
git push -u <remote_name> <branch_name>
|
||||
|
||||
# Pushes changes to a remote repository overwriting another branch
|
||||
git push <remote name> <branch>:<branch to overwrite>
|
||||
git push <remote_name> <branch>:<branch_to_overwrite>
|
||||
|
||||
# Overwrites remote branch with local branch changes
|
||||
git push <remote name> <branch name> -f
|
||||
git push <remote_name> <branch_name> -f
|
||||
|
||||
# Pulls changes to a remote repo to the local repo
|
||||
git pull --ff-only
|
||||
|
||||
# Merges changes on one branch into current branch
|
||||
git merge <branch name>
|
||||
git merge <branch_name>
|
||||
|
||||
# Displays log of commits for a repo
|
||||
git log
|
||||
|
@ -59,3 +57,5 @@ git clean -dxf
|
|||
|
||||
# Sign all commits in a branch based on master
|
||||
git rebase master -S -f
|
||||
|
||||
$ branch: git branch --format='%(refname:short)'
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ARG_REGEX="<[0-9a-zA-Z_]+>"
|
||||
|
||||
arg::fn() {
|
||||
awk -F'---' '{print $1}'
|
||||
}
|
||||
|
@ -16,7 +18,7 @@ arg::interpolate() {
|
|||
}
|
||||
|
||||
arg::next() {
|
||||
grep -Eo '<[0-9a-zA-Z_]+>' \
|
||||
grep -Eo "$ARG_REGEX" \
|
||||
| head -n1 \
|
||||
| tr -d '<' \
|
||||
| tr -d '>'
|
||||
|
|
|
@ -9,4 +9,11 @@ test::success() {
|
|||
test::fail() {
|
||||
echo "Test failed..."
|
||||
exit 42
|
||||
}
|
||||
|
||||
test::run() {
|
||||
echo
|
||||
echo "-> $1"
|
||||
shift
|
||||
eval "$*" && test::success || test::fail
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
source "${SCRIPT_DIR}/test/core.sh"
|
||||
|
||||
cheat::find \
|
||||
| grep -q "docker.cheat" \
|
||||
&& test::success \
|
||||
|| test::fail
|
24
test/run
Executable file
24
test/run
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
export SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
source "${SCRIPT_DIR}/test/core.sh"
|
||||
|
||||
check_all_vars() {
|
||||
local arg
|
||||
IFS=$'\n'
|
||||
for var in $(cat "$1" | grep -Eo "<[^>]*>"); do
|
||||
if ! echo "$var" | grep -qE "$ARG_REGEX"; then
|
||||
echoerr "$var isn't a valid variable name!"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
test::run "We can find at least one known cheatsheet" \
|
||||
'cheat::find | grep -q "docker.cheat"'
|
||||
|
||||
for cheat in $(cheat::find); do
|
||||
test::run "All variables in $(basename $cheat) are valid" \
|
||||
'check_all_vars "$cheat"'
|
||||
done
|
Loading…
Reference in a new issue