Refactor a bit
This commit is contained in:
parent
8559e0ae88
commit
69c1d3c2aa
22
mcopy.cpp
22
mcopy.cpp
|
@ -95,6 +95,9 @@ void getMetadataFromFile(std::string format, std::string str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!std::cin) // Failed to get details, skipping
|
||||||
|
return;
|
||||||
|
|
||||||
std::string filename = format;
|
std::string filename = format;
|
||||||
|
|
||||||
// TODO: Replace this junk
|
// TODO: Replace this junk
|
||||||
|
@ -123,17 +126,18 @@ void getMetadataFromFile(std::string format, std::string str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::string format = "";
|
bool set{false};
|
||||||
|
std::string format;
|
||||||
|
|
||||||
for (int i{1}; i < argc; i++) {
|
for (int i{1}; i < argc; i++) {
|
||||||
std::string arg = argv[i];
|
std::string arg = argv[i];
|
||||||
|
|
||||||
if (!arg.compare("-h") || !arg.compare("--help")) {
|
if (!arg.compare("-h") || !arg.compare("--help")) {
|
||||||
help();
|
help();
|
||||||
std::exit(0);
|
return 0;
|
||||||
} else if (!arg.compare("-v") || !arg.compare("--version")) {
|
} else if (!arg.compare("-v") || !arg.compare("--version")) {
|
||||||
std::cout << "mcopy " << VERSION << '\n';
|
std::cout << "mcopy " << VERSION << '\n';
|
||||||
std::exit(0);
|
return 0;
|
||||||
} else if (!arg.compare("-a") || !arg.compare("--ask")) {
|
} else if (!arg.compare("-a") || !arg.compare("--ask")) {
|
||||||
ask = true;
|
ask = true;
|
||||||
} else if (!arg.compare("-na") || !arg.compare("--no-ask")) {
|
} else if (!arg.compare("-na") || !arg.compare("--no-ask")) {
|
||||||
|
@ -150,29 +154,27 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!format.compare("")) {
|
if (!format.empty()) {
|
||||||
std::cerr << "mcopy: You must specify a format.\n";
|
std::cerr << "mcopy: You must specify a format.\n";
|
||||||
std::exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
std::cerr << "mcopy: You must specify a file to copy.\n";
|
std::cerr << "mcopy: You must specify a file to copy.\n";
|
||||||
std::exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int set{0};
|
|
||||||
|
|
||||||
for (int i{1}; i < argc; i++) {
|
for (int i{1}; i < argc; i++) {
|
||||||
std::ifstream f(argv[i]);
|
std::ifstream f(argv[i]);
|
||||||
|
|
||||||
if (static_cast<bool>(f.good())) {
|
if (static_cast<bool>(f.good())) {
|
||||||
set = 1;
|
set = true;
|
||||||
getMetadataFromFile(format, argv[i]);
|
getMetadataFromFile(format, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!set) {
|
if (!set) {
|
||||||
std::cerr << "mcopy: File not found.\n";
|
std::cerr << "mcopy: File not found.\n";
|
||||||
std::exit(1);
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue