add sample 3 phase parse command line parse

Adjusted `inc/md2html.cfg` to improve the 3 phase parse process.

Added `tmp/sample_getopt.sh` as a demo of the 3 phase parse of command
line options and arguments for that a markdown to HTML tool that
uses the `inc/md2html.cfg` configuration file.

Try:

```sh
cd tmp
./sample_getopt.sh -v 3 foo
```

The `tmp/sample_getopt.sh` tool performs a somewhat complicated 3
phase getopt parse of simulated command line options and arguments
that a tool converting markdown to HTML and using the `inc/md2html.cfg`
configuration file would perform.  The tool does not actually use
the  `inc/md2html.cfg`, it just simulates the complex 3 phase getopt
parsing procedure.

Updated `tmp/README.md` accordingly.
This commit is contained in:
Landon Curt Noll committed 2023-12-18 00:30:11 -08:00
1 parent 19218d5fd8
commit a4bd2fff67
3 files changed
+684 -19

No files matched your search

+17 -19
View File
@@ -52,13 +52,10 @@
#
# -d topdir set topdir (def: if 'git rev-parse --is-inside-work-tree' is true, then
# topdir is output of 'git rev-parse --show-toplevel')
# -D def 'def' is default HTML phase name (def: 'default' is default phase name)
# NOTE: -d may only be used in command_options (getopt phase 0)
#
# -i inc inc files are located under topdir/inc (def: inc files are under topdir/inc)
#
# -c md2html.cfg Use md2html.cfg as the configuration file (def: use inc/md2html.cfg)
# -C dir cd dir (def: if 'git rev-parse --is-inside-work-tree' is true, then
# cd to the output of 'git rev-parse --show-cdup')
# -c md2html.cfg Use md2html.cfg as the configuration file (def: use topdir/inc/md2html.cfg)
# NOTE: -c may only be used in command_options (getopt phase 0)
#
# -H phase=name use 'phase.name.html' file for HTML phase named 'phase' (def: use 'phase.default.html')
# -H phase=. ignore processing for HTML phase 'phase' (def: process HTML phase)
@@ -69,9 +66,8 @@
# -b . skip HTML phase number 20 (def: do nothing during HTML phase number 20)
# -B optstr run 'before tool' with options found in 'optstr' (def: do not add any options to 'before tool')
#
# -p tool path to 'pandoc tool' wrapper used in HTML phase number 21 is 'tool' (def: use inc/pandoc.sh)
# -p tool run 'pandoc tool' wrapper (not path to pandoc) during HTML phase number 21 (def: use inc/pandoc.sh)
# -p . skip HTML phase number 21 (def: do nothing during HTML phase number 21)
# NOTE: The 'tool' is a 'pandoc tool' wrapper tool, NOT the path to the actual pandoc application.
# -P optstr run 'pandoc tool' with options found in 'optstr' (def: use only the 'pandoc tool' default options)
#
# -a tool run 'after tool' during HTML phase number 20 (def: do not output after pandoc tool)
@@ -85,11 +81,13 @@
#
# -o tool Use output tool, 'tool', to generate option lines (def: do not)
# -o . disable use of 'output tool' (def: do not use an 'output tool')
# NOTE: -o may only be used in command_options and cfg_options (getopt phases 0 and 1)
# -O tool=optstr run the 'token replace' named 'tool' with options found in 'optstr' (def: do not add any options)
# NOTE: The 'tool' string may not contain = (equal), nor double-quote, nor single-quote.
# NOTE: -O may only be used in command_options and cfg_options (getopt phases 0 and 1)
#
# -e exitcode force exit with exitcode (def: exit based on success or failure of the action)
# -E string output string, followed by newline, to stderr (def: do not)
# -e string output string, followed by newline, to stderr (def: do not)
# -E exitcode force exit with exitcode (def: exit based on success or failure of the action)
#
# The output from 'before tool' (unless -b .) will be used in HTML phase number 20 (before pandoc processing).
# The output from 'pandoc tool' (unless -p .) will be used HTML phase number 21 (pandoc processing).
@@ -120,14 +118,14 @@
#
# The command options are evaluated in the following getopt phases:
#
# 0. collect command line options, up to but not including any '--' or up to the command line filename argument(s)
# 0a. ((evaluate all getopt phase 0 options))
# getopt phase 0. collect command line options, up to but not including any '--' or up to the command line filename argument(s)
# getopt phase 0a. ((evaluate all getopt phase 0 options))
#
# 1. collect 'cfg_options' from the first md2html.cfg line where 'file_glob' matched the filename argument
# 1a. ((evaluate all getopt phase 1 options))
# getopt phase 1. collect 'cfg_options' from the first md2html.cfg line where 'file_glob' matched the filename argument
# getopt phase 1a. ((evaluate all getopt phase 1 options, except '-d topdir', '-c md2html.cfg' are ignored))
#
# 2. collect output of '-o tool' from getopt phase 0a and then from getopt phase 1a, in the order collected
# 2a. ((evaluate all getopt phase 2 options, except that any new '-o tool' are ignored))
# getopt phase 2. collect output of '-o tool' from getopt phase 0a and then from getopt phase 1a, in the order collected
# getopt phase 2a. ((evaluate all getopt phase 2 options, except '-d topdir', '-c md2html.cfg', '-o tool' are ignored))
#
# Command line options are evaluated in order, during each getopt phase (i.e., getopt phase 0a, then 1a, phase 2a).
#
@@ -140,8 +138,8 @@
# Also in the case of '-s token=value', later '-s token=value' only overrides an earlier use of '-s'
# for the same 'token' only.
#
# When '-e exitcode' is evaluated, the application will exit with the 'exitcode' value. If one wishes to also
# output a message to stderr, the '-E string' must come BEFORE any '-e exitcode' in the command line.
# When '-E exitcode' is evaluated, the application will exit with the 'exitcode' value. If one wishes to also
# output a message to stderr, the '-e string' must come BEFORE any '-E exitcode' in the command line.
#
# All tokens (i.e., strings of the form '%%token%%') MUST be substituted (by some -s token=value)
# in all HTML output, except during phase numbers 20-29 (i.e., except 'before tool' output, pandoc output,
@@ -262,7 +260,7 @@
# Exit 9 for any markdown file that we have not previously configured
*.md -E "markdown file does not match any md2html.cfg line" -e 200
*.md -e "markdown file does not match any md2html.cfg line" -E 200
# Last, everything else is silently ignored