Skip to content

Commit 18e194b

Browse files
committed
Client: Import, generate-car(core), local
Signed-off-by: elestrias <[email protected]>
1 parent 0ed0e74 commit 18e194b

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

core/cli/node/_tree.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ namespace fc::cli::_node {
1818
{"client",
1919
tree<Group>({
2020
{"retrieve", tree<clientRetrieve>()},
21+
{"import", tree<clientImportData>()},
22+
{"generate-car", tree<clientGenerateCar>()},
23+
{"local", tree<clientLocal>()},
2124
})},
2225
})};
2326
} // namespace fc::cli::_node

core/cli/node/client.hpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "cli/node/node.hpp"
66

77
namespace fc::cli::_node {
8+
using api::FileRef;
9+
using api::ImportRes;
810
using api::RetrievalOrder;
911
using primitives::BigInt;
1012
using primitives::address::Address;
@@ -17,12 +19,13 @@ namespace fc::cli::_node {
1719
BigInt max_funds;
1820
boost::filesystem::path path;
1921
std::string provider;
22+
bool car{};
2023

2124
CLI_OPTS() {
2225
Opts opts;
2326
auto option{opts.add_options()};
2427
option("from", po::value(&from), "transaction from");
25-
option("pieceCID", po::value(&piece_cid), "cid of piece to retrieve");
28+
option("piece-CID", po::value(&piece_cid), "cid of piece to retrieve");
2629
option(
2730
"maxPrice",
2831
po::value(&max_funds),
@@ -33,6 +36,9 @@ namespace fc::cli::_node {
3336
option("provider",
3437
po::value(&provider)->required(),
3538
"specifies retrieval provider to perform a deal");
39+
option("car",
40+
po::bool_switch(&car),
41+
"store result of retrieval deal to car file");
3642
return opts;
3743
}
3844
};
@@ -53,7 +59,65 @@ namespace fc::cli::_node {
5359
"Invalid Client Address: " + args.from)
5460
}
5561
// TODO: continue function
62+
// TODO: positional args
5663
}
5764
};
5865

66+
struct clientImportData {
67+
struct Args {
68+
bool car{};
69+
std::string path;
70+
71+
CLI_OPTS() {
72+
Opts opts;
73+
auto option{opts.add_options()};
74+
option("car",
75+
po::bool_switch(&car),
76+
"import from a car file instead of a regular file");
77+
option("path,p", po::value(&path), "path to import");
78+
return opts;
79+
}
80+
};
81+
82+
CLI_RUN() {
83+
Node::Api api{argm};
84+
FileRef file_ref{args.path, args.car};
85+
CLI_TRY_TEXT(result, api._->ClientImport(file_ref), "Fail of data import")
86+
std::cout << "File Root CID: " << result.root.toString().value() << "\n";
87+
std::cout << "Data Import Success\n";
88+
}
89+
};
90+
91+
92+
struct clientGenerateCar{
93+
struct Args{
94+
std::string in_path;
95+
std::string out_path;
96+
CLI_OPTS(){
97+
Opts opts;
98+
auto option{opts.add_options()};
99+
option("input-path, inp", po::value(&in_path), "specifies path to source file");
100+
option("output-path, outp", po::value(&in_path), "specifies path to generated file");
101+
}
102+
103+
CLI_RUN(){
104+
std::cout<<"Does not supported yet\n";
105+
}
106+
};
107+
};
108+
109+
struct clientLocal: Empty{
110+
CLI_RUN(){
111+
Node::Api api {argm};
112+
CLI_TRY_TEXT(result, api._->ClientListImports(), "Fail of getting imports list");
113+
for(auto it = result.begin(); it != result.end(); it++){
114+
std::cout<<"Root CID: "<<it->root.toString().value()<<"\n";
115+
std::cout<<"Source: "<<it->source<<"\n";
116+
std::cout<<"Path: "<<it->path<<"\n";
117+
}
118+
}
119+
};
120+
121+
122+
59123
} // namespace fc::cli::_node

0 commit comments

Comments
 (0)