|
2 | 2 |
|
3 | 3 | -include("src/sysexits.hrl"). |
4 | 4 |
|
5 | | --export([run/2]). |
| 5 | +-export([run/2, |
| 6 | + run_old/2]). |
6 | 7 |
|
7 | 8 | -spec run(string(), iodata()) -> ok. |
8 | 9 |
|
9 | | -run(ProgName, RawArgs) -> |
| 10 | +run(_ProgName, Args) -> |
| 11 | + ParserOpts = #{}, |
| 12 | + CommandMods = discover_commands(), |
| 13 | + CommandSpec = collect_args_spec(CommandMods, ParserOpts), |
| 14 | + rabbit_cli_io:setup(#{}), % ParsedArgs |
| 15 | + argparse:run(Args, CommandSpec, ParserOpts), |
| 16 | + rabbit_cli_io:close(). |
| 17 | + |
| 18 | +run_old(ProgName, RawArgs) -> |
10 | 19 | ParserOpts = #{progname => ProgName}, |
11 | 20 | CommandMods = discover_commands(), |
12 | 21 | CommandSpec = collect_args_spec(CommandMods, ParserOpts), |
@@ -86,15 +95,15 @@ set_log_level({ArgMap, _}) -> |
86 | 95 | collect_args_spec(Modules, Options) when is_list(Modules) -> |
87 | 96 | lists:foldl( |
88 | 97 | fun (Mod, Cmds) -> |
89 | | - ModCmd = |
90 | | - try |
91 | | - {_, MCmd} = argparse:validate(Mod:cli(), Options), |
92 | | - MCmd |
93 | | - catch |
94 | | - _:_ -> |
95 | | - %% TODO: Handle error. |
96 | | - #{} |
97 | | - end, |
| 98 | + ModCmd = Mod:cli(), |
| 99 | + %try |
| 100 | + %{_, MCmd} = argparse:validate(Mod:cli(), Options), |
| 101 | + %MCmd |
| 102 | + %catch |
| 103 | + %_:_ -> |
| 104 | + %%% TODO: Handle error. |
| 105 | + %#{} |
| 106 | + %end, |
98 | 107 |
|
99 | 108 | %% handlers: use first non-empty handler |
100 | 109 | Cmds1 = |
|
0 commit comments