aboutsummaryrefslogtreecommitdiff
path: root/v2/src/bin/extract
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xv2/src/bin/extract18
1 files changed, 12 insertions, 6 deletions
diff --git a/v2/src/bin/extract b/v2/src/bin/extract
index ce4b115..4380be7 100755
--- a/v2/src/bin/extract
+++ b/v2/src/bin/extract
@@ -5,7 +5,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- extract -t TYPE < STDIN
+ extract -t TYPE FILENAME
extract -h
EOF
}
@@ -17,21 +17,24 @@ help() {
-t TYPE the type of extraction to perform ("content" or "env")
-h, --help show this message
+ FILENAME the name of the input file, also to be used as
+ URL.
+
Separate the content from the "frontmatter", and emit the
- selected one.
+ selected one, given the FILENAME.
Examples:
Get the content:
- $ extract -t content < src/file.md > src/file.entry-content
+ $ extract -t content src/file.md > src/file.entry-content
Get the "frontmatter":
- $ extract -t env < src/f.md > src/f.entry-env
+ $ extract -t env src/f.md > src/f.entry-env
EOF
}
@@ -71,6 +74,8 @@ done
shift $((OPTIND - 1))
+FILENAME="${1:-}"
+eval "$(assert-arg "$FILENAME" 'FILENAME')"
eval "$(assert-arg "$TYPE" '-t TYPE')"
@@ -79,7 +84,7 @@ case "$TYPE" in
awk '
separator >= 2
/^---$/ { separator++ }
- '
+ ' "$FILENAME"
;;
env)
awk '
@@ -92,7 +97,8 @@ case "$TYPE" in
}
{ print }
- '
+ ' "$FILENAME"
+ printf "FILENAME='%s'\n" "$FILENAME"
;;
*)
printf 'Bad value for TYPE: "%s".\n\n' \