···4343 | Set of set
4444 | Wait of int
4545 | Dot of string (* a.k.a source *)
4646+ | Unset of [ `Variables of string list | `Functions of string list ]
46474748(* Change Directory *)
4849module Cd = struct
···131132 Cmd.v info term
132133end
133134135135+module Unset = struct
136136+ open Cmdliner
137137+138138+ let names =
139139+ let doc = "Names of variables or functions to remove." in
140140+ Arg.(value & pos_all string [] & info [] ~docv:"NAMES" ~doc)
141141+142142+ let kind =
143143+ let func =
144144+ let doc = "Names refer to functions to be removed." in
145145+ Arg.(info [ "f" ] ~docv:"FUNCTION" ~doc)
146146+ in
147147+ let vari =
148148+ let doc = "Names refer to variables to be removed." in
149149+ Arg.(info [ "v" ] ~docv:"VARIABLE" ~doc)
150150+ in
151151+ Arg.(value & vflag `Variable [ (`Function, func); (`Variable, vari) ])
152152+153153+ let t =
154154+ let make_unset kind n =
155155+ let names =
156156+ match kind with `Variable -> `Variables n | `Function -> `Functions n
157157+ in
158158+ Unset names
159159+ in
160160+ let term = Term.(const make_unset $ kind $ names) in
161161+ let info =
162162+ let doc = "Wait for a particular PID (default is 0)" in
163163+ Cmd.info "wait" ~doc
164164+ in
165165+ Cmd.v info term
166166+end
167167+134168module Make_dot (T : sig
135169 val name : string
136170end) =
···177211 | "wait" :: _ as cmd -> exec_cmd cmd Wait.t
178212 | "source" :: _ as cmd -> exec_cmd cmd Source.t
179213 | "." :: _ as cmd -> exec_cmd cmd Dot.t
214214+ | "unset" :: _ as cmd -> exec_cmd cmd Unset.t
180215 | _ -> None
+1
src/lib/built_ins.mli
···2020 | Set of set
2121 | Wait of int
2222 | Dot of string
2323+ | Unset of [ `Variables of string list | `Functions of string list ]
23242425val of_args : string list -> (t, string) result option
2526(** Parses a command-line to the built-ins, errors are returned if parsing. *)
+16
src/lib/eval.ml
···744744 let program = Ast.of_file (ctx.fs / f) in
745745 let ctx, _ = run (Exit.zero ctx) program in
746746 ctx)
747747+ | Unset names -> (
748748+ match names with
749749+ | `Variables names ->
750750+ let state =
751751+ List.fold_left
752752+ (fun t param -> S.remove ~param t |> snd)
753753+ ctx.state names
754754+ in
755755+ Exit.zero { ctx with state }
756756+ | `Functions names ->
757757+ let functions =
758758+ List.fold_left
759759+ (fun t param -> List.remove_assoc param t)
760760+ ctx.functions names
761761+ in
762762+ Exit.zero { ctx with functions })
747763748764 and exec initial_ctx ((command, sep) : Ast.complete_command) =
749765 let rec loop : Eio.Switch.t -> ctx -> Ast.clist -> ctx Exit.t =
+5
src/lib/posix/state.ml
···2222 let variables' = Variables.add param (export, v) t.variables in
2323 { t with variables = variables' }
24242525+let remove ~param t =
2626+ match Variables.find_opt param t.variables with
2727+ | None -> (false, t)
2828+ | Some _ -> (true, { t with variables = Variables.remove param t.variables })
2929+2530let exports t =
2631 Variables.to_list t.variables
2732 |> List.filter_map (function p, (true, v) -> Some (p, v) | _ -> None)
+4
src/lib/types.ml
···2727 (** Update the state with a new parameter mapping and whether or not it should
2828 exported to the environment (default false). *)
29293030+ val remove : param:string -> t -> bool * t
3131+ (** [remove ~param t] removes [param] from [t] if it exists. [bool] is [true]
3232+ if a removal took place. *)
3333+3034 val exports : t -> (string * Ast.word_cst) list
3135 (** All of the variables that must be exported to the environment *)
3236