]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/cal/cal.factor
Switch to https urls
[factor.git] / extra / tools / cal / cal.factor
1 ! Copyright (C) 2016 John Benediktsson
2 ! See https://factorcode.org/license.txt for BSD license
3 USING: accessors calendar calendar.format combinators
4 command-line kernel math.parser namespaces sequences
5 sequences.extras ;
6 IN: tools.cal
7
8 : cal-args ( -- timestamp year? )
9     now command-line get [
10         f
11     ] [
12         dup first {
13             { "-m" [ rest ?first2 swap f ] }
14             { "-y" [ rest ?first2 dup [ swap ] when t ] }
15             [ drop ?first2 dup [ swap ] when dup not ]
16         } case [
17             [ string>number ] bi@
18             [ [ >>year ] when* ]
19             [ [ >>month ] when* ] bi*
20         ] dip
21     ] if-empty ;
22
23 : run-cal ( -- )
24     cal-args [ year. ] [ month. ] if ;
25
26 MAIN: run-cal