basic cli parsing

This commit is contained in:
2024-08-18 03:49:34 +07:00
commit 6328b43957
11 changed files with 127 additions and 0 deletions

10
bin/detect.ml Normal file
View File

@ -0,0 +1,10 @@
(** detection module
detect a given file for formats or ISA
*)
open Printf
let runner isa file =
printf "Detect file isa=%b %s\n" isa file

6
bin/dune Normal file
View File

@ -0,0 +1,6 @@
(env (dev (flags :standard -warn-error -27-32)))
(executable
(public_name firmex)
(name main)
(libraries firmex cmdliner))

4
bin/extract.ml Normal file
View File

@ -0,0 +1,4 @@
open Printf
let runner dry file =
printf "Extract file dry=%b %s\n" dry file

32
bin/main.ml Normal file
View File

@ -0,0 +1,32 @@
(** Firmware extractor
1. Verify if the file is a welknown archive format
2. Checking internal bytes for common filesystem
3. Recursive
Some files might require different approach
Common archive file formats are ZIP XZ TAR
Common filesystem are SQUASHFS JIFFS
*)
open Cmdliner
let extract =
let info = Cmd.info "extract" ~doc:"Extract the file." in
let dry = Arg.(value & opt bool false & info ["d"; "dry"] ~docv:"false" ~doc:"Dry run") in
let file = Arg.(required & pos 0 (some string) None & info [] ~docv:"FILE") in
Cmd.v info Term.(const Extract.runner $ dry $ file)
let detect =
let info = Cmd.info "detect" ~doc:"Detect the file type and its internal contents." in
let isa = Arg.(value & opt bool false & info ["isa"] ~docv:"false" ~doc:"Detect Instruction Set Architecture") in
let file = Arg.(required & pos 0 (some string) None & info [] ~docv:"FILE") in
Cmd.v info Term.(const Detect.runner $ isa $ file)
let cmd =
let info = Cmd.info "firmex group" ~version:"0.0.0-alpha" in
Cmd.group info [extract; detect;]
let () = exit (Cmd.eval cmd)