Source file bash.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
(******************************************************************************)
(*  Copyright 2023 Gurvan Debaussart                                          *)
(*  This file is distributed under the MIT license.                           *)
(*  https://codeberg.org/gurvan/argsh                                         *)
(******************************************************************************)

open Common
open Format

let create out executable_name args =

  let args_to_opt (key, _, _) = key in

  let args =  add_help args
           |> List.map args_to_opt
           |> String.concat " \\\n    "
  in

  let up_exec_name = String.uppercase_ascii executable_name in

  fprintf out
{|# %s

%s_OPTIONS="%s"
complete -W \"$%s_OPTIONS\" -f %s|}
  msg up_exec_name args up_exec_name executable_name