Skip to content

Commit

Permalink
just: replace make, update targets, format, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mor1 committed Jan 16, 2025
1 parent 6bb1296 commit 8ef8631
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 232 deletions.
Empty file added .ocamlformat
Empty file.
60 changes: 60 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SPDX-FileCopyrightText: 2024 Richard Mortier <[email protected]>
#
# SPDX-License-Identifier: ISC

_default:
@just --list

PWD := env("PWD")
DOCDIR := "_build/default/_doc/_html"
BUILDDIR := "_build/install/default/bin"
TARGET := "ocal"

# build targets
build:
dune build @all

# cleanup
clean:
dune clean

# install targets
install: build
dune build @install
ln -sf {{PWD}}/{{BUILDDIR}}/{{TARGET}} ~/.local/bin/

# uninstall targets
uninstall:
dune uninstall

# run any tests
test:
dune runtest

# format sources
format:
dune fmt

# lint everything
lint:
dune build @lint
dune-release lint

# build docs
doc:
dune build @doc
dune build @doc-private

# open the docs for reading
read: doc
handlr open {{DOCDIR}}/index.html || open {{DOCDIR}}

# tag and create a release
release:
dune-release tag
dune-release -vv

# install dependencies
depends:
opam install --yes dune-release odoc
opam install --yes . --deps-only
File renamed without changes.
23 changes: 19 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
;;; SPDX-FileCopyrightText: 2024 Richard Mortier <[email protected]>
;;;
;;; SPDX-License-Identifier: ISC
(lang dune 3.17)

(lang dune 1.0)
(name ocal)

(generate_opam_files true)

(source
(github mor1/ocal))

(authors "Richard Mortier <[email protected]>")

(maintainers "Richard Mortier <[email protected]>")

(license MIT)

(package
(name ocal)
(synopsis "An improved UNIX `cal` utility")
(description "Replace `cal` because I could and because I find the CLI irritating")
(tags
()))
51 changes: 24 additions & 27 deletions ocal.opam
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
maintainer: "Richard Mortier <[email protected]>"
authors: [ "Richard Mortier" ]
license: "ISC"

synopsis: "An improved UNIX `cal` utility"
description:
"Replace `cal` because I could and because I find the CLI irritating"
maintainer: ["Richard Mortier <[email protected]>"]
authors: ["Richard Mortier <[email protected]>"]
license: "MIT"
homepage: "https://github.com/mor1/ocal"
dev-repo: "git+https://github.com/mor1/ocal.git"
bug-reports: "https://github.com/mor1/ocal/issues"
doc: "https://mor1.github.io/ocal/"

build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]

depends: [
"astring" {build}
"calendar" {build}
"cmdliner" {build}
"dune" {build}
"notty" {build & >="0.2.0"}
"ocaml" {build & >="4.02.3"}
"dune" {>= "3.17"}
"odoc" {with-doc}
]

synopsis: "An improved Unix `cal` utility"

description: """
`ocal` is a replacement for the standard Unix `cal` utility.
Partly because I could, partly because I'd become too irritated with its command
line interface.
"""
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/mor1/ocal.git"
12 changes: 5 additions & 7 deletions pkg/pkg.ml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
#!/usr/bin/env ocaml

(*
* SPDX-FileCopyrightText: 2024 Richard Mortier <[email protected]>
*
* SPDX-License-Identifier: ISC
*)

#!/usr/bin/env ocaml
#use "topfind"

#require "topkg-jbuilder"

open Topkg

let publish =
Pkg.publish ~artefacts:[`Distrib] ()

let () =
Topkg_jbuilder.describe ~publish ()
let publish = Pkg.publish ~artefacts:[ `Distrib ] ()
let () = Topkg_jbuilder.describe ~publish ()
15 changes: 6 additions & 9 deletions src/days.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
open CalendarLib

let of_week firstday =
let days = Date.([| Mon; Tue; Wed; Thu; Fri; Sat; Sun;
Mon; Tue; Wed; Thu; Fri; Sat; Sun
|])
let days =
Date.
[| Mon; Tue; Wed; Thu; Fri; Sat; Sun; Mon; Tue; Wed; Thu; Fri; Sat; Sun |]
in
let find x =
let rec aux a x n = if a.(n) = x then n else aux a x (n+1) in
let rec aux a x n = if a.(n) = x then n else aux a x (n + 1) in
aux days x 0
in

Array.sub days (find firstday) 7
|> Array.to_list
Array.sub days (find firstday) 7 |> Array.to_list

let of_month monthyear =
let length = Date.days_in_month monthyear in
let rec aux a b =
if a > b then [] else a :: aux (a+1) b
in
let rec aux a b = if a > b then [] else a :: aux (a + 1) b in
aux 1 length
19 changes: 6 additions & 13 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
;;; SPDX-License-Identifier: ISC

(executable
(public_name ocal)
(package ocal)
(name main)

(libraries
astring
calendar
cmdliner
notty
notty.unix
)
(flags (:standard -w "A-44-48-52" -safe-string))
)
(public_name ocal)
(package ocal)
(name main)
(libraries astring calendar cmdliner notty notty.unix)
(flags
(:standard -w "A-44-48-52" -safe-string)))
93 changes: 43 additions & 50 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,81 @@ let () = Time_Zone.(change Local)
let today =
let date =
let parse date =
try
`Ok (Printer.Date.from_fstring "%d%b%Y" date)
with
| Invalid_argument _ ->
`Error ("invalid date string: " ^ date)
try `Ok (Printer.Date.from_fstring "%d%b%Y" date)
with Invalid_argument _ -> `Error ("invalid date string: " ^ date)
in
parse, fun ppf p -> Format.fprintf ppf "%s" (Printer.Date.to_string p)
(parse, fun ppf p -> Format.fprintf ppf "%s" (Printer.Date.to_string p))
in
let doc = "Set today's date." in
Arg.(value & opt date (Date.today ())
& info ["t"; "today"] ~docv:"ddMmmyyyy" ~doc)
Arg.(
value
& opt date (Date.today ())
& info [ "t"; "today" ] ~docv:"ddMmmyyyy" ~doc)

let ncols =
let doc = "Format across $(docv) columns." in
Arg.(value & opt int 3 & info ["c"; "columns"] ~docv:"N" ~doc)
Arg.(value & opt int 3 & info [ "c"; "columns" ] ~docv:"N" ~doc)

let sep =
let doc = "Format using $(docv) as month separator." in
Arg.(value & opt string " " & info ["s"; "separator"] ~docv:"sep" ~doc)
Arg.(value & opt string " " & info [ "s"; "separator" ] ~docv:"sep" ~doc)

let weeks_of_year =
let doc = "Don't display weeks of year." in
Arg.(value & flag & info ["w"; "weeks"] ~doc)
Arg.(value & flag & info [ "w"; "weeks" ] ~doc)

let first_dow =
let aux =
let parse day =
try
`Ok (day |> String.Ascii.capitalize |> Day.of_string)
with
| Invalid_argument s -> `Error s
try `Ok (day |> String.Ascii.capitalize |> Day.of_string)
with Invalid_argument s -> `Error s
in
parse, fun ppf p -> Format.fprintf ppf "%s" (Printer.short_name_of_day p)
(parse, fun ppf p -> Format.fprintf ppf "%s" (Printer.short_name_of_day p))
in
let doc = "Format with $(docv) as first day-of-week." in
Arg.(value & opt aux (Date.Mon) & info ["f"; "first_dow"] ~docv:"ddd" ~doc)
Arg.(value & opt aux Date.Mon & info [ "f"; "first_dow" ] ~docv:"ddd" ~doc)

let plain =
let doc = "Turn off highlighting." in
Arg.(value & flag & info ["p"; "plain"] ~doc)
Arg.(value & flag & info [ "p"; "plain" ] ~doc)

let range =
let doc = "$(docv) are specified as:\n\
\ $(i,mmm) (month $(i,mmm));\n\
\ $(i,yyyy) (year $(i,yyyy));\n\
\ $(i,mmmyyyy) (month $(i,mmm), year $(i,yyyy));\n\
\ $(i,d1-d2) (all months in the range $(i,d1-d2)).\
"
let doc =
"$(docv) are specified as:\n\
\ $(i,mmm) (month $(i,mmm));\n\
\ $(i,yyyy) (year $(i,yyyy));\n\
\ $(i,mmmyyyy) (month $(i,mmm), year $(i,yyyy));\n\
\ $(i,d1-d2) (all months in the range $(i,d1-d2))."
in
let thismonth = Printer.Date.sprint "%b%Y" (Date.today ()) in
Arg.(value & pos 0 string thismonth & info [] ~docv:"DATES" ~doc)

let cmd =
let doc = "pretty print calendar months" in
let man = [
`S "DESCRIPTION";
`P "$(tname) -- pretty prints specified monthly calendars.";

`S "SEE ALSO";
`P "cal(1), ncal(1), calendar(3), strftime(3)";

`S "HISTORY";
`P "\
An alternative to\
\ https://github.com/mor1/python-scripts/blob/master/cal.py because I got\
\ tired of the startup time. The Python version was written because I got\
\ tired of the CLI.";

`S "AUTHORS";
`P "%%PKG_AUTHORS%%";

`S "BUGS";
`P "Report bugs at %%PKG_ISSUES%%";
]
let man =
[
`S "DESCRIPTION";
`P "$(tname) -- pretty prints specified monthly calendars.";
`S "SEE ALSO";
`P "cal(1), ncal(1), calendar(3), strftime(3)";
`S "HISTORY";
`P
"An alternative to \
https://github.com/mor1/python-scripts/blob/master/cal.py because I \
got tired of the startup time. The Python version was written because \
I got tired of the CLI.";
`S "AUTHORS";
`P "%%PKG_AUTHORS%%";
`S "BUGS";
`P "Report bugs at %%PKG_ISSUES%%";
]
in
let info = Cmd.info "ocal" ~version:"%%VERSION%%" ~doc ~man in
Cmd.v info Term.(
const Ocal.cal
$ plain $ weeks_of_year $ today $ ncols $ sep $ first_dow $ range
)
Cmd.v info
Term.(
const Ocal.cal $ plain $ weeks_of_year $ today $ ncols $ sep $ first_dow
$ range)

(* go! *)

let () =
exit (Cmd.eval cmd)
let () = exit (Cmd.eval cmd)
Loading

0 comments on commit 8ef8631

Please sign in to comment.