forked from basho/clique
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request basho#45 from basho/feature/cuttlefish-datatypes
Introduce spec record for args and flags, datatypes, and validators. Reviewed-by: nickelization
- Loading branch information
Showing
6 changed files
with
287 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%% This record represents the specification for a key-value argument | ||
%% or flag on the command line. | ||
-record(clique_spec, | ||
{ | ||
key :: atom(), | ||
name :: string(), | ||
shortname :: char() | undefined, | ||
datatype :: cuttlefish_datatypes:datatype() | undefined, | ||
validator :: fun((term()) -> ok | err()) | undefined, | ||
typecast :: fun((string()) -> err() | term()) | undefined | ||
}). | ||
|
||
-type spec() :: #clique_spec{}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
%% | ||
%% ------------------------------------------------------------------- | ||
-module(clique_command). | ||
-include("clique_specs.hrl"). | ||
|
||
-define(cmd_table, clique_commands). | ||
|
||
|
@@ -40,7 +41,9 @@ init() -> | |
|
||
%% @doc Register a cli command (i.e.: "riak-admin handoff status") | ||
-spec register([string()], list(), list(), fun()) -> true. | ||
register(Cmd, Keys, Flags, Fun) -> | ||
register(Cmd, Keys0, Flags0, Fun) -> | ||
Keys = make_specs(Keys0), | ||
Flags = make_specs(Flags0), | ||
ets:insert(?cmd_table, {Cmd, Keys, Flags, Fun}). | ||
|
||
-spec run(err()) -> err(); | ||
|
@@ -86,6 +89,11 @@ split_command(Cmd0) -> | |
clique_parser:is_not_flag(Str) | ||
end, Cmd0). | ||
|
||
|
||
-spec make_specs([{atom(), proplist()}]) -> [spec()]. | ||
make_specs(Specs) -> | ||
[ clique_spec:make(Spec) || Spec <- Specs ]. | ||
|
||
%% NB This is a bit sneaky. We normally only accept key/value args like | ||
%% "handoff.inbound=off" and flag-style arguments like "--node [email protected]" or "--all", | ||
%% but the builtin "show" and "describe" commands work a bit differently. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.