diff --git a/CHANGES.md b/CHANGES.md index b150ee1..41a41d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,10 @@ - API: `Contributions.of_json` parameter `~from` is replaced by `~period` (#31, @gpetiot) +### Added + +- Display curl requests and responses in debug mode (`-vv` or `--verbosity debug`) (#36, @gpetiot) + ## 1.0.1 ### Fixed diff --git a/bin/dune b/bin/dune index 7f8fa6e..9506f36 100644 --- a/bin/dune +++ b/bin/dune @@ -2,4 +2,11 @@ (name main) (public_name get-activity) (package get-activity) - (libraries cmdliner dune-build-info get-activity-lib)) + (libraries + cmdliner + dune-build-info + get-activity-lib + logs.cli + logs.fmt + fmt.cli + fmt.tty)) diff --git a/bin/main.ml b/bin/main.ml index 87288da..f0c1efb 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -43,6 +43,15 @@ let mode = `Normal open Cmdliner +let setup_log style_renderer level = + Fmt_tty.setup_std_outputs ?style_renderer (); + Logs.set_level level; + Logs.set_reporter (Logs_fmt.reporter ()); + () + +let setup_log = + Term.(const setup_log $ Fmt_cli.style_renderer () $ Logs_cli.level ()) + let from = let doc = Arg.info ~docv:"TIMESTAMP" ~doc:"Starting date (ISO8601)." [ "from" ] @@ -88,11 +97,10 @@ let version = let info = Cmd.info "get-activity" ~version -let run period user : unit = +let run () period user : unit = match mode with | `Normal -> Period.with_period period ~last_fetch_file ~f:(fun period -> - (* Fmt.pr "period: %a@." Fmt.(pair string string) period; *) let* token = get_token () in let request = Contributions.request ~period ~user ~token in let* contributions = Graphql.exec request in @@ -112,6 +120,6 @@ let run period user : unit = in show ~period ~user @@ Yojson.Safe.from_file "activity.json" -let term = Term.(const run $ term_result period $ user) +let term = Term.(const run $ setup_log $ term_result period $ user) let cmd = Cmd.v info term let () = Stdlib.exit @@ Cmd.eval cmd diff --git a/dune-project b/dune-project index 7e7f63c..eb45f87 100644 --- a/dune-project +++ b/dune-project @@ -1,17 +1,27 @@ (lang dune 2.8) + (name get-activity) + (generate_opam_files true) -(source (github tarides/get-activity)) + +(source + (github tarides/get-activity)) + (authors "talex5@gmail.com") + (maintainers "Guillaume Petiot ") (package (name get-activity) (synopsis "Collect activity as markdown") (depends - (cmdliner (>= 1.1.1)) + (cmdliner + (>= 1.1.1)) dune-build-info - (get-activity-lib (= :version)))) + fmt + logs + (get-activity-lib + (= :version)))) (package (name get-activity-lib) @@ -21,7 +31,11 @@ (ppx_expect :with-test) astring curly - (fmt (>= 0.8.7)) + (fmt + (>= 0.8.7)) + logs ppx_yojson_conv - (yojson (>= 1.6)) - (ocaml (>= 4.08)))) + (yojson + (>= 1.6)) + (ocaml + (>= 4.08)))) diff --git a/get-activity-lib.opam b/get-activity-lib.opam index 9a58268..0c5207c 100644 --- a/get-activity-lib.opam +++ b/get-activity-lib.opam @@ -12,6 +12,7 @@ depends: [ "astring" "curly" "fmt" {>= "0.8.7"} + "logs" "ppx_yojson_conv" "yojson" {>= "1.6"} "ocaml" {>= "4.08"} diff --git a/get-activity.opam b/get-activity.opam index 45496bd..74200fa 100644 --- a/get-activity.opam +++ b/get-activity.opam @@ -9,6 +9,8 @@ depends: [ "dune" {>= "2.8"} "cmdliner" {>= "1.1.1"} "dune-build-info" + "fmt" + "logs" "get-activity-lib" {= version} "odoc" {with-doc} ] diff --git a/lib/dune b/lib/dune index 921b990..d96d5c4 100644 --- a/lib/dune +++ b/lib/dune @@ -1,6 +1,6 @@ (library (name get_activity) (public_name get-activity-lib) - (libraries astring curly fmt yojson) + (libraries astring curly fmt logs yojson) (preprocess (pps ppx_yojson_conv))) diff --git a/lib/graphql.ml b/lib/graphql.ml index af5a7b8..9b95795 100644 --- a/lib/graphql.ml +++ b/lib/graphql.ml @@ -24,8 +24,10 @@ let exec request = let { meth; url; headers; body } = request in let body = Yojson.Safe.to_string body in let request = Curly.Request.make ~headers ~body ~url ~meth () in + Logs.debug (fun m -> m "request: @[%a@]@." Curly.Request.pp request); match Curly.run request with - | Ok { Curly.Response.body; _ } -> ( + | Ok ({ Curly.Response.body; _ } as response) -> ( + Logs.debug (fun m -> m "response: @[%a@]@." Curly.Response.pp response); let json = Yojson.Safe.from_string body in match json / "message" with | `Null -> Ok json