| 1 |
#!/usr/bin/env runawk |
| 2 |
|
| 3 |
#use "power_getopt.awk" |
| 4 |
|
| 5 |
#.begin-str help |
| 6 |
# power_getopt - program demonstrating a power of power_getopt.awk module |
| 7 |
# usage: power_getopt [OPTIONS] |
| 8 |
# OPTIONS: |
| 9 |
# -h|--help display this screen |
| 10 |
# -f|--flag flag |
| 11 |
# --long-flag long flag only |
| 12 |
# -s short flag only |
| 13 |
# =F|--FLAG <value> flag with value |
| 14 |
# =-LONG-FLAG <value> long flag with value |
| 15 |
# =S <value> short flag with value |
| 16 |
# -X short flag |
| 17 |
# =Y <value> short flag with value |
| 18 |
# -P print ARGC and ARGV |
| 19 |
#.end-str |
| 20 |
|
| 21 |
# Very powerful easy for use module for handling options |
| 22 |
|
| 23 |
BEGIN { |
| 24 |
if (getarg("P")){ |
| 25 |
print "ARGC=" ARGC |
| 26 |
for (i=1; i < ARGC; ++i){ |
| 27 |
printf "ARGV [%d]=%s\n", i, ARGV [i] |
| 28 |
} |
| 29 |
exit (0) |
| 30 |
} |
| 31 |
|
| 32 |
print "The following option were applied" |
| 33 |
for (i in options){ |
| 34 |
print "options [" i "]=" options [i] |
| 35 |
} |
| 36 |
print "f --- " getarg("f") |
| 37 |
print "flag --- " getarg("flag") |
| 38 |
print "long-flag --- " getarg("long-flag") |
| 39 |
print "s --- " getarg("s") |
| 40 |
print "F --- " getarg("F", "default1") |
| 41 |
print "FLAG --- " getarg("FLAG", "default2") |
| 42 |
print "LONG-FLAG --- " getarg("LONG-FLAG", "default3") |
| 43 |
print "S --- " getarg("S", "default4") |
| 44 |
print "X --- " getarg("X") |
| 45 |
print "Y --- " getarg("Y", "default5") |
| 46 |
|
| 47 |
|
| 48 |
exit 0 |
| 49 |
} |