-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.xonsh
More file actions
executable file
·56 lines (52 loc) · 1.94 KB
/
example.xonsh
File metadata and controls
executable file
·56 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env xonsh
# NOTE if youre actually using this as reference, please just use argparse, its much better, more complete, less hacky, and actually python
# im not really even sure why i went through all the effort to be able to support xonsh
# maybe itll be easier to add more languages or something because of it, but mostly its just dumb
echo $ARGS
#import os
#pid = os.getpid()
#cat -v /proc/@(pid)/cmdline
#cat /proc/@(pid)/comm
# TODO figure out how to get exiting working
make or exit(1)
spec = 'flags: f,flag=-g=-h g=-h=-qwerty qwerty=-flag=-h=-g h,help; parameters: q,asdf u=defval nothing zzz,z,Z=someth; positionals: asdf test;'
helpmsg = '''
help = print this help message
flag = a random flag
g = i dunno, its nonsense
qwerty = a keyboard layout
asdf = q param
u = something
zzz = a bunch of zs
'''
print(spec)
# print out the raw output
echo raw output:
parser_output = !(echo @(spec) | ./clparser -s xonsh --prog-name $ARG0 -e --help-msg @(helpmsg) -- @($ARGS[1:]))
ec = parser_output.returncode
vars = parser_output.output
print(vars)
print(parser_output.errors)
if ec != 0:
print(f'exit code: {ec}')
exit(ec)
# actually run it and show results
echo 'variable results:'
#$XONSH_SHOW_TRACEBACK = True
# execx isn't really documented well, so its annoying that they changed the name of the globals keyword
execx(vars, glbs=globals())
#execx($(echo @(spec) | ./clparser -s xonsh -e --help-msg @(helpmsg) -- @($ARGS[1:])), glbs=globals())
print(f'f,flag = { flags["flag"]}')
print(f'g = { flags["g"]}')
print(f'qwerty = { flags["qwerty"]}')
print(f'h,help = { flags["help"]}')
print(f'q,asdf = {params["asdf"]}')
print(f'u = {params["u"]}')
print(f'nothing = {params["nothing"]}')
print(f'zzz,z,Z = {params["Z"]}')
print('positional params:')
print(f'asdf = {positionals["asdf"]}')
print(f'test = {positionals["test"]}')
#printf 'positional args: %s\n' $ARGS
#print(f'positional args: {$ARGS}')
print(f'positional args: {args}')