Skip to content

Commit bac4825

Browse files
authored
Merge pull request #39 from terrateamio/add-print-usage
ADD Print default usage subcommand
2 parents 10ca3f4 + bc95f05 commit bac4825

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

files/usage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"description": "Default AWS EC2 Instance hours (according to ChatGPT)",
3+
"description": "Default AWS EC2 Instance hours",
44
"match_query": "type = aws_instance and service_class = instance and purchase_option = on_demand and os = linux",
55
"usage": {
66
"time": 730

src/oiq/oiq_usage.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ let of_channel in_chan =
115115

116116
let match_ ms t =
117117
CCList.find_opt (fun { Entry.match_query; _ } -> Oiq_match_query.eval ms match_query) t.entries
118+
119+
let to_yojson { entries } = [%to_yojson: Entry.t list] entries

src/oiq/oiq_usage.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ module Entry : sig
6363
end
6464

6565
type of_channel_err = [ `Usage_file_err of string ] [@@deriving show]
66-
type t
66+
type t [@@deriving to_yojson]
6767

6868
val default : unit -> t
6969
val of_channel : in_channel -> (t, [> of_channel_err ]) result

src/oiq_cli/oiq_cli.ml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ module Cli = struct
7070
C.Cmd.v
7171
(C.Cmd.info "price" ~doc ~exits)
7272
C.Term.(const f $ usage $ input $ output_format $ match_query $ region)
73+
74+
let print_default_usage_cmd f =
75+
let doc = "Print default usage file." in
76+
let exits = C.Cmd.Exit.defaults in
77+
C.Cmd.v (C.Cmd.info "print-default-usage" ~doc ~exits) C.Term.(const f $ const ())
7378
end
7479

7580
let reporter ppf =
@@ -153,6 +158,16 @@ let price usage input output_format match_query regions =
153158
Logs.err (fun m -> m "%a" Oiq.pp_price_err err);
154159
exit 1
155160

161+
let print_default_usage () =
162+
let default = Oiq_usage.default () in
163+
print_endline @@ Yojson.Safe.pretty_to_string @@ Oiq_usage.to_yojson default
164+
156165
let () =
157166
let info = Cmdliner.Cmd.info ~version:Cli.version "oiq" in
158-
exit @@ Cmdliner.Cmd.eval @@ Cmdliner.Cmd.group info [ Cli.match_cmd match_; Cli.price_cmd price ]
167+
exit
168+
@@ Cmdliner.Cmd.eval
169+
@@ Cmdliner.Cmd.group
170+
info
171+
[
172+
Cli.match_cmd match_; Cli.price_cmd price; Cli.print_default_usage_cmd print_default_usage;
173+
]

0 commit comments

Comments
 (0)