From 0a5e1eece1282e39a974ab7562d8d1dcbc160169 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Thu, 13 Mar 2025 22:04:25 +0000 Subject: [PATCH] add cmdline parsing example; add json parsing example --- projects/oorexx/params.rex | 24 ++++++++++++++++++++++++ projects/python/params.py | 33 +++++++++++++++++++++++++++++++++ samples/oorexx/serialize.rex | 29 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 projects/oorexx/params.rex create mode 100755 projects/python/params.py create mode 100755 samples/oorexx/serialize.rex diff --git a/projects/oorexx/params.rex b/projects/oorexx/params.rex new file mode 100755 index 0000000..5ff039a --- /dev/null +++ b/projects/oorexx/params.rex @@ -0,0 +1,24 @@ +#!/usr/bin/env rexx + +/* Rexx */ +Address system +parse arg parms + +call parse_argv + +say "Instruction: " || instr +say "Parameter : " || parm + +exit + +parse_argv: procedure expose parms instr parm + parse var parms instr "(" parm ")" + if instr="" & parm="" then call HELP + return + +HELP: + "clear" + say "********************************************************" + say "* YOUR STRINGS WERE EMPTY. HOW DARE YOU. *" + say "********************************************************" + exit 1 \ No newline at end of file diff --git a/projects/python/params.py b/projects/python/params.py new file mode 100755 index 0000000..590d23f --- /dev/null +++ b/projects/python/params.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import sys +import os + + +def parse_argv() -> tuple: + if len(sys.argv) == 1: + help() + + sys.argv.pop(0) # remove the script name + instruction = sys.argv.pop(0) # capture the first arg + params = ' '.join(sys.argv).strip("(").strip(")") # render the remaining as a string + + return instruction, params + + +def help() -> None: + os.system('clear') + print("********************************************************") + print("* YOUR STRINGS WERE EMPTY. HOW DARE YOU. *") + print("********************************************************") + exit(1) + + +def main(): + instruction, params = parse_argv() + print(f"Instruction: {instruction}") + print(f"Parameter : {params}") +exit + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/samples/oorexx/serialize.rex b/samples/oorexx/serialize.rex new file mode 100755 index 0000000..e9ffaaf --- /dev/null +++ b/samples/oorexx/serialize.rex @@ -0,0 +1,29 @@ +#!/usr/bin/env rexx +/* serialize.rex */ +test = .array~new() + +test~append(.directory~new()) +test[test~last]['name'] = 'Adam' +test[test~last]['location'] = 'NC' +test[test~last]['terminated'] = .true +test[test~last]['number'] = 2 +test[test~last]['description'] = 'The quick brown fox jumped over the lazy dog.'.endofline||'The quick brown fox jumped over the lazy dog.' + +test~append(.directory~new()) +test[test~last]['name'] = 'Bob' +test[test~last]['location'] = 'SC' +test[test~last]['terminated'] = .false +test[test~last]['number'] = 10 +test[test~last]['description'] = .nil + +test~append(.directory~new()) +test[test~last]['name'] = 'Carl' +test[test~last]['location'] = 'VA' +test[test~last]['terminated'] = .false +test[test~last]['number'] = 15 +test[test~last]['description'] = .nil + +say .json~new()~toJSON(test) +Exit + +::requires 'json.cls' \ No newline at end of file