cmdr
Check-in [307a15e657]
Not logged in

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

Overview
Comment:And more vtypes: positive ints, years, and weekdays
Timelines: family | ancestors | descendants | both | more-vtypes
Files: files | file ages | folders
SHA1:307a15e657abb079c3d130d4d6059032676874d9
User & Date: aku 2015-03-06 19:14:12
Context
2015-03-10
03:01
Got fix for history check-in: a94ac7b701 user: aku tags: more-vtypes
2015-03-06
19:14
And more vtypes: positive ints, years, and weekdays check-in: 307a15e657 user: aku tags: more-vtypes
19:13
fixes (defaults, metadata) and extensions (2external) for date/time check-in: d993d2bda7 user: aku tags: more-vtypes
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added vt_posint.tcl.



























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## CMDR - Validate::Posint - Supporting validation type - positive integers (> 0)

# @@ Meta Begin
# Package cmdr::validate::posint 1
# Meta author   {Andreas Kupries}
# Meta location https://core.tcl.tk/akupries/cmdr
# Meta platform tcl
# Meta summary     Standard parameter validation type for positive ints > 0
# Meta description Standard parameter validation type for positive ints > 0
# Meta subject {command line}
# Meta require {Tcl 8.5-}
# Meta require {cmdr::validate::common 1.2}
# Meta require debug
# Meta require debug::caller
# Meta require try
# @@ Meta End

# # ## ### ##### ######## ############# #####################
## Requisites

package require Tcl 8.5
package require cmdr::validate::common 1.2
package require debug
package require debug::caller
package require try

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

namespace eval ::cmdr {
    namespace export validate
    namespace ensemble create
}
namespace eval ::cmdr::validate {
    namespace export posint
    namespace ensemble create
}
namespace eval ::cmdr::validate::posint {
    namespace export default validate complete release
    namespace ensemble create

    namespace import ::cmdr::validate::common::fail
}

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

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

# # ## ### ##### ######## ############# #####################
## Posints as parsed by clock::iso86

proc ::cmdr::validate::posint::release  {p x} { return }
proc ::cmdr::validate::posint::default  {p}  { return 1 }
proc ::cmdr::validate::posint::complete {p x} {
    debug.cmdr/validate/posint {} 10
    # No completion
    return {}
}
proc ::cmdr::validate::posint::validate {p x} {
    debug.cmdr/validate/posint {}
    # While we accept integers in octal and hex we convert them into
    # proper decimals for internal use, as our standard
    # representation.
    if {[string is integer -strict $x] && ($x > 0)} {
	return [format %d $x]
    }
    fail $p INTEGER "a positive integer" $x
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::posint 1
return

Added vt_weekday.tcl.

































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## CMDR - Validate::Weekday - Supporting validation type - iso weekdays.

# @@ Meta Begin
# Package cmdr::validate::weekday 1
# Meta author   {Andreas Kupries}
# Meta location https://core.tcl.tk/akupries/cmdr
# Meta platform tcl
# Meta summary     Standard parameter validation type for weekdays
# Meta description Standard parameter validation type for weekdays
# Meta subject {command line}
# Meta require {Tcl 8.5-}
# Meta require {cmdr::validate::common 1.2}
# Meta require debug
# Meta require debug::caller
# Meta require try
# @@ Meta End

# # ## ### ##### ######## ############# #####################
## Requisites

package require Tcl 8.5
package require cmdr::validate::common 1.2
package require debug
package require debug::caller
package require try

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

namespace eval ::cmdr {
    namespace export validate
    namespace ensemble create
}
namespace eval ::cmdr::validate {
    namespace export weekday
    namespace ensemble create
}
namespace eval ::cmdr::validate::weekday {
    namespace export default validate complete release 2external
    namespace ensemble create

    namespace import ::cmdr::validate::common::fail
}

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

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

# # ## ### ##### ######## ############# #####################
## Weekdays as parsed by clock::iso86

proc ::cmdr::validate::weekday::2external {x}  {
    debug.cmdr/validate/weekday {}
    return [clock format [clock scan $x -format %u] -format {%A}]
}

proc ::cmdr::validate::weekday::release  {p x} { return }
proc ::cmdr::validate::weekday::default  {p}  {
    debug.cmdr/validate/weekday {}
    # Weekday of today.
    return [clock format [clock seconds] -format %u]
}
proc ::cmdr::validate::weekday::complete {p x} {
    debug.cmdr/validate/weekday {} 10
    # No completion (too many possible inputs (across the locales))
    return {}
}
proc ::cmdr::validate::weekday::validate {p x} {
    debug.cmdr/validate/weekday {}
    # Accept short and long weekday names, and weekday numbers 0-7.
    # Sunday can be either 0, or 7.

    set xa [string tolower $x]
    foreach pattern {%A %a %u %w} {
	try {
	    set epoch [clock scan $xa -format $pattern]
	} trap {CLOCK badInputString} {e o} {
	    continue
	} on ok {e o} {
	    # We have an epoch value.
	    # Format it back to a numeric weekday (1->monday, 7->sunday).
	    # (iso8601)
	    return [clock format $epoch -format %u]
	}
    }
    fail $p WEEKDAY "a weekday" $x
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::weekday 1
return

Added vt_year.tcl.



















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
## -*- tcl -*-
# # ## ### ##### ######## ############# #####################
## CMDR - Validate::Year - Supporting validation type - iso years.

# @@ Meta Begin
# Package cmdr::validate::year 1
# Meta author   {Andreas Kupries}
# Meta location https://core.tcl.tk/akupries/cmdr
# Meta platform tcl
# Meta summary     Standard parameter validation type for years
# Meta description Standard parameter validation type for years
# Meta subject {command line}
# Meta require {Tcl 8.5-}
# Meta require {cmdr::validate::common 1.2}
# Meta require debug
# Meta require debug::caller
# Meta require try
# @@ Meta End

# # ## ### ##### ######## ############# #####################
## Requisites

package require Tcl 8.5
package require cmdr::validate::common 1.2
package require debug
package require debug::caller
package require try

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

namespace eval ::cmdr {
    namespace export validate
    namespace ensemble create
}
namespace eval ::cmdr::validate {
    namespace export year
    namespace ensemble create
}
namespace eval ::cmdr::validate::year {
    namespace export default validate complete release
    namespace ensemble create

    namespace import ::cmdr::validate::common::fail
}

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

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

# # ## ### ##### ######## ############# #####################
## Years as parsed by clock::iso86

proc ::cmdr::validate::year::release  {p x} { return }
proc ::cmdr::validate::year::default  {p}  {
    debug.cmdr/validate/year {}
    # Year of today.
    return [clock format [clock seconds] -format %Y]
}
proc ::cmdr::validate::year::complete {p x} {
    debug.cmdr/validate/year {} 10
    # No completion (too many possible inputs (across the locales))
    return {}
}
proc ::cmdr::validate::year::validate {p x} {
    debug.cmdr/validate/year {}
    # Accept short and long year numbers

    set xa [string tolower $x]
    foreach pattern {%Y %y} {
	try {
	    set epoch [clock scan $xa -format $pattern]
	} trap {CLOCK badInputString} {e o} {
	    continue
	} on ok {e o} {
	    # We have an epoch value.
	    # Format it back to a full numeric year
	    return [clock format $epoch -format %Y]
	}
    }
    fail $p YEAR "a year" $x
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::year 1
return