Skip to content

Commit ff29739

Browse files
authored
Feature/cli_description (#669)
* Change macros and fill description. Signed-off-by: Mark Esaian <[email protected]> * Add description for all commands. Signed-off-by: Mark Esaian <[email protected]> * Fix name variable. Signed-off-by: Mark Esaian <[email protected]>
1 parent 17a887b commit ff29739

File tree

5 files changed

+140
-49
lines changed

5 files changed

+140
-49
lines changed

core/cli/node/client.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ namespace fc::cli::cli_node {
199199
}
200200
};
201201

202-
struct Node_client_importData {
202+
struct Node_client_import {
203203
struct Args {
204204
CLI_BOOL("car", "import from a car file instead of a regular file") car;
205205

core/cli/node/filplus.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,22 @@ namespace fc::cli::cli_node {
138138
auto state =
139139
cliTry(getCbor<VerifiedRegistryActorStatePtr>(ipfs, actor.head));
140140

141-
auto encoded_params1 = cliTry(codec::cbor::encode(
141+
auto encoded_params = cliTry(codec::cbor::encode(
142142
vm::actor::builtin::v0::verified_registry::AddVerifier::Params{
143143
*args.from, *args.amount
144144
}));
145-
SignedMessage signed_message1 = cliTry(api->MpoolPushMessage(
145+
const SignedMessage signed_message = cliTry(api->MpoolPushMessage(
146146
{kVerifiedRegistryAddress,
147147
state->root_key,
148148
{},
149149
0,
150150
0,
151151
0,
152152
vm::actor::builtin::v0::verified_registry::AddVerifier::Number,
153-
encoded_params1},
153+
encoded_params},
154154
api::kPushNoSpec));
155-
const MsgWait message_wait1 =
156-
cliTry(api->StateWaitMsg(signed_message1.getCid(), 1, 10, false),
155+
const MsgWait message_wait =
156+
cliTry(api->StateWaitMsg(signed_message.getCid(), 1, 10, false),
157157
"Wait message");
158158
}
159159
};

core/cli/node/main.cpp

+113-42
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,127 @@
99
#include "cli/node/wallet.hpp"
1010
#include "cli/run.hpp"
1111

12-
#define CMD(NAME, TYPE) \
13-
{ NAME, tree<TYPE>() }
14-
#define CMDS(NAME, TYPE) NAME, tree<TYPE>
15-
#define GROUP(NAME) CMDS(NAME, Group)
12+
#define CMD(NAME, TYPE, DESC, ...) \
13+
{ NAME, treeDesc<TYPE>(DESC, {__VA_ARGS__})() }
14+
#define CMDS(NAME, TYPE, DESC) NAME, treeDesc<TYPE>(DESC)
15+
#define GROUP(NAME, DESC) CMDS(NAME, Group, DESC)
1616

1717
namespace fc::cli::cli_node {
1818
const auto _tree{tree<Node>({
19-
{GROUP("net")({
20-
CMD("connect", Node_net_connect),
21-
CMD("listen", Node_net_listen),
22-
CMD("peers", Node_net_peers),
19+
{GROUP("net", "Manage P2P Network")({
20+
CMD("connect",
21+
Node_net_connect,
22+
"Connect to a peer",
23+
"peerMultiaddr|minerActorAddress"),
24+
CMD("listen", Node_net_listen, "List listen addresses"),
25+
CMD("peers", Node_net_peers, "Print peers"),
2326
})},
24-
{GROUP("filplus")({
25-
CMD("grant-datacap", Node_filplus_grantDatacap),
26-
CMD("list-notaries", Node_filplus_listNotaries),
27-
CMD("list-clients", Node_filplus_listClients),
28-
CMD("add-verifier", Node_filplus_addVerifier),
29-
CMD("check-client-datacap", Node_filplus_checkClientDataCap),
30-
CMD("check-notary-datacap", Node_filplus_checkNotaryDataCap),
27+
{GROUP("filplus",
28+
"Interact with the verified registry actor used by Filplus")({
29+
CMD("grant-datacap",
30+
Node_filplus_grantDatacap,
31+
"Give allowance to the specified verified client address",
32+
"address",
33+
"allowance"),
34+
CMD("list-notaries", Node_filplus_listNotaries, "List all notaries"),
35+
CMD("list-clients",
36+
Node_filplus_listClients,
37+
"List all verified clients"),
38+
CMD("add-verifier", Node_filplus_addVerifier, "Add verifier address"),
39+
CMD("check-client-datacap",
40+
Node_filplus_checkClientDataCap,
41+
"Check verified client remaining bytes",
42+
"client address"),
43+
CMD("check-notary-datacap",
44+
Node_filplus_checkNotaryDataCap,
45+
"Check a notary's remaining bytes",
46+
"notary address"),
3147
})},
32-
{GROUP("client")({
33-
CMD("retrieve", Node_client_retrieve),
34-
CMD("import", Node_client_importData),
35-
CMD("deal", Node_client_deal),
36-
CMD("generate-car", Node_client_generateCar),
37-
CMD("local", Node_client_local),
38-
CMD("find", Node_client_find),
39-
CMD("list-retrievals", Node_client_listRetrievals),
40-
CMD("inspect-deal", Node_client_inspectDeal),
41-
CMD("deal-stats", Node_client_dealStats),
42-
CMD("list-deals", Node_client_listDeals),
43-
CMD("balances", Node_client_balances),
44-
CMD("get-deal", Node_client_getDeal),
48+
{GROUP("client", "Make deals, store data, retrieve data")({
49+
CMD("retrieve",
50+
Node_client_retrieve,
51+
"Retrieve data from network",
52+
"data CID",
53+
"output path"),
54+
CMD("import", Node_client_import, "Import data", "input path"),
55+
CMD("deal",
56+
Node_client_deal,
57+
"Initialize storage deal with a miner",
58+
"dataCid",
59+
"miner",
60+
"price",
61+
"duration"),
62+
CMD("generate-car",
63+
Node_client_generateCar,
64+
"Generate a car file from input",
65+
"input path",
66+
"output path"),
67+
CMD("local", Node_client_local, "List locally imported data"),
68+
CMD("find", Node_client_find, "Find data in the network", "data CID"),
69+
CMD("list-retrievals",
70+
Node_client_listRetrievals,
71+
"List retrieval market deals"),
72+
CMD("inspect-deal",
73+
Node_client_inspectDeal,
74+
"Inspect detailed information about deal's lifecycle and the "
75+
"various stages it goes through"),
76+
CMD("deal-stats",
77+
Node_client_dealStats,
78+
"Print statistics about local storage deals"),
79+
CMD("list-deals", Node_client_listDeals, "List storage market deals"),
80+
CMD("balances",
81+
Node_client_balances,
82+
"Print storage market client balances"),
83+
CMD("get-deal",
84+
Node_client_getDeal,
85+
"Print detailed deal information",
86+
"proposal CID"),
4587
})},
46-
{GROUP("wallet")({
47-
CMD("new", Node_wallet_new),
48-
CMD("list", Node_wallet_list),
49-
CMD("add-balance", Node_wallet_addBalance),
50-
CMD("balance", Node_wallet_balance),
51-
CMD("default", Node_wallet_default),
52-
CMD("set-default", Node_wallet_setDefault),
53-
CMD("import", Node_wallet_import),
54-
CMD("sign", Node_wallet_sign),
55-
CMD("verify", Node_wallet_verify),
56-
CMD("delete", Node_wallet_delete),
57-
{GROUP("market")({
58-
CMD("add", Node_wallet_market_add),
88+
{GROUP("wallet", "Manage wallet")({
89+
CMD("new",
90+
Node_wallet_new,
91+
"Generate a new key of the given type",
92+
"type(bls|secp256k1 (default: secp256k1))"),
93+
CMD("list", Node_wallet_list, "List wallet address"),
94+
CMD("add-balance",
95+
Node_wallet_addBalance,
96+
"Send funds between accounts",
97+
"target address",
98+
"amount"),
99+
CMD("balance",
100+
Node_wallet_balance,
101+
"Get account balance",
102+
"address"),
103+
CMD("default", Node_wallet_default, "Get default wallet address"),
104+
CMD("set-default",
105+
Node_wallet_setDefault,
106+
"Set default wallet address",
107+
"address"),
108+
CMD("import", Node_wallet_import, "Import keys", {"path(optional)"}),
109+
CMD("sign",
110+
Node_wallet_sign,
111+
"Sign a message",
112+
"signing address",
113+
"hex message"),
114+
CMD("verify",
115+
Node_wallet_verify,
116+
"Verify the signature of a message",
117+
"signing address",
118+
"hexMessage",
119+
"signature"),
120+
CMD("delete",
121+
Node_wallet_delete,
122+
"Soft delete an address from the wallet - hard deletion "
123+
"needed for permanent removal",
124+
"address"),
125+
{GROUP("market", "Interact with market balances")({
126+
CMD("add",
127+
Node_wallet_market_add,
128+
"Add funds to the Storage Market Actor",
129+
"amount"),
59130
})},
60131
})},
61-
CMD("version", Node_version),
132+
CMD("version", Node_version, "Api version"),
62133
})};
63134

64135
} // namespace fc::cli::cli_node

core/cli/run.hpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ namespace fc::cli {
9393
}
9494
}
9595
}
96-
fmt::print("name:\n {}\n", fmt::join(cmds, " "));
96+
fmt::print("name:\n {}", fmt::join(cmds, " "));
97+
for(const auto &arg : tree->argusage) {
98+
fmt::print(" <{}>", arg);
99+
}
100+
fmt::print("\n");
101+
102+
if (not tree->description.empty()) {
103+
fmt::print("description:\n {}\n", tree->description);
104+
}
97105
fmt::print("options:\n{}", args.opts);
98106
if (!tree->sub.empty()) {
99107
fmt::print("subcommands:\n");

core/cli/tree.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77

88
#include "cli/cli.hpp"
9+
#include <string>
910

1011
namespace fc::cli {
1112
struct Tree {
@@ -17,6 +18,8 @@ namespace fc::cli {
1718
std::function<Args()> args;
1819
std::function<RunResult(ArgsMap &argm, Argv &&argv)> run;
1920
Sub sub;
21+
std::string description;
22+
std::vector<std::string> argusage;
2023
};
2124
template <typename Cmd>
2225
Tree tree(Tree::Sub sub = {}) {
@@ -37,4 +40,13 @@ namespace fc::cli {
3740
t.sub = std::move(sub);
3841
return t;
3942
}
43+
template<class Cmd>
44+
auto treeDesc(std::string description, std::vector<std::string> argusage = {}) {
45+
return [=](Tree::Sub sub = {}) {
46+
auto t = tree<Cmd>(sub);
47+
t.description = description;
48+
t.argusage = argusage;
49+
return t;
50+
}; }
51+
4052
} // namespace fc::cli

0 commit comments

Comments
 (0)