add cmdline parsing example; add json parsing example
This commit is contained in:
parent
e64e978f01
commit
0a5e1eece1
24
projects/oorexx/params.rex
Executable file
24
projects/oorexx/params.rex
Executable file
@ -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
|
33
projects/python/params.py
Executable file
33
projects/python/params.py
Executable file
@ -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()
|
29
samples/oorexx/serialize.rex
Executable file
29
samples/oorexx/serialize.rex
Executable file
@ -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'
|
Loading…
Reference in New Issue
Block a user