Skip to content

Commit faee2e4

Browse files
committed
feat: Add --force/-f flag to force experimental features
1 parent a911ce5 commit faee2e4

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

bin/main.ml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@ open Ns
22
open Ns.Cmd
33
open Ns.Util
44

5-
let main ({ installables; target_info; printcmd } : Cli.strategy) =
5+
let main
6+
({ installables; target_info; printcmd; force_experimental_features } :
7+
Cli.strategy)
8+
=
69
let ({ entrypoint; attribute; subshell_dir } : Cli.target_info) = target_info in
710
Option.value ~default:(Option.value ~default:(Sys.getcwd ()) entrypoint) subshell_dir
811
|> Unix.cd;
912
let cmd =
10-
match entrypoint with
11-
| Some entrypoint ->
12-
(match Unix.flake_exists_at entrypoint with
13-
| true ->
14-
Cmd.builder "nix"
15-
|>+ [ "develop" ] @ [ Uri.sprintf_uri_attr_opt entrypoint attribute ]
16-
| false ->
17-
(match Unix.shell_exists_at entrypoint with
18-
| true ->
19-
Cmd.builder "nix-shell"
20-
|>+ Option.value
21-
~default:[]
22-
(Option.map (fun attr -> [ "--attr"; attr ]) attribute)
23-
|>+ [ entrypoint ]
24-
| false ->
25-
Error.handle_ns_error "no available devshell entrypoint: %s\n%!" entrypoint))
26-
|>+ [ "--command"; Unix.shell ]
27-
| None -> Cmd.builder "nix" |>+ [ "shell" ] |>+ installables
13+
(match entrypoint with
14+
| Some entrypoint ->
15+
(match Unix.flake_exists_at entrypoint with
16+
| true ->
17+
Cmd.builder "nix"
18+
|>+ [ "develop" ] @ [ Uri.sprintf_uri_attr_opt entrypoint attribute ]
19+
| false ->
20+
(match Unix.shell_exists_at entrypoint with
21+
| true ->
22+
Cmd.builder "nix-shell"
23+
|>+ Option.value
24+
~default:[]
25+
(Option.map (fun attr -> [ "--attr"; attr ]) attribute)
26+
|>+ [ entrypoint ]
27+
| false ->
28+
Error.handle_ns_error "no available devshell entrypoint: %s\n%!" entrypoint))
29+
|>+ [ "--command"; Unix.shell ]
30+
| None -> Cmd.builder "nix" |>+ [ "shell" ] |>+ installables)
31+
|>+ Option.value ~default:[] force_experimental_features
2832
in
2933
if printcmd then print_endline (Cmd.to_string cmd) else ignore (Cmd.run cmd)
3034
;;

lib/cli.ml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module Cli = struct
1818
{ installables : string list
1919
; target_info : target_info
2020
; printcmd : bool
21+
; force_experimental_features : string list option
2122
}
2223

2324
(** Positional URI arguments passed to the program via the command line. *)
@@ -28,9 +29,14 @@ module Cli = struct
2829
Arg.(value & flag & info [ "printcmd" ] ~doc)
2930
;;
3031

32+
let force_experimental_features =
33+
let doc = "Force the use of flakes and nix-command experimental features." in
34+
Arg.(value & flag & info [ "force"; "f" ] ~doc)
35+
;;
36+
3137
(** Processes the args so that the main function knows what to do with them. *)
3238
let make_strategy =
33-
let build original_args printcmd =
39+
let build original_args printcmd force_experimental_features =
3440
let installables, target_info =
3541
let default_installables = []
3642
and default_target =
@@ -87,9 +93,22 @@ module Cli = struct
8793
, { entrypoint = None; attribute = None; subshell_dir = Some subshell_dir } )
8894
| _ -> Uri.parse_targets_tr original_args, default_target)
8995
in
90-
{ installables; target_info; printcmd }
96+
{ installables
97+
; target_info
98+
; printcmd
99+
; force_experimental_features =
100+
(if force_experimental_features
101+
then
102+
Some
103+
[ "--extra-experimental-features"
104+
; "flakes"
105+
; "--extra-experimental-features"
106+
; "nix-command"
107+
]
108+
else None)
109+
}
91110
in
92-
Term.(const build $ uris $ printcmd)
111+
Term.(const build $ uris $ printcmd $ force_experimental_features)
93112
;;
94113

95114
let cmd entrypoint =

0 commit comments

Comments
 (0)