Skip to content

Commit 0ed0e74

Browse files
committed
retireve args parsing
Signed-off-by: elestrias <[email protected]>
1 parent 4c3d4b1 commit 0ed0e74

File tree

3 files changed

+56
-23
lines changed

3 files changed

+56
-23
lines changed

core/cli/cli.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#include <memory>
1212
#include <typeindex>
1313

14+
#define CLI_TRY(valueName, maybeResult) \
15+
auto valueName##OUTCOME_TRY = maybeResult; \
16+
if (valueName##OUTCOME_TRY.has_error()) throw std::invalid_argument(""); \
17+
auto valueName = valueName##OUTCOME_TRY.value();
18+
19+
#define CLI_TRY_TEXT(valueName, maybeResult, textError) \
20+
auto valueName##OUTCOME_TRY = maybeResult; \
21+
if (valueName##OUTCOME_TRY.has_error()) throw std::invalid_argument(textError); \
22+
auto valueName = valueName##OUTCOME_TRY.value();
23+
1424
#define CLI_OPTS() ::fc::cli::Opts opts()
1525
#define CLI_RUN() \
1626
static ::fc::cli::RunResult run(const ::fc::cli::ArgsMap &argm, \

core/cli/node/_tree.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace fc::cli::_node {
1717
})},
1818
{"client",
1919
tree<Group>({
20-
{"retrieve", tree<clientRetrive>()},
20+
{"retrieve", tree<clientRetrieve>()},
2121
})},
2222
})};
2323
} // namespace fc::cli::_node

core/cli/node/client.hpp

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,56 @@
44
#pragma once
55
#include "cli/node/node.hpp"
66

7-
namespace fc::cli::_node{
8-
9-
10-
struct clientRetrive{
11-
struct Args{
12-
bool car{};
13-
bool export_merkle_root{};
14-
std::string data_selector;
15-
16-
CLI_OPTS(){
17-
Opts opts;
7+
namespace fc::cli::_node {
8+
using api::RetrievalOrder;
9+
using primitives::BigInt;
10+
using primitives::address::Address;
11+
using primitives::address::decodeFromString;
12+
13+
struct clientRetrieve {
14+
struct Args {
15+
std::string from;
16+
std::string piece_cid;
17+
BigInt max_funds;
18+
boost::filesystem::path path;
19+
std::string provider;
20+
21+
CLI_OPTS() {
22+
Opts opts;
1823
auto option{opts.add_options()};
19-
option("car", po::bool_switch(&car), "Export to a car file instead of a regular file");
20-
option("data-selector", po::value(&data_selector), "IPLD datamodel text-path selector, or IPLD json selector");
21-
option("car-export-merkle-proof", po::bool_switch(&export_merkle_root), "(requires --data-selector and --car) Export data-selector merkle proof");
24+
option("from", po::value(&from), "transaction from");
25+
option("pieceCID", po::value(&piece_cid), "cid of piece to retrieve");
26+
option(
27+
"maxPrice",
28+
po::value(&max_funds),
29+
"specifies the maximum token amount that client ready to spend");
30+
option("path",
31+
po::value(&path)->required(),
32+
"specifies the path to retrieve");
33+
option("provider",
34+
po::value(&provider)->required(),
35+
"specifies retrieval provider to perform a deal");
2236
return opts;
2337
}
2438
};
2539

26-
27-
CLI_RUN(){
28-
std::cout<<args.data_selector<<"\n";
40+
CLI_RUN() {
41+
Node::Api api{argm};
42+
CLI_TRY_TEXT(cid,
43+
CID::fromString(args.piece_cid),
44+
"Invalid piece CID: " + args.piece_cid)
45+
if (!args.provider.empty()) {
46+
CLI_TRY_TEXT(miner,
47+
decodeFromString(args.provider),
48+
"Invalid Provider Address: " + args.provider)
49+
}
50+
if (!args.from.empty()) {
51+
CLI_TRY_TEXT(client,
52+
decodeFromString(args.from),
53+
"Invalid Client Address: " + args.from)
54+
}
55+
// TODO: continue function
2956
}
3057
};
3158

32-
33-
34-
35-
36-
} //fc::cli::node
59+
} // namespace fc::cli::_node

0 commit comments

Comments
 (0)