Skip to content

Commit

Permalink
[spec/oil] Create two basic spec tests for argparse builtin (#1395)
Browse files Browse the repository at this point in the history
Part of #469
  • Loading branch information
Melkor333 authored Nov 1, 2022
1 parent 8d3af9b commit 3639caf
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions spec/oil-builtin-argparse.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,60 @@
#
# Some thoughts before writing code. Hm can we do this entirely in user code, not as a builtin?
#
# I think it modifies OPT
# The following is as close as possible to the python argparse which seems to work well

#### Argparse boolsche option and positional
hay define ArgSpec
hay define ArgSpec/Arg

#### Argparse Prototype

hay define argparse
ArgSpec myspec {
Arg -v --verbose { type = Bool }
Arg src
Arg dst
}
var args = ['-v', 'src/path', 'dst/path']
argparse (myspec, args, :opts)

# Oops, we're running into this problem ...
json write (opts)
json write (args)
## STDOUT:
{
"verbose": true,
"src": "src/path",
"dst": "dst/path"
}
# TODO: Should this be empty afterwards? Is it even possible with above call?
[

hay define argparse/flag
]
## END

# This means we need expr.Type objects?
#### Argparse basic help message
hay define ArgSpec
hay define ArgSpec/Arg

ArgSpec myspec {
description = '''
Reference Implementation
'''
prog = "program-name"
Arg -v --verbose { type = Bool; help = "Verbose" }
Arg src
Arg dst
}
var args = ['-h', 'src', 'dst']

argparse foo {
flag -v --verbose (Bool) {
help = 'fo'
default = true
}
argparse (myspec, args, :opts)
## STDOUT:
usage: program-name [-h] [-v] src dst

flag -h --help (Bool) {
help = 'fo'
}
Reference Implementation

arg name (pos = 1) {
foo
}
}
positional arguments:
src
dst

## STDOUT:
TODO
options:
-h, --help show this help message and exit
-v, --verbose Verbose
## END

0 comments on commit 3639caf

Please sign in to comment.