Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 164 lines (117 sloc) 4.564 kb
#!/bin/sh
set -ex
#
# pretty-printing args as Piq AST
#
piqi getopt # empty input
piqi getopt -- # empty input
piqi getopt -- foo
piqi getopt -- 10 -20 30.0 -0.inf 0.nan '"foo\r"' '"\xff"' --fum [ --foo bar [] ] --baz
#
# converting args to Piq objects
#
# NOTE: converting to encodings other than Piq (controlled by -t parameter) is
# tested as a part of "piqi convert" testing as they share the same
# functionality
#
# built-in types
piqi getopt --piqtype bool -- true
piqi getopt --piqtype int -- -10
piqi getopt --piqtype float -- -0.inf
piqi getopt --piqtype string -- foo # parsing words as strings
piqi getopt --piqtype string -- foo\ bar
piqi getopt --piqtype string -- '"\tfoo\x20\u0045"'
piqi getopt --piqtype string -- "привет"
piqi getopt --piqtype binary -- '"\x00ab\tcd\xff\xfe"'
piqi getopt --piqtype piqi-any -- 10 -20 30.0 -0.inf 0.nan '"foo\r"' '"\xff"' --fum [ --foo bar [] ] --baz
# complex types
piqi getopt --piqtype complex/t -- .re 0 .im 0
piqi getopt --piqtype complex/t -- --re 0 --im 0
piqi getopt --piqtype complex/t -- 0 0
piqi getopt --piqtype complex/foo
piqi getopt --piqtype complex/foo --
piqi getopt --piqtype complex/foo --add-defaults --
piqi getopt --piqtype def/r -- -i 0 --flag
piqi getopt --piqtype def/r -- -i 0 --flag
piqi getopt --piqtype def/r -- -i 0 --flag
piqi getopt --piqtype def/int-list
piqi getopt --piqtype def/int-list --
piqi getopt --piqtype def/int-list -- 1 2 3 4 5
piqi getopt --piqtype def/int-list-list
piqi getopt --piqtype def/int-list-list --
piqi getopt --piqtype def/int-list-list -- [] [ 1 2 3 ]
piqi getopt --piqtype record-variant-list/r -- -a 0 -b 1
piqi getopt --piqtype record-variant-list/l -- -a 0 -b 1
piqi getopt --piqtype record-variant-list/v -- -a 0
piqi getopt --piqtype record-variant-list/v -- -b 1
# test for a top-level enum value
piqi getopt --piqtype def/e -t pb -- -a | piqi convert -f pb --piqtype def/e
piqi getopt --piqtype def/e -t json -- -a | piqi convert -f json --piqtype def/e
piqi getopt --add-defaults -t json --piqtype person/person -- \
--name "J. Random Hacker" \
--id 0 \
--email "j.r.hacker@example.com" \
--phone [ --number "(111) 123 45 67" ] \
--phone [ \
--number "(222) 123 45 67" \
--mobile \
] \
--phone [ \
--number "(333) 123 45 67" \
--work \
]
piqi getopt --piqtype person/person -- \
.name "Joe User" \
.id 1 \
.phone [ "(444) 123 45 67" ] \
.phone [ "(555) 123 45 67" .work ]
piqi getopt --piqtype function/bar-input -- 10
piqi getopt --piqtype function/bar-output -- 1
piqi getopt --piqtype function/bar-error -- 100.0
piqi getopt --piqtype function/baz-input --
piqi getopt --piqtype function/baz-input --add-defaults --
# treat an argument starting with '@' as a name of the file that neads to be
# read into a string
piqi getopt --piqtype string -- @string.piq
# parsing file's contents as a binary
piqi getopt --piqtype binary -- @string.piq
#
# parsing long and short options
#
# record fields
piqi getopt --piqtype getopt/r -- --long-option 1
piqi getopt --piqtype getopt/r -- -o 1
piqi getopt --piqtype getopt/r -- --long-flag
piqi getopt --piqtype getopt/r -- -f
piqi getopt --piqtype getopt/r -- --long-flag -o 1 --long-g
piqi getopt --piqtype getopt/r -- -f --long-option 1 -g
# short options combined
piqi getopt --piqtype getopt/r -- -fo 1 -g
piqi getopt --piqtype getopt/r -- -gfo 1
piqi getopt --piqtype getopt/r -- -fgo 1
# variant options
piqi getopt --piqtype getopt/v -- --long-option 1
piqi getopt --piqtype getopt/v -- -o 1
piqi getopt --piqtype getopt/v -- --long-flag
piqi getopt --piqtype getopt/v -- -f
# enum flags
piqi getopt --piqtype getopt/e -- --long-flag
piqi getopt --piqtype getopt/e -- -f
piqi getopt --piqtype getopt/e -- --long-g
piqi getopt --piqtype getopt/e -- -g
# list of variants
# each option mentioned only once
piqi getopt --piqtype getopt/l -- --long-option 1
piqi getopt --piqtype getopt/l -- -o 1
piqi getopt --piqtype getopt/l -- --long-flag
piqi getopt --piqtype getopt/l -- -f
# both options are present in the list
piqi getopt --piqtype getopt/l -- -f --long-option 1
piqi getopt --piqtype getopt/l -- -o 1 --long-flag
# each option mentioned two times using different notations:
piqi getopt --piqtype getopt/l -- -f --long-option 1 -o 1 --long-flag
# short options combined
piqi getopt --piqtype getopt/l -- -fo 1 -g
piqi getopt --piqtype getopt/l -- -gfo 1
piqi getopt --piqtype getopt/l -- -fgo 1
piqi getopt --piqtype getopt/l -- -fgo 1 -fgo 1 -gf
Jump to Line
Something went wrong with that request. Please try again.