cmdr
Check-in [56a4c28f89]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Extended the integrated help system to declare a global option --help (-h, -?), inherited by all commands to provide their help. Updated the testsuite.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:56a4c28f89836c5b74d6895a269c908ae46a6c51
User & Date: aku 2016-06-22 18:41:01
Context
2016-06-22
19:01
Restructured the file hierarchy, sorted the package files into related groups. check-in: b09c92cbff user: aku tags: trunk
18:41
Extended the integrated help system to declare a global option --help (-h, -?), inherited by all commands to provide their help. Updated the testsuite. check-in: 56a4c28f89 user: aku tags: trunk
05:50
Updated copyright year, and regenerated the docs. check-in: d0ef9140a0 user: aku tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to config.tcl.

531
532
533
534
535
536
537

538
539
540
541
542
543
544

545
546
547
548
549
550

551
552
553
554
555
556
557
....
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
....
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
    method Interactive {} {
	debug.cmdr/config {}
	set myinteractive 1
	return
    }

    method Section {args} {

	# Remember the help section this private is a part of.
	lappend mysections $args
	return
    }

    # Externally visible variant of the 'Option' specification command.
    method make-option {args} {

	# Splat is a dummy for this.
	set splat no
	my DefineParameter 0 1 0 0 {*}$args
    }
    # Externally visible variant of the 'State' specification command.
    method make-state {args} {

	# Splat is a dummy for this.
	set splat no
	my DefineParameter 0 0 1 1 {*}$args
    }

    # Parameter definition itself.
    # order, cmdline, required, defered (O C R D) name ?spec?
................................................................................
	#puts [A size]|$argname|[P size]
	[dict get $mymap $argname] process $argname $mypq
	#puts \t==>[P size]
	return
    }

    method ProcessOption {} {
	debug.cmdr/config {}
	# Get option. Do special handling.
	# Non special option gets dispatched to handler (cmdr::parameter instance).
	# The handler is responsible for retrieved the option's value.
	set option [P get]
	debug.cmdr/config {taking ($option)}

	# Handle general special forms:
................................................................................
	# --foo=bar ==> --foo bar
	# -f=bar    ==> -f bar

	if {[regexp {^(-[^=]+)=(.*)$} $option --> option value]} {
	    P unget $value
	}

	debug.cmdr/config {having ($option)}

	# Validate existence of the option
	if {![dict exists $myfullopt $option]} {
	    my raise "Unknown option $option" \
		CMDR CONFIG BAD OPTION
	}








>







>






>







 







|







 







|







531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
....
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
....
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
    method Interactive {} {
	debug.cmdr/config {}
	set myinteractive 1
	return
    }

    method Section {args} {
	debug.cmdr/config {}
	# Remember the help section this private is a part of.
	lappend mysections $args
	return
    }

    # Externally visible variant of the 'Option' specification command.
    method make-option {args} {
	debug.cmdr/config {![context fullname]}
	# Splat is a dummy for this.
	set splat no
	my DefineParameter 0 1 0 0 {*}$args
    }
    # Externally visible variant of the 'State' specification command.
    method make-state {args} {
	debug.cmdr/config {![context fullname]}
	# Splat is a dummy for this.
	set splat no
	my DefineParameter 0 0 1 1 {*}$args
    }

    # Parameter definition itself.
    # order, cmdline, required, defered (O C R D) name ?spec?
................................................................................
	#puts [A size]|$argname|[P size]
	[dict get $mymap $argname] process $argname $mypq
	#puts \t==>[P size]
	return
    }

    method ProcessOption {} {
	debug.cmdr/config {![context fullname]}
	# Get option. Do special handling.
	# Non special option gets dispatched to handler (cmdr::parameter instance).
	# The handler is responsible for retrieved the option's value.
	set option [P get]
	debug.cmdr/config {taking ($option)}

	# Handle general special forms:
................................................................................
	# --foo=bar ==> --foo bar
	# -f=bar    ==> -f bar

	if {[regexp {^(-[^=]+)=(.*)$} $option --> option value]} {
	    P unget $value
	}

	debug.cmdr/config {having ($option) in ([dict keys $myfullopt])}

	# Validate existence of the option
	if {![dict exists $myfullopt $option]} {
	    my raise "Unknown option $option" \
		CMDR CONFIG BAD OPTION
	}

Changes to help.tcl.

43
44
45
46
47
48
49
50
51
52
53
54
55
56



57
58
59
60
61
62
63
64
65
66
67
68
69
..
70
71
72
73
74
75
76


77


































78
79
80
81
82
83
84
85
86
87
...
132
133
134
135
136
137
138




139
140
141
142
143
144
145

namespace eval ::cmdr {
    namespace export help
    namespace ensemble create
}

namespace eval ::cmdr::help {
    namespace export query format auto
    namespace ensemble create

    namespace import ::cmdr::tty
}

# # ## ### ##### ######## ############# #####################




proc ::cmdr::help::query {actor words} {
    debug.cmdr/help {}
    # Resolve chain of words (command name path) to the actor
    # responsible for that command, starting from the specified actor.
    # This is very much a convenience command.

    set root   [$actor root]
    set prefix $words

    if {![$root exists *in-shell*] ||
	![$root get    *in-shell*]} {
	# Not in the shell, put executable's name into the prefix.
................................................................................
	set prefix [linsert $prefix 0 [$root name]]
    }

    return [[$actor find $words] help $prefix]
}

# # ## ### ##### ######## ############# #####################





































proc ::cmdr::help::auto {actor} {
    debug.cmdr/help {}
    # Generate a standard help command for any actor, and add it dynamically.

    # Auto create options based on the help formats found installed
    foreach c [lsort -dict [info commands {::cmdr::help::format::[a-z]*}]] {
	set format [namespace tail $c]

	# Skip the imported helper commands which are NOT formats
	if {[string match query* $format]} continue
................................................................................
	    The entire command line, the name of the
	    command to get help for. This can be several
	    words.
	} { optional ; list }
    }] [list ::cmdr::help::auto-help $actor]
    return
}





proc ::cmdr::help::auto-help {actor config} {
    debug.cmdr/help {}

    set width  [$config @width]
    set nopage [$config @no-pager]
    set words  [$config @cmdname]







|






>
>
>



<
<
<







 







>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


<







 







>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62



63
64
65
66
67
68
69
..
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

116
117
118
119
120
121
122
...
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

namespace eval ::cmdr {
    namespace export help
    namespace ensemble create
}

namespace eval ::cmdr::help {
    namespace export query format auto auto-option
    namespace ensemble create

    namespace import ::cmdr::tty
}

# # ## ### ##### ######## ############# #####################
## A helper to resolve a chain of words (i.e. command name path) to
## the actor responsible for that command, starting from the specified
## actor.

proc ::cmdr::help::query {actor words} {
    debug.cmdr/help {}




    set root   [$actor root]
    set prefix $words

    if {![$root exists *in-shell*] ||
	![$root get    *in-shell*]} {
	# Not in the shell, put executable's name into the prefix.
................................................................................
	set prefix [linsert $prefix 0 [$root name]]
    }

    return [[$actor find $words] help $prefix]
}

# # ## ### ##### ######## ############# #####################
## The internal support command dynamically generating and inserting
## the user's --help option. This is restricted to the root actor.

proc ::cmdr::help::auto-option {actor} {
    $actor learn {
	option help {
	    Show the help of the application or of the current
	    command, and stop.
	} {
	    alias h
	    alias ?
	    presence
	    when-set [lambda {p x} {
		# Invoke the help command which will be generated and
		# inserted below.
		set root [$p config context root]
		if {[$root exists *prefix*]} {
		    # Invoke help for the current command.
		    $root do help {*}[$root get *prefix*]
		} else {
		    # Invoke global help.
		    $root do help
		}
		# Prevent any other processing.
		return -code error -errorcode {CMDR QUIT} Quit
	    }]
	}
    }
    return
}

# # ## ### ##### ######## ############# #####################
## The internal support command dynamically generating and inserting
## the user's help command into the specified actor. See officer.tcl,
## method 'Setup' for the place where this gets used. If the actor is
## the root of the hierarchy a global option --help is added as well.

proc ::cmdr::help::auto {actor} {
    debug.cmdr/help {}


    # Auto create options based on the help formats found installed
    foreach c [lsort -dict [info commands {::cmdr::help::format::[a-z]*}]] {
	set format [namespace tail $c]

	# Skip the imported helper commands which are NOT formats
	if {[string match query* $format]} continue
................................................................................
	    The entire command line, the name of the
	    command to get help for. This can be several
	    words.
	} { optional ; list }
    }] [list ::cmdr::help::auto-help $actor]
    return
}

# # ## ### ##### ######## ############# #####################
## Implementation/back-end of the generated help.
## The bridge between cmd hierarchy and actual generation.

proc ::cmdr::help::auto-help {actor config} {
    debug.cmdr/help {}

    set width  [$config @width]
    set nopage [$config @no-pager]
    set words  [$config @cmdname]

Changes to officer.tcl.

45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
..
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
..
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213

214












215


216
217
218
219

220
221
222
223
224
225

226
227
228
229
230
231
232
233
234
235
236
237

238
239
240


241
242
243
244
245
246
247
248
249
250
251
252
...
260
261
262
263
264
265
266


267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
...
298
299
300
301
302
303
304

305
306
307
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
...
337
338
339
340
341
342
343

344
345
346
347
348
349
350
...
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
...
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
...
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
...
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
...
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
...
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
package require cmdr::help
package require cmdr::config

# # ## ### ##### ######## ############# #####################

debug define cmdr/officer
debug level  cmdr/officer
debug prefix cmdr/officer {[debug caller] | }


# # ## ### ##### ######## ############# #####################
## Definition - Single purpose command.

# # ## ### ##### ######## ############# #####################
## Definition

................................................................................
    # Specification commands.
    #
    # private $name $arguments $cmdprefix --> sub-ordinate private for the action.
    # officer $name $actions              --> sub-ordinate officer with more actions.
    # default $name                       --> default action

    constructor {super name actions} {
	debug.cmdr/officer {}
	next

	my super: $super
	my name:  $name

	set myactions   $actions ; # Action spec for future initialization
	set myinit      no       ; # Dispatch map will be initialized lazily
................................................................................
	set myconfig    {}
	return
    }

    # # ## ### ##### ######## #############

    method ehandler {cmd} {
	debug.cmdr/officer {}
	set myhandler $cmd
	return
    }

    method shandler {cmd} {
	debug.cmdr/officer {}
	set myshandler $cmd
	return
    }

    # # ## ### ##### ######## #############
    ## Public API. (Introspection, mostly).
    ## - Determine set of known actions.
    ## - Determine default action.
    ## - Determine handler for an action.

    method known {} {
	debug.cmdr/officer {}
	my Setup
	set result {}
	dict for {k v} $mymap {
	    if {![string match a,* $k]} continue
	    lappend result [string range $k 2 end]
	}
	return $result
    }

    method hasdefault {} {
	debug.cmdr/officer {} 10
	my Setup
	return [dict exists $mymap default]
    }

    method default {} {
	debug.cmdr/officer {} 10
	my Setup
	return [dict get $mymap default]
    }

    method lookup {name} {
	debug.cmdr/officer {}
	my Setup
	# An exact action name has priority over any prefixes.
	if {[dict exists $mymap a,$name]} {
	    return [dict get $mymap a,$name]
	}
	# Accept any unique prefix.
	if {
................................................................................

	[my lookup $word] internal_find \
	    [lrange $words 1 end] \
	    [linsert $prefix end $word]
    }

    method has {name} {
	debug.cmdr/officer {}
	my Setup
	return [dict exists $mymap a,$name]
    }

    method children {} {
	debug.cmdr/officer {}
	my Setup
	return $mychildren
    }

    # Make the parameter container accessible.
    method config {} {
	debug.cmdr/officer {}
	return $myconfig
    }

    # # ## ### ##### ######## #############
    ## Internal. Dispatcher setup. Defered until required.
    ## Core setup code runs only once.

    method Setup {} {

	# Process the action specification only once.
	if {$myinit} return
	set myinit 1
	debug.cmdr/officer {}

	set super [my super]
	if {$super ne {}} {
	    set super [$super config]
	}


	set myconfig [cmdr::config create config [self] {} $super]












	my learn $myactions


	$myconfig complete-definitions

	# Auto-create a 'help' command when possible, i.e not in
	# conflict with a user-specified command.

	if {![my has help]} {
	    cmdr help auto [self]
	}

	# Auto-create an 'exit' command when possible, i.e not in
	# conflict with a user-specified command.

	if {![my has exit]} {
	    my extend exit {
		section *AutoGenerated*
		description {
		    Exit the shell.
		    No-op if not in a shell.
		}
	    } [mymethod shell-exit]
	}

	# Invoke the user-specified hook for extending a newly-made
	# officer, if any.

	if {[llength $myshandler]} {
	    {*}$myshandler [self]
	}


	return
    }

    method learn {script} {
	debug.cmdr/officer {}
	# Make the DSL commands directly available. Note that
	# "description:" and "common" are superclass methods, and
	# renamed to their DSL counterparts. The others are unexported
	# instance methods of this class.

	link \
	    {ehandler    ehandler} \
................................................................................
	    {common      set} \
	    {option      Option} \
	    {state       State}
	eval $script

	# Postprocessing.
	set mycommands [lsort -dict $mycommands]


	return
    }

    # Convenience method for dynamically creating a command hierarchy.
    # Command specified as path, intermediate officers are generated
    # automatically as needed.

    method extend {path arguments action} {
	debug.cmdr/officer {}
	if {[llength $path] == 1} {
	    # Reached the bottom of the recursion.
	    # Generate the private handling arguments and action.
	    set cmd [lindex $path 0]
	    return [my Private $cmd $arguments $action]
	}

................................................................................
    # common      => set          (super cmdr::actor)
    # description => description: (super cmdr::actor)

    forward Private my DefineAction private
    forward Officer my DefineAction officer

    method Default {{name {}}} {

	if {[llength [info level 0]] == 2} {
	    set name [my Last]
	} elseif {![dict exists $mymap a,$name]} {
	    return -code error \
		-errorcode [list CMDR ACTION UNKNOWN $name] \
		"Unable to set default, expected action, got \"$name\""
	}
	dict set mymap default $name
	return
    }

    method Alias {name args} {

	set n [llength $args]
	if {($n == 1) || (($n > 1) && ([lindex $args 0] ne "="))} {
	    return -code error \
		"wrong\#args: should be \"name ?= cmd ?word...??\""
	}
	my ValidateAsUnknown $name

................................................................................
	# refers to.
	my Def $name $handler
	return
    }

    # Internal. Common code to declare actions and their handlers.
    method DefineAction {what name args} {

	my ValidateAsUnknown $name

	# Note: By placing the subordinate objects into the officer's
	# namespace they will be automatically destroyed with the
	# officer itself. No special code for cleanup required.

	set handler [self namespace]::${what}_$name
................................................................................
	    append prefix $c
	    dict lappend mypmap $prefix $handler
	}
	return
    }

    method ValidateAsUnknown {name} {
	debug.cmdr/officer {}
	if {![dict exists $mymap a,$name]} return
	return -code error -errorcode {CMDR ACTION KNOWN} \
	    "Unable to learn $name, already specified."
    }

    method Last {} {
	if {![dict exists $mymap last]} {
................................................................................
	    return -code error -errorcode {CMDR ACTION NO-LAST} \
		"Cannot be used as first command"
	}
	return [dict get $mymap last]
    }

    method Known {name} {
	debug.cmdr/officer {}
	# Known exact action is good
	if {[dict exists $mymap a,$name]} { return 1 }
	debug.cmdr/officer {no action, maybe prefix}
	# Unknown prefix is bad
	if {![dict exists $mypmap $name]} { return 0 }
	debug.cmdr/officer {prefix, maybe ambiguous}
	# As is an ambiguous prefix
................................................................................
	return 1
    }

    # # ## ### ##### ######## #############
    ## Command dispatcher. Choose the subordinate and delegate.

    method do {args} {
	debug.cmdr/officer {}
	my Setup

	# Process any options we may find. The first non-option
	# will be the command to dispatch on.
	set args [config parse-head-options {*}$args]

	# No command specified, what should we do ?
................................................................................
	# we have no default to punt to and interaction is globally
	# allowed.

	if {![llength $args] && ![my hasdefault] && [cmdr interactive?]} {
	    # Drop into a shell where the user can enter her commands
	    # interactively.

	    debug.cmdr/officer {shell}

	    set shell [linenoise::facade new [self]]
	    set myreplexit 0 ; # Initialize stop signal, no stopping
	    $shell history 1
	    $shell history= [my history-setup]
	    [my root] set *in-shell* true
	    $shell repl
	    [my root] set *in-shell* false
	    $shell destroy

	    debug.cmdr/officer {/done shell}
	    return
	}

	my Do {*}$args

	debug.cmdr/officer {/done}
	return
    }

    # Internal. Actual dispatch. Shared by main entry and shell.
    method Do {args} {
	debug.cmdr/officer {}
	set reset 0
	if {![my exists *command*]} {
	    # Prevent handling of application-specific options here.
	    my set *command* -- $args
	    set reset 1
	}
	try {
................................................................................
	    }

	    # Split into command and arguments
	    set remainder [lassign $args cmd]

	    # Delegate to the handler for a known command.
	    if {[my Known $cmd]} {
		debug.cmdr/officer {/known $cmd}

		my lappend *prefix* $cmd
		[my lookup $cmd] do {*}$remainder

		debug.cmdr/officer {/done known}
		return
	    }

	    # The command word is not known. Delegate the full command to
	    # the default, if we have any. Otherwise fail.

	    if {[my hasdefault]} {
		# prefix left as is.
		debug.cmdr/officer {/default}

		[my lookup [my default]] do {*}$args
		debug.cmdr/officer {/done default}
		return
	    }

	    # See also private::FullCmd
	    if {[catch {
		set prefix " [my get *prefix*] "
	    }]} { set prefix "" }
................................................................................
	} finally {
	    if {$reset} {
		my unset *command*
	    }
	    my unset *prefix*
	}

	debug.cmdr/officer {/done}
    }

    # # ## ### ##### ######## #############
    ## Shell hook methods called by the linenoise::facade.

    method prompt1   {}     { return "[my fullname] > " }
    method prompt2   {}     { error {Continuation lines are not supported} }
................................................................................
    method shell-exit {config} {
	# No arguments, ignore config.
	set myreplexit 1
	return
    }

    method dispatch {cmd} {
	debug.cmdr/officer {}

	if {$cmd eq {}} {
	    # No command, do nothing.
	    return
	}

	if {$cmd eq ".exit"} {
................................................................................
	    # i.e not in conflict with a user-specified command.
	    set myreplexit 1 ; return
	}
	my Do {*}[string token shell -- $cmd]
    }

    method report {what data} {
	debug.cmdr/officer {}
	switch -exact -- $what {
	    ok {
		if {$data eq {}} return
		puts stdout $data
	    }
	    fail {
		puts stderr $data
................................................................................
	}
    }

    # # ## ### ##### ######## #############
    # Shell hook method - Command line completion.

    method complete {line} {
	debug.cmdr/officer {} 10
	#puts stderr ////////$line
	try {
	    set completions [my complete-words [my parse-line $line]]
	} on error {e o} {
	    puts stderr "ERROR: $e"
	    puts stderr $::errorInfo
	    set completions {}
	}
	#puts stderr =($completions)
	return $completions
    }

    method complete-words {parse} {
	debug.cmdr/officer {} 10
	#puts stderr [my fullname]/[self]/$parse/
	# Note: This method has to entry-points.
	# (1) Above in 'complete', for command completion from self's REPL.
	# (2) Below, as part of recursion from a higher officer while
	#     following the chain of words to the actor responsible
	#     for handling the last word.

................................................................................
	}

	#puts stderr \tC($completions)
	return [lsort -unique [lsort -dict $completions]]
    }

    method CompleteRecurse {parse} {
	debug.cmdr/officer {} 10
	# Inside the command line. Find the relevant subordinate based
	# on the current word and let it handle everything.

	# The '.exit' pseudo-command of the subordinate is irrelevant
	# during recursion from the current or higher REPL, suppress
	# it. The pseudo-command is only relevant to the officers
	# actually in their REPL.
................................................................................
	# No default, no completions.
	return {}
    }

    # # ## ### ##### ######## #############

    method CCommands {{doexit 1}} {
	debug.cmdr/officer {} 10
	if {![llength $myccommands]} {
	    # Fill completion command cache.

	    # Standard pseudo-commands.
	    if {$doexit} {
		lappend myccommands .exit
	    }
................................................................................
	return $myccommands
    }


    # # ## ### ##### ######## #############

    method help {{prefix {}}} {
	debug.cmdr/officer {}
	my Setup
	# Query each subordinate for their help and use it to piece ours together.
	# Note: Result is not finally formatted text, but nested dict structure.
	# Same is expected from the sub-ordinates

	# help = dict (name -> command)
	#if {![my documented]} { return {} }







|
>







 







|







 







|





|











|










|





|





|







 







|





|






|








>



|






>

>
>
>
>
>
>
>
>
>
>
>
>

>
>
|



>






>












>



>
>




|







 







>
>








|







 







>












>







 







>







 







|







 







|







 







|







 







|










|





|





|







 







|




|








|


|







 







|







 







|







 







|







 







|













|







 







|







 







|







 







|







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
..
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
...
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
...
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
...
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
...
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
...
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
...
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
...
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
...
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
...
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
...
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
...
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
...
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
package require cmdr::help
package require cmdr::config

# # ## ### ##### ######## ############# #####################

debug define cmdr/officer
debug level  cmdr/officer
#debug prefix cmdr/officer {[debug caller] | }
debug prefix cmdr/officer {}

# # ## ### ##### ######## ############# #####################
## Definition - Single purpose command.

# # ## ### ##### ######## ############# #####################
## Definition

................................................................................
    # Specification commands.
    #
    # private $name $arguments $cmdprefix --> sub-ordinate private for the action.
    # officer $name $actions              --> sub-ordinate officer with more actions.
    # default $name                       --> default action

    constructor {super name actions} {
	debug.cmdr/officer {[self] $super $name}
	next

	my super: $super
	my name:  $name

	set myactions   $actions ; # Action spec for future initialization
	set myinit      no       ; # Dispatch map will be initialized lazily
................................................................................
	set myconfig    {}
	return
    }

    # # ## ### ##### ######## #############

    method ehandler {cmd} {
	debug.cmdr/officer {[self] $cmd}
	set myhandler $cmd
	return
    }

    method shandler {cmd} {
	debug.cmdr/officer {[self] $cmd}
	set myshandler $cmd
	return
    }

    # # ## ### ##### ######## #############
    ## Public API. (Introspection, mostly).
    ## - Determine set of known actions.
    ## - Determine default action.
    ## - Determine handler for an action.

    method known {} {
	debug.cmdr/officer {[debug caller] | }
	my Setup
	set result {}
	dict for {k v} $mymap {
	    if {![string match a,* $k]} continue
	    lappend result [string range $k 2 end]
	}
	return $result
    }

    method hasdefault {} {
	debug.cmdr/officer {[debug caller] | } 10
	my Setup
	return [dict exists $mymap default]
    }

    method default {} {
	debug.cmdr/officer {[debug caller] | } 10
	my Setup
	return [dict get $mymap default]
    }

    method lookup {name} {
	debug.cmdr/officer {[debug caller] | }
	my Setup
	# An exact action name has priority over any prefixes.
	if {[dict exists $mymap a,$name]} {
	    return [dict get $mymap a,$name]
	}
	# Accept any unique prefix.
	if {
................................................................................

	[my lookup $word] internal_find \
	    [lrange $words 1 end] \
	    [linsert $prefix end $word]
    }

    method has {name} {
	debug.cmdr/officer {[debug caller] | }
	my Setup
	return [dict exists $mymap a,$name]
    }

    method children {} {
	debug.cmdr/officer {[debug caller] | }
	my Setup
	return $mychildren
    }

    # Make the parameter container accessible.
    method config {} {
	debug.cmdr/officer {[debug caller] | $myconfig}
	return $myconfig
    }

    # # ## ### ##### ######## #############
    ## Internal. Dispatcher setup. Defered until required.
    ## Core setup code runs only once.

    method Setup {} {
	debug.cmdr/officer {[debug caller] | $myinit}
	# Process the action specification only once.
	if {$myinit} return
	set myinit 1
	debug.cmdr/officer {[debug caller] | }

	set super [my super]
	if {$super ne {}} {
	    set super [$super config]
	}

	debug.cmdr/officer {[debug caller] | make config}
	set myconfig [cmdr::config create config [self] {} $super]

	# Option --help, -h, -?, added early. Done to ensure that it
	# is known should the specification we will learn in a moment
	# (*) unfold itself deeper during learning, and push the
	# global options down. Adding is done only at the root of the
	# hierarchy, to be inherited by everybody.
	if {[[self] super] eq {}} {
	    cmdr help auto-option [self]
	}

	# (*)
	debug.cmdr/officer {[debug caller] | learn}
	my learn $myactions

	debug.cmdr/officer {[debug caller] | complete}
	config complete-definitions

	# Auto-create a 'help' command when possible, i.e not in
	# conflict with a user-specified command.
	debug.cmdr/officer {[debug caller] | make help}
	if {![my has help]} {
	    cmdr help auto [self]
	}

	# Auto-create an 'exit' command when possible, i.e not in
	# conflict with a user-specified command.
	debug.cmdr/officer {[debug caller] | make exit}
	if {![my has exit]} {
	    my extend exit {
		section *AutoGenerated*
		description {
		    Exit the shell.
		    No-op if not in a shell.
		}
	    } [mymethod shell-exit]
	}

	# Invoke the user-specified hook for extending a newly-made
	# officer, if any.
	debug.cmdr/officer {[debug caller] | call shandler}
	if {[llength $myshandler]} {
	    {*}$myshandler [self]
	}

	debug.cmdr/officer {[debug caller] | /done}
	return
    }

    method learn {script} {
	debug.cmdr/officer {[self] learn}
	# Make the DSL commands directly available. Note that
	# "description:" and "common" are superclass methods, and
	# renamed to their DSL counterparts. The others are unexported
	# instance methods of this class.

	link \
	    {ehandler    ehandler} \
................................................................................
	    {common      set} \
	    {option      Option} \
	    {state       State}
	eval $script

	# Postprocessing.
	set mycommands [lsort -dict $mycommands]

	debug.cmdr/officer {[self] learn /done}
	return
    }

    # Convenience method for dynamically creating a command hierarchy.
    # Command specified as path, intermediate officers are generated
    # automatically as needed.

    method extend {path arguments action} {
	debug.cmdr/officer {[debug caller] | }
	if {[llength $path] == 1} {
	    # Reached the bottom of the recursion.
	    # Generate the private handling arguments and action.
	    set cmd [lindex $path 0]
	    return [my Private $cmd $arguments $action]
	}

................................................................................
    # common      => set          (super cmdr::actor)
    # description => description: (super cmdr::actor)

    forward Private my DefineAction private
    forward Officer my DefineAction officer

    method Default {{name {}}} {
	debug.cmdr/officer {[self] Default ($name)}
	if {[llength [info level 0]] == 2} {
	    set name [my Last]
	} elseif {![dict exists $mymap a,$name]} {
	    return -code error \
		-errorcode [list CMDR ACTION UNKNOWN $name] \
		"Unable to set default, expected action, got \"$name\""
	}
	dict set mymap default $name
	return
    }

    method Alias {name args} {
	debug.cmdr/officer {[self] Alias ($name) $args}
	set n [llength $args]
	if {($n == 1) || (($n > 1) && ([lindex $args 0] ne "="))} {
	    return -code error \
		"wrong\#args: should be \"name ?= cmd ?word...??\""
	}
	my ValidateAsUnknown $name

................................................................................
	# refers to.
	my Def $name $handler
	return
    }

    # Internal. Common code to declare actions and their handlers.
    method DefineAction {what name args} {
	debug.cmdr/officer {[self] DefineAction $what ($name) ...}
	my ValidateAsUnknown $name

	# Note: By placing the subordinate objects into the officer's
	# namespace they will be automatically destroyed with the
	# officer itself. No special code for cleanup required.

	set handler [self namespace]::${what}_$name
................................................................................
	    append prefix $c
	    dict lappend mypmap $prefix $handler
	}
	return
    }

    method ValidateAsUnknown {name} {
	debug.cmdr/officer {[debug caller] | }
	if {![dict exists $mymap a,$name]} return
	return -code error -errorcode {CMDR ACTION KNOWN} \
	    "Unable to learn $name, already specified."
    }

    method Last {} {
	if {![dict exists $mymap last]} {
................................................................................
	    return -code error -errorcode {CMDR ACTION NO-LAST} \
		"Cannot be used as first command"
	}
	return [dict get $mymap last]
    }

    method Known {name} {
	debug.cmdr/officer {[debug caller] | }
	# Known exact action is good
	if {[dict exists $mymap a,$name]} { return 1 }
	debug.cmdr/officer {no action, maybe prefix}
	# Unknown prefix is bad
	if {![dict exists $mypmap $name]} { return 0 }
	debug.cmdr/officer {prefix, maybe ambiguous}
	# As is an ambiguous prefix
................................................................................
	return 1
    }

    # # ## ### ##### ######## #############
    ## Command dispatcher. Choose the subordinate and delegate.

    method do {args} {
	debug.cmdr/officer {[debug caller] | }
	my Setup

	# Process any options we may find. The first non-option
	# will be the command to dispatch on.
	set args [config parse-head-options {*}$args]

	# No command specified, what should we do ?
................................................................................
	# we have no default to punt to and interaction is globally
	# allowed.

	if {![llength $args] && ![my hasdefault] && [cmdr interactive?]} {
	    # Drop into a shell where the user can enter her commands
	    # interactively.

	    debug.cmdr/officer {[debug caller] | shell}

	    set shell [linenoise::facade new [self]]
	    set myreplexit 0 ; # Initialize stop signal, no stopping
	    $shell history 1
	    $shell history= [my history-setup]
	    [my root] set *in-shell* true
	    $shell repl
	    [my root] set *in-shell* false
	    $shell destroy

	    debug.cmdr/officer {[debug caller] | /done shell}
	    return
	}

	my Do {*}$args

	debug.cmdr/officer {[debug caller] | /done}
	return
    }

    # Internal. Actual dispatch. Shared by main entry and shell.
    method Do {args} {
	debug.cmdr/officer {[debug caller] | }
	set reset 0
	if {![my exists *command*]} {
	    # Prevent handling of application-specific options here.
	    my set *command* -- $args
	    set reset 1
	}
	try {
................................................................................
	    }

	    # Split into command and arguments
	    set remainder [lassign $args cmd]

	    # Delegate to the handler for a known command.
	    if {[my Known $cmd]} {
		debug.cmdr/officer {[debug caller] | /known $cmd}

		my lappend *prefix* $cmd
		[my lookup $cmd] do {*}$remainder

		debug.cmdr/officer {[debug caller] | /done known}
		return
	    }

	    # The command word is not known. Delegate the full command to
	    # the default, if we have any. Otherwise fail.

	    if {[my hasdefault]} {
		# prefix left as is.
		debug.cmdr/officer {[debug caller] | /default}

		[my lookup [my default]] do {*}$args
		debug.cmdr/officer {[debug caller] | /done default}
		return
	    }

	    # See also private::FullCmd
	    if {[catch {
		set prefix " [my get *prefix*] "
	    }]} { set prefix "" }
................................................................................
	} finally {
	    if {$reset} {
		my unset *command*
	    }
	    my unset *prefix*
	}

	debug.cmdr/officer {[debug caller] | /done}
    }

    # # ## ### ##### ######## #############
    ## Shell hook methods called by the linenoise::facade.

    method prompt1   {}     { return "[my fullname] > " }
    method prompt2   {}     { error {Continuation lines are not supported} }
................................................................................
    method shell-exit {config} {
	# No arguments, ignore config.
	set myreplexit 1
	return
    }

    method dispatch {cmd} {
	debug.cmdr/officer {[debug caller] | }

	if {$cmd eq {}} {
	    # No command, do nothing.
	    return
	}

	if {$cmd eq ".exit"} {
................................................................................
	    # i.e not in conflict with a user-specified command.
	    set myreplexit 1 ; return
	}
	my Do {*}[string token shell -- $cmd]
    }

    method report {what data} {
	debug.cmdr/officer {[debug caller] | }
	switch -exact -- $what {
	    ok {
		if {$data eq {}} return
		puts stdout $data
	    }
	    fail {
		puts stderr $data
................................................................................
	}
    }

    # # ## ### ##### ######## #############
    # Shell hook method - Command line completion.

    method complete {line} {
	debug.cmdr/officer {[debug caller] | } 10
	#puts stderr ////////$line
	try {
	    set completions [my complete-words [my parse-line $line]]
	} on error {e o} {
	    puts stderr "ERROR: $e"
	    puts stderr $::errorInfo
	    set completions {}
	}
	#puts stderr =($completions)
	return $completions
    }

    method complete-words {parse} {
	debug.cmdr/officer {[debug caller] | } 10
	#puts stderr [my fullname]/[self]/$parse/
	# Note: This method has to entry-points.
	# (1) Above in 'complete', for command completion from self's REPL.
	# (2) Below, as part of recursion from a higher officer while
	#     following the chain of words to the actor responsible
	#     for handling the last word.

................................................................................
	}

	#puts stderr \tC($completions)
	return [lsort -unique [lsort -dict $completions]]
    }

    method CompleteRecurse {parse} {
	debug.cmdr/officer {[debug caller] | } 10
	# Inside the command line. Find the relevant subordinate based
	# on the current word and let it handle everything.

	# The '.exit' pseudo-command of the subordinate is irrelevant
	# during recursion from the current or higher REPL, suppress
	# it. The pseudo-command is only relevant to the officers
	# actually in their REPL.
................................................................................
	# No default, no completions.
	return {}
    }

    # # ## ### ##### ######## #############

    method CCommands {{doexit 1}} {
	debug.cmdr/officer {[debug caller] | } 10
	if {![llength $myccommands]} {
	    # Fill completion command cache.

	    # Standard pseudo-commands.
	    if {$doexit} {
		lappend myccommands .exit
	    }
................................................................................
	return $myccommands
    }


    # # ## ### ##### ######## #############

    method help {{prefix {}}} {
	debug.cmdr/officer {[debug caller] | }
	my Setup
	# Query each subordinate for their help and use it to piece ours together.
	# Note: Result is not finally formatted text, but nested dict structure.
	# Same is expected from the sub-ordinates

	# help = dict (name -> command)
	#if {![my documented]} { return {} }

Changes to tests/help.tests.

305
306
307
308
309
310
311
312






313
314
315
316
317
318
319
...
357
358
359
360
361
362
363
364






365
366
367
368
369
370
371
...
579
580
581
582
583
584
585
586

587





588
589
590
591
592
593
594
...
616
617
618
619
620
621
622
623

624





625
626
627
628
629
630
631
...
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
...
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
...
749
750
751
752
753
754
755
756

757
758
759
760
761
762

763
764
765
	} documented yes flags {--no-pager primary} generator {} interactive no isbool 1 label no-pager arglabel no-pager list no ordered 0 presence yes prompt {Enter no-pager: } required 0 threshold {} type option validator ::cmdr::validate::boolean} short {cmdline 1 code ? default no defered 0 description {
		Activate short form of the help.
	    } documented yes flags {--short primary} generator {} interactive no isbool 1 label short arglabel short list no ordered 0 presence yes prompt {Enter short: } required 0 threshold {} type option validator ::cmdr::validate::boolean} width {cmdline 1 code ? default {} defered 0 description {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} documented yes flags {-w alias --width primary} generator {::apply {p { linenoise columns }}} interactive no isbool 0 label width arglabel width list no ordered 0 presence no prompt {Enter width: } required 0 threshold {} type option validator ::cmdr::validate::integer}} sections *AutoGenerated* action {::cmdr::help::auto-help ::x}} exit {desc {Exit the shell.
		    No-op if not in a shell.} options {} opt2para {} arguments {} states {} parameters {} sections *AutoGenerated* action {ZZZ::my shell-exit}} {} {desc TEST options {} opt2para {} arguments {} states {} parameters {} sections {}}}







test cmdr-help-1.1 {help structure, inverted boolean option} -body {
    cmdr create x foo {
	description TEST
	private nail {
	    description workbench
	    option no-driver force { list ; alias force }
................................................................................
	} documented yes flags {--no-pager primary} generator {} interactive no isbool 1 label no-pager arglabel no-pager list no ordered 0 presence yes prompt {Enter no-pager: } required 0 threshold {} type option validator ::cmdr::validate::boolean} short {cmdline 1 code ? default no defered 0 description {
		Activate short form of the help.
	    } documented yes flags {--short primary} generator {} interactive no isbool 1 label short arglabel short list no ordered 0 presence yes prompt {Enter short: } required 0 threshold {} type option validator ::cmdr::validate::boolean} width {cmdline 1 code ? default {} defered 0 description {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} documented yes flags {-w alias --width primary} generator {::apply {p { linenoise columns }}} interactive no isbool 0 label width arglabel width list no ordered 0 presence no prompt {Enter width: } required 0 threshold {} type option validator ::cmdr::validate::integer}} sections *AutoGenerated* action {::cmdr::help::auto-help ::x}} exit {desc {Exit the shell.
		    No-op if not in a shell.} options {} opt2para {} arguments {} states {} parameters {} sections *AutoGenerated* action {ZZZ::my shell-exit}} {} {desc TEST options {} opt2para {} arguments {} states {} parameters {} sections {}}}







# # ## ### ##### ######## ############# #####################

test cmdr-help-2.0 {full - formatting help structure} -body {
    HelpLarge full
} -result {bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
    hawaii
................................................................................
    cmdname The entire command line, the name of
            the command to get help for. This can
            be several words.

exit
    Exit the shell. No-op if not in a shell.



    TEST}






test cmdr-help-2.1 {full formatting - help structure, inverted boolean option} -body {
    HelpSmall full
} -result {nail [OPTIONS]
    workbench

    --driver    Complementary alias of
................................................................................
    cmdname The entire command line, the name of
            the command to get help for. This can
            be several words.

exit
    Exit the shell. No-op if not in a shell.



    TEST}






# # ## ### ##### ######## ############# #####################

test cmdr-help-3.0 {short - formatting help structure} -body {
    HelpLarge short
} -result {bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
    hawaii
................................................................................
    Retrieve help for a command or command set.
    Without arguments help for all commands is
    given. The default format is --full.

exit
    Exit the shell. No-op if not in a shell.


    TEST}

test cmdr-help-3.1 {short formatting - help structure, inverted boolean option} -body {
    HelpSmall short
} -result {nail [OPTIONS]
    workbench

................................................................................
    Retrieve help for a command or command set.
    Without arguments help for all commands is
    given. The default format is --full.

exit
    Exit the shell. No-op if not in a shell.


    TEST}

# # ## ### ##### ######## ############# #####################

test cmdr-help-4.0 {list - formatting help structure} -body {
    HelpLarge list
} -result {    bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
................................................................................
    tool exit
    tool
    hammer nail [OPTIONS] [<supply>...]
    hammer help [OPTIONS] [<cmdname>...]
    hammer exit
    hammer
    help [OPTIONS] [<cmdname>...]
    exit}


test cmdr-help-4.1 {list formatting - help structure, inverted boolean option} -body {
    HelpSmall list
} -result {    nail [OPTIONS]
    help [OPTIONS] [<cmdname>...]
    exit}


# # ## ### ##### ######## ############# #####################
return







|
>
>
>
>
>
>







 







|
>
>
>
>
>
>







 







<
>
|
>
>
>
>
>







 







<
>
|
>
>
>
>
>







 







|







 







|







 







|
>





|
>



305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
...
591
592
593
594
595
596
597

598
599
600
601
602
603
604
605
606
607
608
609
610
611
...
633
634
635
636
637
638
639

640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
...
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
...
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
	} documented yes flags {--no-pager primary} generator {} interactive no isbool 1 label no-pager arglabel no-pager list no ordered 0 presence yes prompt {Enter no-pager: } required 0 threshold {} type option validator ::cmdr::validate::boolean} short {cmdline 1 code ? default no defered 0 description {
		Activate short form of the help.
	    } documented yes flags {--short primary} generator {} interactive no isbool 1 label short arglabel short list no ordered 0 presence yes prompt {Enter short: } required 0 threshold {} type option validator ::cmdr::validate::boolean} width {cmdline 1 code ? default {} defered 0 description {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} documented yes flags {-w alias --width primary} generator {::apply {p { linenoise columns }}} interactive no isbool 0 label width arglabel width list no ordered 0 presence no prompt {Enter width: } required 0 threshold {} type option validator ::cmdr::validate::integer}} sections *AutoGenerated* action {::cmdr::help::auto-help ::x}} exit {desc {Exit the shell.
		    No-op if not in a shell.} options {} opt2para {} arguments {} states {} parameters {} sections *AutoGenerated* action {ZZZ::my shell-exit}} {} {desc TEST options {--help {
	    Show the help of the application or of the current
	    command, and stop.
	} -? {Alias of --help.} -h {Alias of --help.}} opt2para {--help help -? help -h help} arguments {} states {} parameters {help {cmdline 1 code ? default no defered 0 description {
	    Show the help of the application or of the current
	    command, and stop.
	} documented yes flags {-h alias -? alias --help primary} generator {} interactive no isbool 1 label help arglabel help list no ordered 0 presence yes prompt {Enter help: } required 0 threshold {} type option validator ::cmdr::validate::boolean}} sections {}}}

test cmdr-help-1.1 {help structure, inverted boolean option} -body {
    cmdr create x foo {
	description TEST
	private nail {
	    description workbench
	    option no-driver force { list ; alias force }
................................................................................
	} documented yes flags {--no-pager primary} generator {} interactive no isbool 1 label no-pager arglabel no-pager list no ordered 0 presence yes prompt {Enter no-pager: } required 0 threshold {} type option validator ::cmdr::validate::boolean} short {cmdline 1 code ? default no defered 0 description {
		Activate short form of the help.
	    } documented yes flags {--short primary} generator {} interactive no isbool 1 label short arglabel short list no ordered 0 presence yes prompt {Enter short: } required 0 threshold {} type option validator ::cmdr::validate::boolean} width {cmdline 1 code ? default {} defered 0 description {
	    The line width to format the help for.
	    Defaults to the terminal width, or 80 when
	    no terminal is available.
	} documented yes flags {-w alias --width primary} generator {::apply {p { linenoise columns }}} interactive no isbool 0 label width arglabel width list no ordered 0 presence no prompt {Enter width: } required 0 threshold {} type option validator ::cmdr::validate::integer}} sections *AutoGenerated* action {::cmdr::help::auto-help ::x}} exit {desc {Exit the shell.
		    No-op if not in a shell.} options {} opt2para {} arguments {} states {} parameters {} sections *AutoGenerated* action {ZZZ::my shell-exit}} {} {desc TEST options {--help {
	    Show the help of the application or of the current
	    command, and stop.
	} -? {Alias of --help.} -h {Alias of --help.}} opt2para {--help help -? help -h help} arguments {} states {} parameters {help {cmdline 1 code ? default no defered 0 description {
	    Show the help of the application or of the current
	    command, and stop.
	} documented yes flags {-h alias -? alias --help primary} generator {} interactive no isbool 1 label help arglabel help list no ordered 0 presence yes prompt {Enter help: } required 0 threshold {} type option validator ::cmdr::validate::boolean}} sections {}}}

# # ## ### ##### ######## ############# #####################

test cmdr-help-2.0 {full - formatting help structure} -body {
    HelpLarge full
} -result {bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
    hawaii
................................................................................
    cmdname The entire command line, the name of
            the command to get help for. This can
            be several words.

exit
    Exit the shell. No-op if not in a shell.


 [OPTIONS]
    TEST

    --help Show the help of the application or of
           the current command, and stop.
    -?     Alias of --help.
    -h     Alias of --help.}

test cmdr-help-2.1 {full formatting - help structure, inverted boolean option} -body {
    HelpSmall full
} -result {nail [OPTIONS]
    workbench

    --driver    Complementary alias of
................................................................................
    cmdname The entire command line, the name of
            the command to get help for. This can
            be several words.

exit
    Exit the shell. No-op if not in a shell.


 [OPTIONS]
    TEST

    --help Show the help of the application or of
           the current command, and stop.
    -?     Alias of --help.
    -h     Alias of --help.}

# # ## ### ##### ######## ############# #####################

test cmdr-help-3.0 {short - formatting help structure} -body {
    HelpLarge short
} -result {bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
    hawaii
................................................................................
    Retrieve help for a command or command set.
    Without arguments help for all commands is
    given. The default format is --full.

exit
    Exit the shell. No-op if not in a shell.

 [OPTIONS]
    TEST}

test cmdr-help-3.1 {short formatting - help structure, inverted boolean option} -body {
    HelpSmall short
} -result {nail [OPTIONS]
    workbench

................................................................................
    Retrieve help for a command or command set.
    Without arguments help for all commands is
    given. The default format is --full.

exit
    Exit the shell. No-op if not in a shell.

 [OPTIONS]
    TEST}

# # ## ### ##### ######## ############# #####################

test cmdr-help-4.0 {list - formatting help structure} -body {
    HelpLarge list
} -result {    bar aloha [OPTIONS] <yoyo> [<jump>] <run>...
................................................................................
    tool exit
    tool
    hammer nail [OPTIONS] [<supply>...]
    hammer help [OPTIONS] [<cmdname>...]
    hammer exit
    hammer
    help [OPTIONS] [<cmdname>...]
    exit
     [OPTIONS]}

test cmdr-help-4.1 {list formatting - help structure, inverted boolean option} -body {
    HelpSmall list
} -result {    nail [OPTIONS]
    help [OPTIONS] [<cmdname>...]
    exit
     [OPTIONS]}

# # ## ### ##### ######## ############# #####################
return

Changes to tests/parameter.tests.

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
57
58
59
60
..
64
65
66
67
68
69
70

71

72

73




74
75
76
77

78

79















80
81
82
83
84
85
86
..
93
94
95
96
97
98
99

100

101

102




103
104
105
106

107

108
109
110
111
112
113
114
115
116















117
118
119
120
121
122
123
...
151
152
153
154
155
156
157









158
159
160
161
162
163















164
165
166
167
168
169
170
171
172
173
174
175
176









177
178
179
180
181
182
183
184
185















186
187
188
189
190
191
192
193
194
195









196
197
198
199
200
201
202
203
204
205















206
207
208
209
210
211
212
213

214

215





216
217
218
219

220

221
222
223
224
225
226
227















228
229
230
231
232
233
234
235
236
237
238
239


240






241

242
243
244
245
246
247
248
249
250
251















252
253
254
255
256
257
258
259


260






261

262
263
264
265
266
267
268
269
270
271















272
273
274
275
276
277
278
279









280
281
282
283
284















285
286
287
288
289
290
291
292
293
294
295
296









297
298
299
300
301
302
303
304















305
306
307
308
309
310
311
312
313









314
315
316
317
318
319
320
321















322
323
324
325
326
327
328
...
358
359
360
361
362
363
364









365
366
367
368
369
370
371
372
373
374















375
376
377
378
379
380
381
382


383






384

385
386
387
388
389
390
391
392
393
394















395
396
397
398
399
400
401
402









403
404
405
406
407
408
409
410















411
412
413
414
415
416
417
...
442
443
444
445
446
447
448









449
450
451
452
453
454
455
456
457
458
459















460
461
462
463
464
465
466
467
468









469
470
471
472
473
474
475
476
477
478
479















480
481
482
483
484
485
486
487

488

489





490
491
492
493

494

495
496
497
498
499
500
501
502
503
504
505
506















507
508
509
510
511
512
513
514









515
516
517
518
519
520
521
522
523















524
525
526
527
528
529
530
...
535
536
537
538
539
540
541









542
543
544
545
546
547
548
549















550
551
552
553
554
555
556
...
566
567
568
569
570
571
572

573

574





575
576
577
578

579

580
581
582
583
584
585
586















587
588
589
590
591
592
593
594
595
596
597
598









599
600
601
602
603
604
605
606















607
608
609
610
611
612
613
...
618
619
620
621
622
623
624









625
626
627
628
629
630
631
632
633















634
635
636
637
638
639
640
...
660
661
662
663
664
665
666









667
668
669
670
671
672
673
674
675















676
677
678
679
680
681
682
...
702
703
704
705
706
707
708









709
710
711
712
713
714
715
716















717
718
719
720
721
722
723
724
725
726









727
728
729
730
731
732
733
734















735
736
737
738
739
740
741
742
743


744






745

746
747
748
749
750
751
752
753
754
755















756
757
758
759
760
761
762
763


764






765

766
767
768
769
770
771
772
773
774
775















776
777
778
779
780
781
782
783









784
785
786
787
788
789
790
791















792
793
794
795
796
797
798
799
800









801
802
803
804
805
806
807
808















809
810
811
812
813
814
815
...
825
826
827
828
829
830
831









832
833
834
835
836
837
838
839
840















841
842
843
844
845
846
847
848

849

850





851
852
853
854

855

856
857
858
859
860
861
862
863
864
865
866















867
868
869
870
871
872
873
874









875
876
877
878
879
880
881
882















883
884
885
886
887
888
    -result {Non-option parameter "A" cannot have alias}

test cmdr-parameter-1.3 {parameter DSL, option, alias} -body {
    NiceParamSpec option { alias X }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A

        option (-X) = A




        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        map -X --> (-X)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = inverted
                -A = primary
                -X = alias















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................
    -result {Non-option parameter "A" cannot have alias}

test cmdr-parameter-1.5 {parameter DSL, negative option, alias} -body {
    NiceParamSpec option { alias X } no-A
} -result {
    foo bar = {
        description: ''

        option (--no-A) = no-A

        option (-A) = no-A

        option (-X) = no-A




        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        map -X --> (-X)















        para (no-A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = primary
                -A = inverted
................................................................................
}

test cmdr-parameter-1.6 {parameter DSL, option, negative alias} -body {
    NiceParamSpec option { neg-alias X }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A

        option (-X) = A




        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        map -X --> (-X)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = inverted
                -A = primary
                -X = inverted















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................

test cmdr-parameter-2.3 {parameter DSL, optional input, default, auto validate boolean} -body {
    NiceParamSpec input { optional ; default 0 }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: '0'
            mode=threshold 0
            flags []















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.4 {parameter DSL, optional input, default, auto validate integer} -body {
    NiceParamSpec input { optional ; default 2 }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: '2'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()















        }
    }
}

test cmdr-parameter-2.5 {parameter DSL, optional input, default, auto validate identity} -body {
    NiceParamSpec input { optional ; default X }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: 'X'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-2.6 {parameter DSL, option, default, auto validate boolean} -body {
    NiceParamSpec option { default 0 }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A





        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '0'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.7 {parameter DSL, option, default, auto validate integer } -body {
    NiceParamSpec option { default 2 }
} -result {
    foo bar = {
        description: ''


        option (-A) = A






        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '2'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }















    }
}

test cmdr-parameter-2.8 {parameter DSL, option, default, auto validate identity} -body {
    NiceParamSpec option { default X }
} -result {
    foo bar = {
        description: ''


        option (-A) = A






        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'X'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-2.9 {parameter DSL, state, default, auto validate boolean} -body {
    NiceParamSpec state { default 0 }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '0'
            flags []















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.10 {parameter DSL, state, default, auto validate integer} -body {
    NiceParamSpec state { default 2 }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '2'
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()















        }
    }
}

test cmdr-parameter-2.11 {parameter DSL, state, default, auto validate identity} -body {
    NiceParamSpec state { default X }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: 'X'
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-2.12 {(C7) parameter DSL, optional input, default after generate} -body {
    BadParamSpec input { optional ; generate X ; default VALUE }
} -returnCodes error \
................................................................................

test cmdr-parameter-3.2 {parameter DSL, optional input, generate} -body {
    NiceParamSpec input { optional ; generate G }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            no default
            mode=threshold 0
            flags []
            ge (G)
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-3.3 {parameter DSL, option, generate} -body {
    NiceParamSpec option { generate G }
} -result {
    foo bar = {
        description: ''


        option (-A) = A






        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            no default
            flags [-A]
                -A = primary
            ge (G)
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-3.4 {parameter DSL, state, generate} -body {
    NiceParamSpec state { generate G }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            no default
            flags []
            ge (G)
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-3.5 {(C7) parameter DSL, optional input, generate after default} -body {
    BadParamSpec input { optional ; default VALUE ; generate X }
} -returnCodes error \
................................................................................

test cmdr-parameter-4.2 {parameter DSL, optional input, interact, default prompt} -body {
    NiceParamSpec input { optional ; interact }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, interact, immediate
            default: ''
            prompt: 'Enter A: '
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-4.3 {parameter DSL, optional input, interact, custom prompt} -body {
    NiceParamSpec input { optional ; interact HERE }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, interact, immediate
            default: ''
            prompt: 'HERE'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-4.4 {parameter DSL, option, interact} -body {
    NiceParamSpec option { interact }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A





        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, interact, immediate
            default: 'no'
            prompt: 'Enter A: '
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }















    }
}

test cmdr-parameter-4.5 {parameter DSL, state, interact} -body {
    NiceParamSpec state { interact }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, interact, defered
            default: ''
            prompt: 'Enter A: '
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'list' across parameters (input, option, state)

................................................................................

test cmdr-parameter-5.1 {parameter DSL, list input} -body {
    NiceParamSpec input { list }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, splat, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-5.2 {parameter DSL, list input not last} -body {
    # Double input, BadParamSpec not suitable
    cmdr create x foo {
................................................................................
    -result {A splat must be the last argument in the specification}

test cmdr-parameter-5.3 {parameter DSL, list option} -body {
    NiceParamSpec option { list }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A





        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, splat, optional, silent, immediate
            default: ''
            flags [--no-A -A]
                --no-A = inverted
                -A = primary















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-5.4 {parameter DSL, list state} -body {
    NiceParamSpec state { list }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, splat, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'optional' across parameters (input, option, state)

................................................................................

test cmdr-parameter-6.1 {parameter DSL, optional input} -body {
    NiceParamSpec input { optional }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-6.2 {parameter DSL, optional option} -body {
    BadParamSpec option { optional }
} -returnCodes error \
................................................................................

test cmdr-parameter-7.2 {parameter DSL, optional input, test} -body {
    NiceParamSpec input { optional ; test }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=peek+test
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-7.3 {parameter DSL, option, test} -body {
    BadParamSpec option { test }
} -returnCodes error \
................................................................................

test cmdr-parameter-8.2 {parameter DSL, input, validate, shorthand} -body {
    NiceParamSpec input { validate integer }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()















        }
    }
}

test cmdr-parameter-8.3 {parameter DSL, input, validate} -body {
    NiceParamSpec input { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

test cmdr-parameter-8.4 {parameter DSL, option, validate, shorthand} -body {
    NiceParamSpec option { validate integer }
} -result {
    foo bar = {
        description: ''


        option (-A) = A






        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '0'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }















    }
}

test cmdr-parameter-8.5 {parameter DSL, option, validate} -body {
    NiceParamSpec option { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''


        option (-A) = A






        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: ''
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

test cmdr-parameter-8.6 {parameter DSL, state, validate, shorthand} -body {
    NiceParamSpec state { validate integer }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '0'
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()















        }
    }
}

test cmdr-parameter-8.7 {parameter DSL, state, validate} -body {
    NiceParamSpec state { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'when-complete' across parameters (input, option, state)

................................................................................

test cmdr-parameter-9.2 {parameter DSL, input, when-complete} -body {
    NiceParamSpec input { when-complete X }
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd (X)
        }















    }
}

test cmdr-parameter-9.3 {parameter DSL, option, when-complete} -body {
    NiceParamSpec option { when-complete X }
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A





        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd (X)
        }















    }
}

test cmdr-parameter-9.4 {parameter DSL, state, when-complete} -body {
    NiceParamSpec state { when-complete X }
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd (X)















        }
    }
}

# # ## ### ##### ######## ############# #####################
return







>

>

>

>
>
>
>




>

>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>

>

>

>
>
>
>




>

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>

>

>

>
>
>
>




>

>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>

>

>
>
>
>
>




>

>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
>

>
>
>
>
>
>

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>

>
>
>
>
>
>

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>

>
>
>
>
>
>

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>

>

>
>
>
>
>




>

>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>

>

>
>
>
>
>




>

>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>

>
>
>
>
>
>

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>

>
>
>
>
>
>

>










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>

>

>
>
>
>
>




>

>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
...
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
...
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
...
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
....
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
....
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
....
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
....
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
....
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
    -result {Non-option parameter "A" cannot have alias}

test cmdr-parameter-1.3 {parameter DSL, option, alias} -body {
    NiceParamSpec option { alias X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        option (-X) = A
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        map -X --> (-X)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = inverted
                -A = primary
                -X = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................
    -result {Non-option parameter "A" cannot have alias}

test cmdr-parameter-1.5 {parameter DSL, negative option, alias} -body {
    NiceParamSpec option { alias X } no-A
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = no-A
        option (-?) = help
        option (-A) = no-A
        option (-h) = help
        option (-X) = no-A
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        map -X --> (-X)
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (no-A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = primary
                -A = inverted
................................................................................
}

test cmdr-parameter-1.6 {parameter DSL, option, negative alias} -body {
    NiceParamSpec option { neg-alias X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        option (-X) = A
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        map -X --> (-X)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A -X]
                --no-A = inverted
                -A = primary
                -X = inverted
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................

test cmdr-parameter-2.3 {parameter DSL, optional input, default, auto validate boolean} -body {
    NiceParamSpec input { optional ; default 0 }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: '0'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.4 {parameter DSL, optional input, default, auto validate integer} -body {
    NiceParamSpec input { optional ; default 2 }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: '2'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.5 {parameter DSL, optional input, default, auto validate identity} -body {
    NiceParamSpec input { optional ; default X }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: 'X'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.6 {parameter DSL, option, default, auto validate boolean} -body {
    NiceParamSpec option { default 0 }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '0'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.7 {parameter DSL, option, default, auto validate integer } -body {
    NiceParamSpec option { default 2 }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '2'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.8 {parameter DSL, option, default, auto validate identity} -body {
    NiceParamSpec option { default X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'X'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.9 {parameter DSL, state, default, auto validate boolean} -body {
    NiceParamSpec state { default 0 }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '0'
            flags []
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.10 {parameter DSL, state, default, auto validate integer} -body {
    NiceParamSpec state { default 2 }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '2'
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.11 {parameter DSL, state, default, auto validate identity} -body {
    NiceParamSpec state { default X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: 'X'
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-2.12 {(C7) parameter DSL, optional input, default after generate} -body {
    BadParamSpec input { optional ; generate X ; default VALUE }
} -returnCodes error \
................................................................................

test cmdr-parameter-3.2 {parameter DSL, optional input, generate} -body {
    NiceParamSpec input { optional ; generate G }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            no default
            mode=threshold 0
            flags []
            ge (G)
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-3.3 {parameter DSL, option, generate} -body {
    NiceParamSpec option { generate G }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            no default
            flags [-A]
                -A = primary
            ge (G)
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-3.4 {parameter DSL, state, generate} -body {
    NiceParamSpec state { generate G }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            no default
            flags []
            ge (G)
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-3.5 {(C7) parameter DSL, optional input, generate after default} -body {
    BadParamSpec input { optional ; default VALUE ; generate X }
} -returnCodes error \
................................................................................

test cmdr-parameter-4.2 {parameter DSL, optional input, interact, default prompt} -body {
    NiceParamSpec input { optional ; interact }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, interact, immediate
            default: ''
            prompt: 'Enter A: '
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-4.3 {parameter DSL, optional input, interact, custom prompt} -body {
    NiceParamSpec input { optional ; interact HERE }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, interact, immediate
            default: ''
            prompt: 'HERE'
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-4.4 {parameter DSL, option, interact} -body {
    NiceParamSpec option { interact }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, interact, immediate
            default: 'no'
            prompt: 'Enter A: '
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-4.5 {parameter DSL, state, interact} -body {
    NiceParamSpec state { interact }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, interact, defered
            default: ''
            prompt: 'Enter A: '
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'list' across parameters (input, option, state)

................................................................................

test cmdr-parameter-5.1 {parameter DSL, list input} -body {
    NiceParamSpec input { list }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, splat, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-5.2 {parameter DSL, list input not last} -body {
    # Double input, BadParamSpec not suitable
    cmdr create x foo {
................................................................................
    -result {A splat must be the last argument in the specification}

test cmdr-parameter-5.3 {parameter DSL, list option} -body {
    NiceParamSpec option { list }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, splat, optional, silent, immediate
            default: ''
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-5.4 {parameter DSL, list state} -body {
    NiceParamSpec state { list }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, splat, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'optional' across parameters (input, option, state)

................................................................................

test cmdr-parameter-6.1 {parameter DSL, optional input} -body {
    NiceParamSpec input { optional }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=threshold 0
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-6.2 {parameter DSL, optional option} -body {
    BadParamSpec option { optional }
} -returnCodes error \
................................................................................

test cmdr-parameter-7.2 {parameter DSL, optional input, test} -body {
    NiceParamSpec input { optional ; test }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=peek+test
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-7.3 {parameter DSL, option, test} -body {
    BadParamSpec option { test }
} -returnCodes error \
................................................................................

test cmdr-parameter-8.2 {parameter DSL, input, validate, shorthand} -body {
    NiceParamSpec input { validate integer }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-8.3 {parameter DSL, input, validate} -body {
    NiceParamSpec input { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-8.4 {parameter DSL, option, validate, shorthand} -body {
    NiceParamSpec option { validate integer }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: '0'
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-8.5 {parameter DSL, option, validate} -body {
    NiceParamSpec option { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: ''
            flags [-A]
                -A = primary
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-8.6 {parameter DSL, state, validate, shorthand} -body {
    NiceParamSpec state { validate integer }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: '0'
            flags []
            ge ()
            va (::cmdr::validate::integer)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-8.7 {parameter DSL, state, validate} -body {
    NiceParamSpec state { validate ::cmdr::validate::identity }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter DSL: 'when-complete' across parameters (input, option, state)

................................................................................

test cmdr-parameter-9.2 {parameter DSL, input, when-complete} -body {
    NiceParamSpec input { when-complete X }
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd (X)
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-9.3 {parameter DSL, option, when-complete} -body {
    NiceParamSpec option { when-complete X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd (X)
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

test cmdr-parameter-9.4 {parameter DSL, state, when-complete} -body {
    NiceParamSpec state { when-complete X }
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd (X)
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
return

Changes to tests/private.tests.

21
22
23
24
25
26
27

28
29






30
31
32
33
34
35
36
..
38
39
40
41
42
43
44

















45
46
47
48
49
50
51
..
92
93
94
95
96
97
98









99
100
101
102
103
104
105
...
139
140
141
142
143
144
145















146
147
148
149
150
151
152
...
179
180
181
182
183
184
185









186
187
188
189
190
191
192
193















194
195
196
197
198
199
200
...
226
227
228
229
230
231
232

233

234





235
236
237
238

239

240
241
242
243
244
245
246















247
248
249
250
251
252
253
...
282
283
284
285
286
287
288









289
290
291
292
293
294
295
296















297
298
299
300
301
302
        description: 'TEST'
        store (def): '
	    input  INPUT  INPUT-DESC
	    option OPTION OPTION-DESC
	    state  STATE  STATE-DESC
	'
        argument (INPUT)

        option (--no-OPTION) = OPTION
        option (--OPTION) = OPTION






        map --n --> (--no-OPTION)
        map --no --> (--no-OPTION)
        map --no- --> (--no-OPTION)
        map --no-O --> (--no-OPTION)
        map --no-OP --> (--no-OPTION)
        map --no-OPT --> (--no-OPTION)
        map --no-OPTI --> (--no-OPTION)
................................................................................
        map --no-OPTION --> (--no-OPTION)
        map --O --> (--OPTION)
        map --OP --> (--OPTION)
        map --OPT --> (--OPTION)
        map --OPTI --> (--OPTION)
        map --OPTIO --> (--OPTION)
        map --OPTION --> (--OPTION)

















        para (INPUT) {
            description: 'INPUT-DESC'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
................................................................................
    foo bar = {
        description: '6.1'
        argument (A)
        argument (B)
        argument (C)
        argument (D)
        argument (E)









        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
................................................................................
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }















    }
}

# # ## ### ##### ######## ############# #####################
## Parameter declaration commands: input, splat, option, state

test cmdr-private-2.0 {private, input, wrong num args, not enough} -setup {
................................................................................
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        argument (A)









        para (A) {
            description: 'D'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

# # ## ### ##### ######## ############# #####################

test cmdr-private-3.0 {private, option, wrong num args, not enough} -setup {
................................................................................
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''

        option (--no-A) = A

        option (-A) = A





        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)

        map -A --> (-A)

        para (A) {
            description: 'D'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary















            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''









        para (A) {
            description: 'D'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()















        }
    }
}

# # ## ### ##### ######## ############# #####################
return







>


>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>

>

>
>
>
>
>




>

>







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
        description: 'TEST'
        store (def): '
	    input  INPUT  INPUT-DESC
	    option OPTION OPTION-DESC
	    state  STATE  STATE-DESC
	'
        argument (INPUT)
        option (--help) = help
        option (--no-OPTION) = OPTION
        option (--OPTION) = OPTION
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-OPTION)
        map --no --> (--no-OPTION)
        map --no- --> (--no-OPTION)
        map --no-O --> (--no-OPTION)
        map --no-OP --> (--no-OPTION)
        map --no-OPT --> (--no-OPTION)
        map --no-OPTI --> (--no-OPTION)
................................................................................
        map --no-OPTION --> (--no-OPTION)
        map --O --> (--OPTION)
        map --OP --> (--OPTION)
        map --OPT --> (--OPTION)
        map --OPTI --> (--OPTION)
        map --OPTIO --> (--OPTION)
        map --OPTION --> (--OPTION)
        map -? --> (-?)
        map -h --> (-h)
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (INPUT) {
            description: 'INPUT-DESC'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
................................................................................
    foo bar = {
        description: '6.1'
        argument (A)
        argument (B)
        argument (C)
        argument (D)
        argument (E)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
................................................................................
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter declaration commands: input, splat, option, state

test cmdr-private-2.0 {private, input, wrong num args, not enough} -setup {
................................................................................
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: 'D'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################

test cmdr-private-3.0 {private, option, wrong num args, not enough} -setup {
................................................................................
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: 'D'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

................................................................................
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: 'D'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
return

Changes to tests/runtime.tests.

62
63
64
65
66
67
68
69
70
71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
...
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
...
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222
...
227
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244

245
246
247
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264

265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296

297
298
299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334
335

336
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351

352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
377
378
379
380
381

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396

397
398
399
400
401
402
403
404

405
406
407
408
409
410
411
412
413
414

415
416
417
418
419
420
421
422

423
424
425
426
427
428
429
430
431
432

433
434
435
436
437
438
439
440

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470

471
472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
...
492
493
494
495
496
497
498
499
500

501
502
503
504
505
506
507
508
...
512
513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
528
...
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
...
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
...
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
...
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664
665
666

667
668
669
670
671
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3
} -result {
    A = '1'         v'1'
    B = <undefined> v'0'
    C = '2'         v'2'
    D = <undefined> v'0'
    E = '3'         v'3'

}

test cmdr-runtime-1.4 {required + optional arguments, assignment under thresholding} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3 4
} -result {
    A = '1'         v'1'
    B = '2'         v'2'
    C = '3'         v'3'
    D = <undefined> v'0'
    E = '4'         v'4'

}

test cmdr-runtime-1.5 {required + optional arguments, assignment under thresholding} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3 4 5
} -result {
    A = '1' v'1'
    B = '2' v'2'
    C = '3' v'3'
    D = '4' v'4'
    E = '5' v'5'

}

test cmdr-runtime-1.6 {required + optional arguments, too many} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
................................................................................

test cmdr-runtime-2.2 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2
} -result {
    A = '1' v'1'
    B = '2' v'2'

}

test cmdr-runtime-2.3 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2 3
} -result {
    A = '1'   v'1'
    B = '2 3' v'2 3'

}

test cmdr-runtime-2.4 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2 3 4
} -result {
    A = '1'     v'1'
    B = '2 3 4' v'2 3 4'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.5 {required + optional splat, not enough} -body {
    Parse {
	input A - { validate integer }
................................................................................

test cmdr-runtime-2.6 {required + optional splat, empty} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1
} -result {
    A = '1'         v'1'
    B = <undefined> v''

}

test cmdr-runtime-2.7 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2
} -result {
    A = '1' v'1'
    B = '2' v'2'

}

test cmdr-runtime-2.8 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3
} -result {
    A = '1'   v'1'
    B = '2 3' v'2 3'

}

test cmdr-runtime-2.9 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3 4
} -result {
    A = '1'     v'1'
    B = '2 3 4' v'2 3 4'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.10 {optional + required splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
................................................................................

test cmdr-runtime-2.11 {optional + required splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1
} -result {
    A = <undefined> v'0'
    B = '1'         v'1'

}
test cmdr-runtime-2.12 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2
} -result {
    A = '1' v'1'
    B = '2' v'2'

}

test cmdr-runtime-2.13 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2 3
} -result {
    A = '1'   v'1'
    B = '2 3' v'2 3'

}

test cmdr-runtime-2.14 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2 3 4
} -result {
    A = '1'     v'1'
    B = '2 3 4' v'2 3 4'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.15 {optional + optional splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    }
} -result {
    A = <undefined> v'0'
    B = <undefined> v''

}

test cmdr-runtime-2.16 {optional + optional splat, empty} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1
} -result {
    A = '1'         v'1'
    B = <undefined> v''

}

test cmdr-runtime-2.17 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2
} -result {
    A = '1' v'1'
    B = '2' v'2'

}

test cmdr-runtime-2.18 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3
} -result {
    A = '1'   v'1'
    B = '2 3' v'2 3'

}

test cmdr-runtime-2.19 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3 4
} -result {
    A = '1'     v'1'
    B = '2 3 4' v'2 3 4'

}

# # ## ### ##### ######## ############# #####################
## Group III: Options.

test cmdr-runtime-3.0 {options, simple, boolean} -body {
    Parse {
	option A -
    }
} -result {

    A = <undefined> v'no'
}

test cmdr-runtime-3.1 {options, simple, boolean} -body {
    Parse {
	option A -
    } -A 1
} -result {
    A = '1' v'1'

}

test cmdr-runtime-3.2 {options, simple, boolean} -body {
    Parse {
	option A -
    } -A 0
} -result {
    A = '0' v'0'

}

test cmdr-runtime-3.2 {options, simple, boolean, multiple use} -body {
    Parse {
	option A -
    } -A 0 -A 1
} -result {
    A = '1' v'1'

}

test cmdr-runtime-3.3 {options, simple, boolean, special forms} -body {
    Parse {
	option A -
	option B -
	option C -
	option D -
	option E -
	option F -
	option G - { validate identity }
    } -A -G X --no-B -G X -C 1 -D 0 --no-E 1 --no-F 0
} -result {
    A = 'yes' v'1'
    B = '0'   v'0'
    C = '1'   v'1'
    D = '0'   v'0'
    E = '0'   v'0'
    F = '1'   v'1'
    G = 'X'   v'X'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.4 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    }
} -result {
    A = <undefined> v''

}

test cmdr-runtime-3.5 {options, list, string, missing value} -body {
    Parse {
	option A - { list ; validate identity }
    } -A
} -returnCodes error \
    -result "wrong\#args, missing value for option '-A'"

test cmdr-runtime-3.6 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    } -A X
} -result {
    A = 'X' v'X'

}

test cmdr-runtime-3.7 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    } -A X -A Y
} -result {
    A = 'X Y' v'X Y'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.8 {options, aliases} -body {
    Parse {
	option A - { validate identity ; alias Z }
    } -A X -Z Y
} -result {
    A = 'Y' v'Y'

}

test cmdr-runtime-3.9 {options, aliases, list} -body {
    Parse {
	option A - { list ; validate identity ; alias Z }
    } -A X -Z Y
} -result {
    A = 'X Y' v'X Y'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.10 {options, long names} -body {
    Parse {
	option ALPHA - { list ; validate identity }
    } --ALPHA Z
} -result {
    ALPHA = 'Z' v'Z'

}

test cmdr-runtime-3.11 {options, unique prefix expansion} -body {
    Parse {
	option ALPHA - { list ; validate identity }
    } --AL Z
} -result {
    ALPHA = 'Z' v'Z'

}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.12 {options, unknown option} -body {
    Parse {
	option A - { validate identity }
    } -B Z
} -returnCodes error \
    -result {Unknown option -B}

test cmdr-runtime-3.13 {options, ambiguous prefix} -body {
    Parse {
	option ALPHA - { validate identity }
	option ALNUM - { validate identity }
    } --AL Z
} -returnCodes error \
    -result {Ambiguous option prefix --AL, matching --ALNUM, --ALPHA}

# NOTE: Test is brittle, dependent on the internal order in which the
# options are processed by UniquePrefixes.

test cmdr-runtime-3.14 {options, semi-ambiguous prefix (other option)} -body {
    Parse {
	option ALPHA - { validate identity }
	option AL    - { validate identity }
    } --AL Z
} -result {
    AL    = 'Z'         v'Z'
    ALPHA = <undefined> v''

}

# NOTE: Test is brittle, dependent on the internal order in which the
# options are processed by UniquePrefixes.

test cmdr-runtime-3.15 {options, semi-ambiguous prefix (other option)} -body {
    Parse {
	option AL-PHA - { validate identity }
	option AL     - { validate identity }
    } --AL Z --AL-PHA Y
} -result {
    AL     = 'Z' v'Z'
    AL-PHA = 'Y' v'Y'

}

# # ## ### ##### ######## ############# #####################
## Group IV: Mix options and arguments.

test cmdr-runtime-4.1 {options, arguments, and splat} -body {
    Parse {
................................................................................
	input  C - { optional ; validate identity ; list }
	option T - { validate identity }
    } A -T X C C C -T Y
    # The threshold method for optional arguments processes options
    # before arguments, handling the 2nd -T before splat collection.
    # Compare to 5.1.
} -result {
    A = 'A'     v'A'
    C = 'C C C' v'C C C'

    T = 'Y'     v'Y'
}

# # ## ### ##### ######## ############# #####################
## Group V: Optional arguments, via peek+validate

test cmdr-runtime-5.1 {options, arguments, and splat, peek} -body {
    Parse {
................................................................................
    } A -T X C C C -T Y
    # The peek+validate method for optional arguments does not look
    # ahead beyond that, thus the 2nd -T becomes part of the splat
    # collection. Compare to 4.1. Note that the splat is _also_ put
    # into peek+validate mode, otherwise it would force the options to
    # be processed first.
} -result {
    A = 'A'          v'A'
    C = 'C C C -T Y' v'C C C -T Y'

    T = 'X'          v'X'
}

# # ## ### ##### ######## ############# #####################
## Group VI: Introspect on the context of the generate, validate, and
##           when-complete command prefixes. Ensure that they are
##           called and work.

................................................................................
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    generate MATCH
    {} {    A = <undefined> v'G'} {}
}

test cmdr-runtime-6.2 {validation, default supplication} -setup {
    StartNotes
    set ons A ; # Trigger parse to save the object namespace.
} -body {
    Note {*}[split [Parse {
................................................................................
	}
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    names = {}
    validate default MATCH
    {} {    A = <undefined> v'zZzZz'} {}
}

test cmdr-runtime-6.3 {generator command} -setup {
    StartNotes
    set ons A ; # Trigger parse to save the parameter object namespace.
} -body {
    Note {*}[split [Parse {
................................................................................
	}
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    names = A
    defined = {}
    defined MATCH
    {} {    A = <undefined> v''} {}
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-7.1 {not-quite options, arguments} -body {
    Parse {
	input  A - { optional ; validate identity }
	option T - { validate identity }
    } -1 -T -3
    # The -1 looks like an option, but is for input A.
} -result {
    A = '-1' v'-1'

    T = '-3' v'-3'
}

test cmdr-runtime-7.2 {validation errors} -body {
    ParseFailParse {
	input A - { validate integer }
	input B - { validate integer }
    } 1 X
................................................................................
	option C -
	option D -
	option E -
	option F -
	option G - { validate identity }
    } -A -G=X --no-B -G=X -C=1 -D=0 --no-E=1 --no-F=0
} -result {
    A = 'yes' v'1'
    B = '0'   v'0'
    C = '1'   v'1'
    D = '0'   v'0'
    E = '0'   v'0'
    F = '1'   v'1'
    G = 'X'   v'X'

}

test cmdr-runtime-8.1 {options, boolean, aliases} -body {
    Parse {
	option A - { alias     X }
	option B - { neg-alias Y }
    } -X -Y
} -result {
    A = 'yes' v'1'
    B = '0'   v'0'

}

test cmdr-runtime-8.2 {options, boolean, aliases, special forms} -body {
    Parse {
	option A - { alias     X }
	option B - { neg-alias Y }
    } -X=0 -Y=0
} -result {
    A = '0' v'0'
    B = '1' v'1'

}

# # ## ### ##### ######## ############# #####################

return







|
|
|
|
|
>











|
|
|
|
|
>











|
|
|
|
|
>







 







|
|
>








|
|
>








|
|
>







 







|
|
>








|
|
>








|
|
>








|
|
>







 







|
|
>







|
|
>








|
|
>








|
|
>










|
|
>








|
|
>








|
|
>








|
|
>








|
|
>










>
|







|
>







|
>


|




|
>


|










|
|
|
|
|
|
|
>




|




|
>


|






|




|
>


|




|
>




|




|
>


|




|
>




|




|
>


|




|
>




|






|










|







>





|





|
|
>







 







|
|
>
|







 







|
|
>
|







 







|







 







|

|







 







|


|











|
>
|







 







|
|
|
|
|
|
|
>








|
|
>








|
|
>





62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
...
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
...
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
...
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
...
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
...
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
...
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3
} -result {
    A    = '1'         v'1'
    B    = <undefined> v'0'
    C    = '2'         v'2'
    D    = <undefined> v'0'
    E    = '3'         v'3'
    help = <undefined> v'no'
}

test cmdr-runtime-1.4 {required + optional arguments, assignment under thresholding} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3 4
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    C    = '3'         v'3'
    D    = <undefined> v'0'
    E    = '4'         v'4'
    help = <undefined> v'no'
}

test cmdr-runtime-1.5 {required + optional arguments, assignment under thresholding} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
	input D - { validate integer; optional ; default 0 }
	input E - { validate integer }
    } 1 2 3 4 5
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    C    = '3'         v'3'
    D    = '4'         v'4'
    E    = '5'         v'5'
    help = <undefined> v'no'
}

test cmdr-runtime-1.6 {required + optional arguments, too many} -body {
    Parse {
	input A - { validate integer }
	input B - { validate integer; optional ; default 0 }
	input C - { validate integer }
................................................................................

test cmdr-runtime-2.2 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    help = <undefined> v'no'
}

test cmdr-runtime-2.3 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2 3
} -result {
    A    = '1'         v'1'
    B    = '2 3'       v'2 3'
    help = <undefined> v'no'
}

test cmdr-runtime-2.4 {required + required splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; validate integer }
    } 1 2 3 4
} -result {
    A    = '1'         v'1'
    B    = '2 3 4'     v'2 3 4'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.5 {required + optional splat, not enough} -body {
    Parse {
	input A - { validate integer }
................................................................................

test cmdr-runtime-2.6 {required + optional splat, empty} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1
} -result {
    A    = '1'         v'1'
    B    = <undefined> v''
    help = <undefined> v'no'
}

test cmdr-runtime-2.7 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    help = <undefined> v'no'
}

test cmdr-runtime-2.8 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3
} -result {
    A    = '1'         v'1'
    B    = '2 3'       v'2 3'
    help = <undefined> v'no'
}

test cmdr-runtime-2.9 {required + optional splat} -body {
    Parse {
	input A - { validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3 4
} -result {
    A    = '1'         v'1'
    B    = '2 3 4'     v'2 3 4'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.10 {optional + required splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
................................................................................

test cmdr-runtime-2.11 {optional + required splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1
} -result {
    A    = <undefined> v'0'
    B    = '1'         v'1'
    help = <undefined> v'no'
}
test cmdr-runtime-2.12 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    help = <undefined> v'no'
}

test cmdr-runtime-2.13 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2 3
} -result {
    A    = '1'         v'1'
    B    = '2 3'       v'2 3'
    help = <undefined> v'no'
}

test cmdr-runtime-2.14 {optional + required splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; validate integer }
    } 1 2 3 4
} -result {
    A    = '1'         v'1'
    B    = '2 3 4'     v'2 3 4'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-2.15 {optional + optional splat, not enough} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    }
} -result {
    A    = <undefined> v'0'
    B    = <undefined> v''
    help = <undefined> v'no'
}

test cmdr-runtime-2.16 {optional + optional splat, empty} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1
} -result {
    A    = '1'         v'1'
    B    = <undefined> v''
    help = <undefined> v'no'
}

test cmdr-runtime-2.17 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2
} -result {
    A    = '1'         v'1'
    B    = '2'         v'2'
    help = <undefined> v'no'
}

test cmdr-runtime-2.18 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3
} -result {
    A    = '1'         v'1'
    B    = '2 3'       v'2 3'
    help = <undefined> v'no'
}

test cmdr-runtime-2.19 {optional + optional splat} -body {
    Parse {
	input A - { optional ; validate integer }
	input B - { list ; optional ; validate integer }
    } 1 2 3 4
} -result {
    A    = '1'         v'1'
    B    = '2 3 4'     v'2 3 4'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################
## Group III: Options.

test cmdr-runtime-3.0 {options, simple, boolean} -body {
    Parse {
	option A -
    }
} -result {
    A    = <undefined> v'no'
    help = <undefined> v'no'
}

test cmdr-runtime-3.1 {options, simple, boolean} -body {
    Parse {
	option A -
    } -A 1
} -result {
    A    = '1'         v'1'
    help = <undefined> v'no'
}

test cmdr-runtime-3.2 {options, simple, boolean} -body {
    Parse {
	option A -
    } -A 0
} -result {
    A    = '0'         v'0'
    help = <undefined> v'no'
}

test cmdr-runtime-3.3 {options, simple, boolean, multiple use} -body {
    Parse {
	option A -
    } -A 0 -A 1
} -result {
    A    = '1'         v'1'
    help = <undefined> v'no'
}

test cmdr-runtime-3.4 {options, simple, boolean, special forms} -body {
    Parse {
	option A -
	option B -
	option C -
	option D -
	option E -
	option F -
	option G - { validate identity }
    } -A -G X --no-B -G X -C 1 -D 0 --no-E 1 --no-F 0
} -result {
    A    = 'yes'       v'1'
    B    = '0'         v'0'
    C    = '1'         v'1'
    D    = '0'         v'0'
    E    = '0'         v'0'
    F    = '1'         v'1'
    G    = 'X'         v'X'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.5 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    }
} -result {
    A    = <undefined> v''
    help = <undefined> v'no'
}

test cmdr-runtime-3.6 {options, list, string, missing value} -body {
    Parse {
	option A - { list ; validate identity }
    } -A
} -returnCodes error \
    -result "wrong\#args, missing value for option '-A'"

test cmdr-runtime-3.7 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    } -A X
} -result {
    A    = 'X'         v'X'
    help = <undefined> v'no'
}

test cmdr-runtime-3.8 {options, list, string} -body {
    Parse {
	option A - { list ; validate identity }
    } -A X -A Y
} -result {
    A    = 'X Y'       v'X Y'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.9 {options, aliases} -body {
    Parse {
	option A - { validate identity ; alias Z }
    } -A X -Z Y
} -result {
    A    = 'Y'         v'Y'
    help = <undefined> v'no'
}

test cmdr-runtime-3.10 {options, aliases, list} -body {
    Parse {
	option A - { list ; validate identity ; alias Z }
    } -A X -Z Y
} -result {
    A    = 'X Y'       v'X Y'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.11 {options, long names} -body {
    Parse {
	option ALPHA - { list ; validate identity }
    } --ALPHA Z
} -result {
    ALPHA = 'Z'         v'Z'
    help  = <undefined> v'no'
}

test cmdr-runtime-3.12 {options, unique prefix expansion} -body {
    Parse {
	option ALPHA - { list ; validate identity }
    } --AL Z
} -result {
    ALPHA = 'Z'         v'Z'
    help  = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-3.13 {options, unknown option} -body {
    Parse {
	option A - { validate identity }
    } -B Z
} -returnCodes error \
    -result {Unknown option -B}

test cmdr-runtime-3.14 {options, ambiguous prefix} -body {
    Parse {
	option ALPHA - { validate identity }
	option ALNUM - { validate identity }
    } --AL Z
} -returnCodes error \
    -result {Ambiguous option prefix --AL, matching --ALNUM, --ALPHA}

# NOTE: Test is brittle, dependent on the internal order in which the
# options are processed by UniquePrefixes.

test cmdr-runtime-3.15 {options, semi-ambiguous prefix (other option)} -body {
    Parse {
	option ALPHA - { validate identity }
	option AL    - { validate identity }
    } --AL Z
} -result {
    AL    = 'Z'         v'Z'
    ALPHA = <undefined> v''
    help  = <undefined> v'no'
}

# NOTE: Test is brittle, dependent on the internal order in which the
# options are processed by UniquePrefixes.

test cmdr-runtime-3.16 {options, semi-ambiguous prefix (other option)} -body {
    Parse {
	option AL-PHA - { validate identity }
	option AL     - { validate identity }
    } --AL Z --AL-PHA Y
} -result {
    AL     = 'Z'         v'Z'
    AL-PHA = 'Y'         v'Y'
    help   = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################
## Group IV: Mix options and arguments.

test cmdr-runtime-4.1 {options, arguments, and splat} -body {
    Parse {
................................................................................
	input  C - { optional ; validate identity ; list }
	option T - { validate identity }
    } A -T X C C C -T Y
    # The threshold method for optional arguments processes options
    # before arguments, handling the 2nd -T before splat collection.
    # Compare to 5.1.
} -result {
    A    = 'A'         v'A'
    C    = 'C C C'     v'C C C'
    help = <undefined> v'no'
    T    = 'Y'         v'Y'
}

# # ## ### ##### ######## ############# #####################
## Group V: Optional arguments, via peek+validate

test cmdr-runtime-5.1 {options, arguments, and splat, peek} -body {
    Parse {
................................................................................
    } A -T X C C C -T Y
    # The peek+validate method for optional arguments does not look
    # ahead beyond that, thus the 2nd -T becomes part of the splat
    # collection. Compare to 4.1. Note that the splat is _also_ put
    # into peek+validate mode, otherwise it would force the options to
    # be processed first.
} -result {
    A    = 'A'          v'A'
    C    = 'C C C -T Y' v'C C C -T Y'
    help = <undefined>  v'no'
    T    = 'X'          v'X'
}

# # ## ### ##### ######## ############# #####################
## Group VI: Introspect on the context of the generate, validate, and
##           when-complete command prefixes. Ensure that they are
##           called and work.

................................................................................
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    generate MATCH
    {} {    A    = <undefined> v'G'} {    help = <undefined> v'no'} {}
}

test cmdr-runtime-6.2 {validation, default supplication} -setup {
    StartNotes
    set ons A ; # Trigger parse to save the object namespace.
} -body {
    Note {*}[split [Parse {
................................................................................
	}
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    names = help
    validate default MATCH
    {} {    A    = <undefined> v'zZzZz'} {    help = <undefined> v'no'} {}
}

test cmdr-runtime-6.3 {generator command} -setup {
    StartNotes
    set ons A ; # Trigger parse to save the parameter object namespace.
} -body {
    Note {*}[split [Parse {
................................................................................
	}
    }] \n]
    string map [list $::ons MATCH] [Notes]
} -cleanup {
    unset ons
    StopNotes
} -result {
    names = {help A}
    defined = {}
    defined MATCH
    {} {    A    = <undefined> v''} {    help = <undefined> v'no'} {}
}

# # ## ### ##### ######## ############# #####################

test cmdr-runtime-7.1 {not-quite options, arguments} -body {
    Parse {
	input  A - { optional ; validate identity }
	option T - { validate identity }
    } -1 -T -3
    # The -1 looks like an option, but is for input A.
} -result {
    A    = '-1'        v'-1'
    help = <undefined> v'no'
    T    = '-3'        v'-3'
}

test cmdr-runtime-7.2 {validation errors} -body {
    ParseFailParse {
	input A - { validate integer }
	input B - { validate integer }
    } 1 X
................................................................................
	option C -
	option D -
	option E -
	option F -
	option G - { validate identity }
    } -A -G=X --no-B -G=X -C=1 -D=0 --no-E=1 --no-F=0
} -result {
    A    = 'yes'       v'1'
    B    = '0'         v'0'
    C    = '1'         v'1'
    D    = '0'         v'0'
    E    = '0'         v'0'
    F    = '1'         v'1'
    G    = 'X'         v'X'
    help = <undefined> v'no'
}

test cmdr-runtime-8.1 {options, boolean, aliases} -body {
    Parse {
	option A - { alias     X }
	option B - { neg-alias Y }
    } -X -Y
} -result {
    A    = 'yes'       v'1'
    B    = '0'         v'0'
    help = <undefined> v'no'
}

test cmdr-runtime-8.2 {options, boolean, aliases, special forms} -body {
    Parse {
	option A - { alias     X }
	option B - { neg-alias Y }
    } -X=0 -Y=0
} -result {
    A    = '0'         v'0'
    B    = '1'         v'1'
    help = <undefined> v'no'
}

# # ## ### ##### ######## ############# #####################

return