File: sample.ml

package info (click to toggle)
ocaml-getopt 0.0.20040811-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 88 kB
  • ctags: 36
  • sloc: ml: 116; makefile: 43
file content (34 lines) | stat: -rw-r--r-- 949 bytes parent folder | download | duplicates (6)
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
27
28
29
30
31
32
33
34
(* Demonstration of the Getopt module *)

open Getopt

let archive = ref false
and update  = ref false
and verbose = ref 0
and includ  = ref []
and output  = ref ""

let bip ()  = Printf.printf "\007"; flush stdout
let wait () = Unix.sleep 1 

let specs = 
[
  ( 'x', "execute", None, Some (fun x -> Printf.printf "execute %s\n" x));
  ( 'I', "include", None, (append includ));
  ( 'o', "output",  None, (atmost_once output (Error "only one output")));
  ( 'a', "archive", (set archive true), None);
  ( 'u', "update",  (set update  true), None);
  ( 'v', "verbose", (incr verbose), None);
  ( 'X', "",        Some bip, None);
  ( 'w', "wait",    Some wait, None)

]

let _ = 
  parse_cmdline specs print_endline;

  Printf.printf "archive = %b\n" !archive;
  Printf.printf "update  = %b\n" !update;
  Printf.printf "verbose = %i\n" !verbose;
  Printf.printf "output  = %s\n" !output;
  List.iter (fun x -> Printf.printf "include %s\n" x) !includ;;