Skip to content

Commit

Permalink
fix error message for validate task (#13)
Browse files Browse the repository at this point in the history
* fix error message for validate task

* -d option
  • Loading branch information
GwendalLaurent authored Oct 11, 2024
1 parent 234a709 commit 5a879fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ This command has 2 options:
This command allows you to validate an update that has been deployed on a device

You must specify the serial number of the device in the command:
This command has 1 mandatory option:
- `--device` or `-d`: Used to specify the serial number of the device on which you want to validate the update

```shell
rebar3 grisp-io validate <serial-number>
rebar3 grisp-io validate -d SERIAL_NUMBER
```

---
Expand Down
24 changes: 14 additions & 10 deletions src/rebar3_grisp_io_validate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ init(State) ->
{name, validate},
{module, ?MODULE},
{bare, true},
{example, "rebar3 grisp-io validate"},
{example, "rebar3 grisp-io validate -d 1337"},
{opts, options()},
{profile, [default]},
{short_desc, "Validate an update"},
{desc, "Validate an update deployed on a specific device"}
{desc, "Validate an update deployed on a specific device~n~n" ++
"Example: rebar3 grisp-io validate -d 1337~n"}
]),
{ok, rebar_state:add_provider(State, Provider)}.

Expand All @@ -41,7 +42,8 @@ init(State) ->
do(RState) ->
{ok, _} = application:ensure_all_started(rebar3_grisp_io),
try
Device = try_get_device_serial(RState),
{Args, _} = rebar_state:command_parsed_args(RState),
Device = integer_to_list(try_get_device_serial(Args)),

Config = rebar3_grisp_io_config:read_config(RState),
EncryptedToken = maps:get(encrypted_token, Config),
Expand Down Expand Up @@ -84,12 +86,14 @@ format_error(Reason) ->

%--- Internals -----------------------------------------------------------------

options() -> [].
options() -> [
{device, $d, "device", integer, "Specify the serial number of the device"}
].

try_get_device_serial(RState) ->
case rebar_state:command_args(RState) of
[] ->
throw(no_device_serial_number);
[Serial | _] ->
Serial
try_get_device_serial(Args) ->
case proplists:is_defined(device, Args) of
true ->
proplists:get_value(device, Args);
false ->
throw(no_device_serial_number)
end.
5 changes: 3 additions & 2 deletions test/rebar3_grisp_io_validate_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ init_per_suite(Config) ->
<<"Testuser">>,
<<"1234">>,
<<"azerty">>),
% Config2.
{skip, need_fixing}.
Config2.

end_per_suite(Config) ->
rebar3_grisp_io_common_test:end_per_suite(Config).

init_per_testcase(run_validate, _) ->
{skip, need_fixing};
init_per_testcase(_, Config) ->
setup_meck_io(),
setup_meck_gio_utils(),
Expand Down

0 comments on commit 5a879fa

Please sign in to comment.