Skip to content

Commit

Permalink
describe: add contexts subcommand
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Chávarri <[email protected]>
  • Loading branch information
jchavarri committed Apr 8, 2024
1 parent 7a5395e commit ac73fa3
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/describe/describe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let subcommands =
; Aliases_targets.Aliases_cmd.command
; Package_entries.command
; Describe_pkg.command
; Describe_contexts.command
]
;;

Expand Down
23 changes: 23 additions & 0 deletions bin/describe/describe_contexts.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open Import

let term =
let+ builder = Common.Builder.term in
let common, config = Common.init builder in
Scheduler.go ~common ~config
@@ fun () ->
let open Fiber.O in
let* setup = Import.Main.setup () in
let+ setup = Memo.run setup in
let ctxts =
List.map
~f:(fun (name, _) -> Context_name.to_string name)
(Context_name.Map.to_list setup.scontexts)
in
List.iter ctxts ~f:print_endline
;;

let command =
let doc = "prints information about the available Dune contexts." in
let info = Cmd.info ~doc "contexts" in
Cmd.v info term
;;
4 changes: 4 additions & 0 deletions bin/describe/describe_contexts.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
open Import

(** Dune command to print out the defined Dune contexts.*)
val command : unit Cmd.t
19 changes: 19 additions & 0 deletions test/blackbox-tests/test-cases/describe/describe-contexts.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Showcase behavior of the `dune describe contexts` subcommand

$ cat >dune-project <<EOF
> (lang dune 3.14)
> EOF

$ cat > dune-workspace << EOF
> (lang dune 3.14)
>
> (context default)
>
> (context
> (default
> (name alt)))
> EOF

$ dune describe contexts
alt
default

0 comments on commit ac73fa3

Please sign in to comment.