| 1 | #!/usr/bin/env python2
|
| 2 | """Flag parser defintions."""
|
| 3 |
|
| 4 | from __future__ import print_function
|
| 5 |
|
| 6 | from frontend import args
|
| 7 | from frontend.flag_spec import (FlagSpec, FlagSpecAndMore, _FlagSpecAndMore)
|
| 8 | from frontend import option_def
|
| 9 |
|
| 10 | #
|
| 11 | # Definitions for builtin_assign
|
| 12 | #
|
| 13 |
|
| 14 | EXPORT_SPEC = FlagSpec('export_')
|
| 15 | EXPORT_SPEC.ShortFlag('-n')
|
| 16 | EXPORT_SPEC.ShortFlag('-f') # stubbed
|
| 17 | EXPORT_SPEC.ShortFlag('-p')
|
| 18 |
|
| 19 | READONLY_SPEC = FlagSpec('readonly')
|
| 20 |
|
| 21 | # TODO: Check the consistency of -a and -A against values, here and below.
|
| 22 | READONLY_SPEC.ShortFlag('-a')
|
| 23 | READONLY_SPEC.ShortFlag('-A')
|
| 24 | READONLY_SPEC.ShortFlag('-p')
|
| 25 |
|
| 26 | NEW_VAR_SPEC = FlagSpec('new_var')
|
| 27 |
|
| 28 | # print stuff
|
| 29 | NEW_VAR_SPEC.ShortFlag('-f')
|
| 30 | NEW_VAR_SPEC.ShortFlag('-F')
|
| 31 | NEW_VAR_SPEC.ShortFlag('-p')
|
| 32 |
|
| 33 | NEW_VAR_SPEC.ShortFlag('-g') # Look up in global scope
|
| 34 |
|
| 35 | # Options +r +x +n
|
| 36 | NEW_VAR_SPEC.PlusFlag('x') # export
|
| 37 | NEW_VAR_SPEC.PlusFlag('r') # readonly
|
| 38 | NEW_VAR_SPEC.PlusFlag('n') # named ref
|
| 39 |
|
| 40 | # Common between readonly/declare
|
| 41 | NEW_VAR_SPEC.ShortFlag('-a')
|
| 42 | NEW_VAR_SPEC.ShortFlag('-A')
|
| 43 | NEW_VAR_SPEC.ShortFlag('-i') # no-op for integers
|
| 44 | NEW_VAR_SPEC.ShortFlag('-u') # no-op for case
|
| 45 | NEW_VAR_SPEC.ShortFlag('-l') # no-op for case
|
| 46 |
|
| 47 | UNSET_SPEC = FlagSpec('unset')
|
| 48 | UNSET_SPEC.ShortFlag('-v')
|
| 49 | UNSET_SPEC.ShortFlag('-f')
|
| 50 | #UNSET_SPEC.ShortFlag('-z', args.String)
|
| 51 |
|
| 52 | #
|
| 53 | # Definitions for builtin_meta
|
| 54 | #
|
| 55 |
|
| 56 | # Unused because there are no flags! Just --.
|
| 57 | EVAL_SPEC = FlagSpec('eval')
|
| 58 | SOURCE_SPEC = FlagSpec('source')
|
| 59 | SOURCE_SPEC.LongFlag('--builtin')
|
| 60 |
|
| 61 | BUILTIN_SPEC = FlagSpec('builtin')
|
| 62 |
|
| 63 | COMMAND_SPEC = FlagSpec('command')
|
| 64 | COMMAND_SPEC.ShortFlag('-v')
|
| 65 | COMMAND_SPEC.ShortFlag('-V')
|
| 66 | COMMAND_SPEC.ShortFlag('-p')
|
| 67 |
|
| 68 | TYPE_SPEC = FlagSpec('type')
|
| 69 | TYPE_SPEC.ShortFlag('-f')
|
| 70 | TYPE_SPEC.ShortFlag('-t')
|
| 71 | TYPE_SPEC.ShortFlag('-p')
|
| 72 | TYPE_SPEC.ShortFlag('-P')
|
| 73 | TYPE_SPEC.ShortFlag('-a')
|
| 74 |
|
| 75 | #
|
| 76 | # Definitions for builtin_pure
|
| 77 | #
|
| 78 |
|
| 79 | ALIAS_SPEC = FlagSpec('alias') # no flags yet
|
| 80 | UNALIAS_SPEC = FlagSpec('unalias') # no flags yet
|
| 81 | UNALIAS_SPEC.ShortFlag('-a')
|
| 82 |
|
| 83 | SHOPT_SPEC = FlagSpec('shopt')
|
| 84 | SHOPT_SPEC.ShortFlag('-s', long_name='--set')
|
| 85 | SHOPT_SPEC.ShortFlag('-u', long_name='--unset')
|
| 86 | SHOPT_SPEC.ShortFlag('-o') # use 'set -o' names
|
| 87 | # TODO: --print could print in a verbose format. (Annoying: codegen conflicts
|
| 88 | # with Python keyword.)
|
| 89 | SHOPT_SPEC.ShortFlag('-p')
|
| 90 | SHOPT_SPEC.ShortFlag('-q') # query option settings
|
| 91 |
|
| 92 | HASH_SPEC = FlagSpec('hash')
|
| 93 | HASH_SPEC.ShortFlag('-r')
|
| 94 |
|
| 95 | ECHO_SPEC = FlagSpec('echo')
|
| 96 | ECHO_SPEC.ShortFlag('-e') # no backslash escapes
|
| 97 | ECHO_SPEC.ShortFlag('-n')
|
| 98 |
|
| 99 | #
|
| 100 | # osh/builtin_printf.py
|
| 101 | #
|
| 102 |
|
| 103 | PRINTF_SPEC = FlagSpec('printf')
|
| 104 | PRINTF_SPEC.ShortFlag('-v', args.String)
|
| 105 |
|
| 106 | #
|
| 107 | # osh/builtin_misc.py
|
| 108 | #
|
| 109 |
|
| 110 | READ_SPEC = FlagSpec('read')
|
| 111 | READ_SPEC.ShortFlag('-r')
|
| 112 | READ_SPEC.ShortFlag('-s') # silent
|
| 113 | READ_SPEC.ShortFlag('-u', args.Int) # file descriptor
|
| 114 | READ_SPEC.ShortFlag('-t', args.Float) # timeout
|
| 115 | READ_SPEC.ShortFlag('-n', args.Int)
|
| 116 | READ_SPEC.ShortFlag('-N', args.Int)
|
| 117 | READ_SPEC.ShortFlag('-a', args.String) # name of array to read into
|
| 118 | READ_SPEC.ShortFlag('-d', args.String)
|
| 119 | READ_SPEC.ShortFlag('-p', args.String) # prompt
|
| 120 | # bash supports -i text for GNU readline. Different than -p
|
| 121 | # -e
|
| 122 |
|
| 123 | # OSH extension (not really considered YSH!)
|
| 124 | READ_SPEC.ShortFlag('-0') # until NUL, like IFS= read -r -d ''
|
| 125 | # Arguably it could be named like
|
| 126 | # grep --null -Z
|
| 127 | # xargs --null -0
|
| 128 | # But this format is NOT recommended in YSH! It's unbuffered and slow. We
|
| 129 | # prefer lines with escaping.
|
| 130 |
|
| 131 | READ_SPEC.LongFlag('--all')
|
| 132 | READ_SPEC.LongFlag('--raw-line')
|
| 133 | READ_SPEC.LongFlag('--num-bytes', args.Int)
|
| 134 | # don't strip the trailing newline
|
| 135 | READ_SPEC.LongFlag('--with-eol')
|
| 136 |
|
| 137 | MAPFILE_SPEC = FlagSpec('mapfile')
|
| 138 | MAPFILE_SPEC.ShortFlag('-t')
|
| 139 |
|
| 140 | CD_SPEC = FlagSpec('cd')
|
| 141 | CD_SPEC.ShortFlag('-L')
|
| 142 | CD_SPEC.ShortFlag('-P')
|
| 143 |
|
| 144 | PUSHD_SPEC = FlagSpec('pushd')
|
| 145 |
|
| 146 | POPD_SPEC = FlagSpec('popd')
|
| 147 |
|
| 148 | DIRS_SPEC = FlagSpec('dirs')
|
| 149 | DIRS_SPEC.ShortFlag('-c')
|
| 150 | DIRS_SPEC.ShortFlag('-l')
|
| 151 | DIRS_SPEC.ShortFlag('-p')
|
| 152 | DIRS_SPEC.ShortFlag('-v')
|
| 153 |
|
| 154 | PWD_SPEC = FlagSpec('pwd')
|
| 155 | PWD_SPEC.ShortFlag('-L')
|
| 156 | PWD_SPEC.ShortFlag('-P')
|
| 157 |
|
| 158 | HELP_SPEC = FlagSpec('help')
|
| 159 | #HELP_SPEC.ShortFlag('-i') # show index
|
| 160 | # Note: bash has help -d -m -s, which change the formatting
|
| 161 |
|
| 162 | BIND_SPEC = FlagSpec('bind')
|
| 163 | BIND_SPEC.ShortFlag('-m', args.String)
|
| 164 | BIND_SPEC.ShortFlag('-q', args.String)
|
| 165 | BIND_SPEC.ShortFlag('-u', args.String)
|
| 166 | BIND_SPEC.ShortFlag('-r', args.String)
|
| 167 | BIND_SPEC.ShortFlag('-f', args.String)
|
| 168 | BIND_SPEC.ShortFlag('-x', args.String)
|
| 169 | BIND_SPEC.ShortFlag('-l')
|
| 170 | BIND_SPEC.ShortFlag('-p')
|
| 171 | BIND_SPEC.ShortFlag('-s')
|
| 172 | BIND_SPEC.ShortFlag('-v')
|
| 173 | BIND_SPEC.ShortFlag('-P')
|
| 174 | BIND_SPEC.ShortFlag('-S')
|
| 175 | BIND_SPEC.ShortFlag('-V')
|
| 176 | BIND_SPEC.ShortFlag('-X')
|
| 177 |
|
| 178 | HISTORY_SPEC = FlagSpec('history')
|
| 179 | HISTORY_SPEC.ShortFlag('-a')
|
| 180 | HISTORY_SPEC.ShortFlag('-r')
|
| 181 | HISTORY_SPEC.ShortFlag('-c')
|
| 182 | HISTORY_SPEC.ShortFlag('-d', args.Int)
|
| 183 |
|
| 184 | #
|
| 185 | # osh/builtin_process.py
|
| 186 | #
|
| 187 |
|
| 188 | EXEC_SPEC = FlagSpec('exec')
|
| 189 |
|
| 190 | WAIT_SPEC = FlagSpec('wait')
|
| 191 | WAIT_SPEC.ShortFlag('-n')
|
| 192 | WAIT_SPEC.LongFlag('--all')
|
| 193 | WAIT_SPEC.LongFlag('--verbose')
|
| 194 |
|
| 195 | TRAP_SPEC = FlagSpec('trap')
|
| 196 | TRAP_SPEC.ShortFlag('-p')
|
| 197 | TRAP_SPEC.ShortFlag('-l')
|
| 198 |
|
| 199 | JOB_SPEC = FlagSpec('jobs')
|
| 200 | JOB_SPEC.ShortFlag('-l', help='long format')
|
| 201 | JOB_SPEC.ShortFlag('-p', help='prints PID only')
|
| 202 | JOB_SPEC.LongFlag('--debug', help='display debug info')
|
| 203 |
|
| 204 | ULIMIT_SPEC = FlagSpec('ulimit')
|
| 205 |
|
| 206 | ULIMIT_SPEC.ShortFlag('-a', help='Print all limits')
|
| 207 | ULIMIT_SPEC.LongFlag('--all', help='Alias for -a')
|
| 208 | ULIMIT_SPEC.ShortFlag('-H', help='Use hard limit')
|
| 209 | ULIMIT_SPEC.ShortFlag('-S', help='Use soft limit')
|
| 210 |
|
| 211 | _ULIMIT_RESOURCES = [
|
| 212 | '-c',
|
| 213 | '-d',
|
| 214 | '-f',
|
| 215 | '-n',
|
| 216 | '-s',
|
| 217 | '-t',
|
| 218 | '-v',
|
| 219 | ]
|
| 220 |
|
| 221 | for u_flag in _ULIMIT_RESOURCES:
|
| 222 | ULIMIT_SPEC.ShortFlag(u_flag)
|
| 223 |
|
| 224 | #
|
| 225 | # FlagSpecAndMore
|
| 226 | #
|
| 227 |
|
| 228 | #
|
| 229 | # set and shopt
|
| 230 | #
|
| 231 |
|
| 232 |
|
| 233 | def _AddShellOptions(spec):
|
| 234 | # type: (_FlagSpecAndMore) -> None
|
| 235 | """Shared between 'set' builtin and the shell's own arg parser."""
|
| 236 | spec.InitOptions()
|
| 237 | spec.InitShopt()
|
| 238 |
|
| 239 | for opt in option_def.All():
|
| 240 | if opt.builtin == 'set':
|
| 241 | spec.Option(opt.short_flag, opt.name)
|
| 242 | # Notes:
|
| 243 | # - shopt option don't need to be registered; we validate elsewhere
|
| 244 | # - 'interactive' Has a cell for internal use, but isn't allowed to be
|
| 245 | # modified.
|
| 246 |
|
| 247 |
|
| 248 | MAIN_SPEC = FlagSpecAndMore('main')
|
| 249 |
|
| 250 | # Special case: Define --eval and --eval-pure
|
| 251 | MAIN_SPEC.EvalFlags()
|
| 252 |
|
| 253 | MAIN_SPEC.ShortFlag('-c', args.String,
|
| 254 | quit_parsing_flags=True) # command string
|
| 255 | MAIN_SPEC.LongFlag('--help')
|
| 256 | MAIN_SPEC.LongFlag('--version')
|
| 257 |
|
| 258 | # --tool ysh-ify, etc.
|
| 259 | # default is ''
|
| 260 | #
|
| 261 | # More ideas for tools
|
| 262 | # undefined-vars - a static analysis pass
|
| 263 | # parse-glob - to debug parsing
|
| 264 | # parse-printf
|
| 265 | MAIN_SPEC.LongFlag('--tool', [
|
| 266 | 'tokens',
|
| 267 | 'lossless-cat',
|
| 268 | 'syntax-tree',
|
| 269 | 'fmt',
|
| 270 | 'test',
|
| 271 | 'ysh-ify',
|
| 272 | 'deps',
|
| 273 | 'cat-em',
|
| 274 | 'find-lhs-array',
|
| 275 | ])
|
| 276 |
|
| 277 | MAIN_SPEC.ShortFlag('-i') # interactive
|
| 278 | MAIN_SPEC.ShortFlag('-l') # login - currently no-op
|
| 279 | MAIN_SPEC.LongFlag('--login') # login - currently no-op
|
| 280 | MAIN_SPEC.LongFlag('--headless') # accepts ECMD, etc.
|
| 281 |
|
| 282 | # TODO: -h too
|
| 283 | # the output format when passing -n
|
| 284 | MAIN_SPEC.LongFlag('--ast-format',
|
| 285 | ['text', 'abbrev-text', 'none', '__perf', '__dumpdoc'],
|
| 286 | default='abbrev-text')
|
| 287 |
|
| 288 | # Defines completion style.
|
| 289 | MAIN_SPEC.LongFlag('--completion-display', ['minimal', 'nice'],
|
| 290 | default='minimal')
|
| 291 | # TODO: Add option for YSH prompt style? RHS prompt?
|
| 292 |
|
| 293 | MAIN_SPEC.LongFlag('--completion-demo')
|
| 294 |
|
| 295 | # Debugging feature only. $SH -n won't reparse a[x+1] and ``. Note that $SH
|
| 296 | # --tool automatically turns it on.
|
| 297 | MAIN_SPEC.LongFlag('--do-lossless')
|
| 298 |
|
| 299 | MAIN_SPEC.LongFlag('--print-status') # TODO: Replace with a shell hook
|
| 300 | MAIN_SPEC.LongFlag('--debug-file', args.String)
|
| 301 | MAIN_SPEC.LongFlag('--xtrace-to-debug-file')
|
| 302 |
|
| 303 | # This flag has is named like bash's equivalent. We got rid of --norc because
|
| 304 | # it can simply by --rcfile /dev/null.
|
| 305 | MAIN_SPEC.LongFlag('--rcfile', args.String)
|
| 306 | MAIN_SPEC.LongFlag('--rcdir', args.String)
|
| 307 | MAIN_SPEC.LongFlag('--norc')
|
| 308 |
|
| 309 | # e.g. to pass data on stdin but pretend that it came from a .hay file
|
| 310 | MAIN_SPEC.LongFlag('--location-str', args.String)
|
| 311 | MAIN_SPEC.LongFlag('--location-start-line', args.Int)
|
| 312 |
|
| 313 | _AddShellOptions(MAIN_SPEC)
|
| 314 |
|
| 315 | SET_SPEC = FlagSpecAndMore('set')
|
| 316 | _AddShellOptions(SET_SPEC)
|
| 317 |
|
| 318 | #
|
| 319 | # Types for completion
|
| 320 | #
|
| 321 |
|
| 322 |
|
| 323 | def _DefineCompletionFlags(spec):
|
| 324 | # type: (_FlagSpecAndMore) -> None
|
| 325 | spec.ShortFlag('-F', args.String, help='Complete with this function')
|
| 326 | spec.ShortFlag('-W', args.String, help='Complete with these words')
|
| 327 | spec.ShortFlag('-C',
|
| 328 | args.String,
|
| 329 | help='Complete with stdout lines of this command')
|
| 330 |
|
| 331 | spec.ShortFlag(
|
| 332 | '-P',
|
| 333 | args.String,
|
| 334 | help=
|
| 335 | 'Prefix is added at the beginning of each possible completion after '
|
| 336 | 'all other options have been applied.')
|
| 337 | spec.ShortFlag('-S',
|
| 338 | args.String,
|
| 339 | help='Suffix is appended to each possible completion after '
|
| 340 | 'all other options have been applied.')
|
| 341 | spec.ShortFlag('-X',
|
| 342 | args.String,
|
| 343 | help='''
|
| 344 | A glob pattern to further filter the matches. It is applied to the list of
|
| 345 | possible completions generated by the preceding options and arguments, and each
|
| 346 | completion matching filterpat is removed from the list. A leading ! in
|
| 347 | filterpat negates the pattern; in this case, any completion not matching
|
| 348 | filterpat is removed.
|
| 349 | ''')
|
| 350 |
|
| 351 |
|
| 352 | def _DefineCompletionOptions(spec):
|
| 353 | # type: (_FlagSpecAndMore) -> None
|
| 354 | """Common -o options for complete and compgen."""
|
| 355 | spec.InitOptions()
|
| 356 |
|
| 357 | # bashdefault, default, filenames, nospace are used in git
|
| 358 | spec.Option2('bashdefault',
|
| 359 | help='If nothing matches, perform default bash completions')
|
| 360 | spec.Option2(
|
| 361 | 'default',
|
| 362 | help="If nothing matches, use readline's default filename completion")
|
| 363 | spec.Option2(
|
| 364 | 'filenames',
|
| 365 | help="The completion function generates filenames and should be "
|
| 366 | "post-processed")
|
| 367 | spec.Option2('dirnames',
|
| 368 | help="If nothing matches, perform directory name completion")
|
| 369 | spec.Option2(
|
| 370 | 'nospace',
|
| 371 | help="Don't append a space to words completed at the end of the line")
|
| 372 | spec.Option2(
|
| 373 | 'plusdirs',
|
| 374 | help="After processing the compspec, attempt directory name completion "
|
| 375 | "and return those matches.")
|
| 376 |
|
| 377 |
|
| 378 | def _DefineCompletionActions(spec):
|
| 379 | # type: (_FlagSpecAndMore) -> None
|
| 380 | """Common -A actions for complete and compgen."""
|
| 381 |
|
| 382 | # NOTE: git-completion.bash uses -f and -v.
|
| 383 | # My ~/.bashrc on Ubuntu uses -d, -u, -j, -v, -a, -c, -b
|
| 384 | spec.InitActions()
|
| 385 | spec.Action('a', 'alias')
|
| 386 | spec.Action('b', 'binding')
|
| 387 | spec.Action('c', 'command')
|
| 388 | spec.Action('d', 'directory')
|
| 389 | spec.Action('e', 'export')
|
| 390 | spec.Action('f', 'file')
|
| 391 | spec.Action('k', 'keyword')
|
| 392 | spec.Action('j', 'job')
|
| 393 | spec.Action('u', 'user')
|
| 394 | spec.Action('v', 'variable')
|
| 395 | spec.Action(None, 'builtin')
|
| 396 | spec.Action(None, 'function')
|
| 397 | spec.Action(None, 'helptopic') # help
|
| 398 | spec.Action(None, 'setopt') # set -o
|
| 399 | spec.Action(None, 'shopt') # shopt -s
|
| 400 | spec.Action(None, 'signal') # kill -s
|
| 401 | spec.Action(None, 'stopped')
|
| 402 |
|
| 403 |
|
| 404 | COMPLETE_SPEC = FlagSpecAndMore('complete')
|
| 405 |
|
| 406 | _DefineCompletionFlags(COMPLETE_SPEC)
|
| 407 | _DefineCompletionOptions(COMPLETE_SPEC)
|
| 408 | _DefineCompletionActions(COMPLETE_SPEC)
|
| 409 |
|
| 410 | COMPLETE_SPEC.ShortFlag('-E', help='Define the compspec for an empty line')
|
| 411 | COMPLETE_SPEC.ShortFlag(
|
| 412 | '-D', help='Define the compspec that applies when nothing else matches')
|
| 413 |
|
| 414 | # I would like this to be less compatible
|
| 415 | # Field name conflicts with 'print' keyword
|
| 416 | #COMPLETE_SPEC.LongFlag(
|
| 417 | # '--print', help='Print spec')
|
| 418 |
|
| 419 | COMPGEN_SPEC = FlagSpecAndMore('compgen') # for -o and -A
|
| 420 |
|
| 421 | # TODO: Add -l for COMP_LINE. -p for COMP_POINT ?
|
| 422 | _DefineCompletionFlags(COMPGEN_SPEC)
|
| 423 | _DefineCompletionOptions(COMPGEN_SPEC)
|
| 424 | _DefineCompletionActions(COMPGEN_SPEC)
|
| 425 |
|
| 426 | COMPOPT_SPEC = FlagSpecAndMore('compopt') # for -o
|
| 427 | _DefineCompletionOptions(COMPOPT_SPEC)
|
| 428 |
|
| 429 | COMPADJUST_SPEC = FlagSpecAndMore('compadjust')
|
| 430 |
|
| 431 | COMPADJUST_SPEC.ShortFlag(
|
| 432 | '-n',
|
| 433 | args.String,
|
| 434 | help=
|
| 435 | 'Do NOT split by these characters. It omits them from COMP_WORDBREAKS.')
|
| 436 | COMPADJUST_SPEC.ShortFlag('-s',
|
| 437 | help='Treat --foo=bar and --foo bar the same way.')
|
| 438 |
|
| 439 | COMPEXPORT_SPEC = FlagSpecAndMore('compexport')
|
| 440 |
|
| 441 | COMPEXPORT_SPEC.ShortFlag('-c',
|
| 442 | args.String,
|
| 443 | help='Shell string to complete, like sh -c')
|
| 444 |
|
| 445 | COMPEXPORT_SPEC.LongFlag('--begin',
|
| 446 | args.Int,
|
| 447 | help='Simulate readline begin index into line buffer')
|
| 448 |
|
| 449 | COMPEXPORT_SPEC.LongFlag('--end',
|
| 450 | args.Int,
|
| 451 | help='Simulate readline end index into line buffer')
|
| 452 |
|
| 453 | # jlines is an array of strings with NO header line
|
| 454 | # TSV8 has a header line. It can have flag descriptions and other data.
|
| 455 | COMPEXPORT_SPEC.LongFlag('--format', ['jlines', 'tsv8'],
|
| 456 | default='jlines',
|
| 457 | help='Output format')
|
| 458 |
|
| 459 | #
|
| 460 | # Pure YSH
|
| 461 | #
|
| 462 |
|
| 463 | TRY_SPEC = FlagSpec('try_')
|
| 464 | TRY_SPEC.LongFlag('--assign',
|
| 465 | args.String,
|
| 466 | help='Assign status to this variable, and return 0')
|
| 467 |
|
| 468 | ERROR_SPEC = FlagSpec('error')
|
| 469 | FAILED_SPEC = FlagSpec('failed')
|
| 470 |
|
| 471 | BOOLSTATUS_SPEC = FlagSpec('boolstatus')
|
| 472 | ASSERT_SPEC = FlagSpec('assert')
|
| 473 |
|
| 474 | # Future directions:
|
| 475 | # run --builtin, run --command, run --proc:
|
| 476 | # to "replace" 'builtin' and # 'command'
|
| 477 |
|
| 478 | APPEND_SPEC = FlagSpec('append')
|
| 479 |
|
| 480 | SHVAR_SPEC = FlagSpec('shvar')
|
| 481 | #SHVAR_SPEC.Flag('-temp', args.String,
|
| 482 | # help='Push a NAME=val binding')
|
| 483 | #SHVAR_SPEC.Flag('-env', args.String,
|
| 484 | # help='Push a NAME=val binding and set the -x flag')
|
| 485 |
|
| 486 | CTX_SPEC = FlagSpec('ctx')
|
| 487 |
|
| 488 | PP_SPEC = FlagSpec('pp')
|
| 489 |
|
| 490 | # --verbose?
|
| 491 | FORK_SPEC = FlagSpec('fork')
|
| 492 | FORKWAIT_SPEC = FlagSpec('forkwait')
|
| 493 |
|
| 494 | # Might want --list at some point
|
| 495 | SOURCE_GUARD_SPEC = FlagSpec('source-guard')
|
| 496 | USE_SPEC = FlagSpec('use')
|
| 497 | USE_SPEC.LongFlag('--extern')
|
| 498 |
|
| 499 | RUNPROC_SPEC = FlagSpec('runproc')
|
| 500 | RUNPROC_SPEC.ShortFlag('-h', args.Bool, help='Show all procs')
|
| 501 |
|
| 502 | INVOKE_SPEC = FlagSpec('invoke')
|
| 503 | INVOKE_SPEC.LongFlag('--builtin') # like 'builtin'
|
| 504 | INVOKE_SPEC.LongFlag('--proc')
|
| 505 | INVOKE_SPEC.LongFlag('--sh-func')
|
| 506 | INVOKE_SPEC.LongFlag('--extern') # new functionality
|
| 507 | INVOKE_SPEC.LongFlag('--show') # like type -a with private builtins
|
| 508 |
|
| 509 | EXTERN_SPEC = FlagSpec('extern')
|
| 510 |
|
| 511 | SLEEP_SPEC = FlagSpec('sleep')
|
| 512 |
|
| 513 | CAT_SPEC = FlagSpec('cat')
|
| 514 |
|
| 515 | RM_SPEC = FlagSpec('rm')
|
| 516 | RM_SPEC.ShortFlag('-f', args.Bool, help="Don't fail when a file doesn't exist")
|
| 517 |
|
| 518 | WRITE_SPEC = FlagSpec('write')
|
| 519 | WRITE_SPEC.LongFlag('--sep',
|
| 520 | args.String,
|
| 521 | default='\n',
|
| 522 | help='Characters to separate each argument')
|
| 523 | WRITE_SPEC.LongFlag('--end',
|
| 524 | args.String,
|
| 525 | default='\n',
|
| 526 | help='Characters to terminate the whole invocation')
|
| 527 | WRITE_SPEC.ShortFlag('-n',
|
| 528 | args.Bool,
|
| 529 | help="Omit newline (synonym for -end '')")
|
| 530 |
|
| 531 | # Note: these 2 aren't documented, but they are implemented
|
| 532 | WRITE_SPEC.LongFlag('--json',
|
| 533 | args.Bool,
|
| 534 | default=False,
|
| 535 | help='Write elements as JSON strings(lossy)')
|
| 536 | WRITE_SPEC.LongFlag('--j8',
|
| 537 | args.Bool,
|
| 538 | default=False,
|
| 539 | help='Write elements as J8 strings')
|
| 540 | # TODO: --jlines for conditional j"" prefix? Like maybe_shell_encode()
|
| 541 |
|
| 542 | # Legacy that's not really needed with J8 notation. The = operator might use a
|
| 543 | # separate pretty printer that shows \u{3bc}
|
| 544 | #
|
| 545 | # x means I want \x00
|
| 546 | # u means I want \u{1234}
|
| 547 | # raw is utf-8
|
| 548 | if 0:
|
| 549 | WRITE_SPEC.LongFlag(
|
| 550 | '--unicode', ['raw', 'u', 'x'],
|
| 551 | default='raw',
|
| 552 | help='Encode QSN with these options. '
|
| 553 | 'x assumes an opaque byte string, while raw and u try to '
|
| 554 | 'decode UTF-8.')
|
| 555 |
|
| 556 | PUSH_REGISTERS_SPEC = FlagSpec('push-registers')
|
| 557 |
|
| 558 | FOPEN_SPEC = FlagSpec('redir')
|
| 559 |
|
| 560 | #
|
| 561 | # JSON
|
| 562 | #
|
| 563 |
|
| 564 | JSON_WRITE_SPEC = FlagSpec('json_write')
|
| 565 |
|
| 566 | if 0:
|
| 567 | JSON_WRITE_SPEC.LongFlag('--pretty',
|
| 568 | args.Bool,
|
| 569 | default=True,
|
| 570 | help='Whitespace in output (default true)')
|
| 571 |
|
| 572 | # Unused:
|
| 573 | # JSON has the questionable decision of allowing (unpaired) surrogate like
|
| 574 | # \udc00.
|
| 575 | # When encoding, we try to catch the error on OUR side, rather than letting it
|
| 576 | # travel over the wire. But you can disable this.
|
| 577 | JSON_WRITE_SPEC.LongFlag(
|
| 578 | '--surrogate-ok',
|
| 579 | args.Bool,
|
| 580 | default=False,
|
| 581 | help='Invalid UTF-8 can be encoded as surrogate like \\udc00')
|
| 582 |
|
| 583 | JSON_WRITE_SPEC.LongFlag('--indent',
|
| 584 | args.Int,
|
| 585 | default=2,
|
| 586 | help='Indent JSON by this amount')
|
| 587 |
|
| 588 | JSON_READ_SPEC = FlagSpec('json_read')
|