Skip to content

Commit

Permalink
Format main.cpp by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
matken11235 committed Dec 31, 2018
1 parent 8fa882e commit e940720
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlwaysBreakTemplateDeclarations: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Stroustrup
IndentWidth: 4
IndentCaseLabels: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PointerAlignment: Left
43 changes: 23 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <cstdlib>

#include "./include/poac/poac.hpp"


using VS = std::vector<std::string>;

// TODO: このあたりの処理をmain.cppがするべきではない.もう一段階抽象化すべき
int error_handling(std::string&& s) {
int error_handling(std::string&& s)
{
namespace inference = poac::core::infer;
namespace io = poac::io;
namespace io = poac::io;
using namespace std::string_literals;

std::cerr << io::cli::to_red("ERROR: ")
<< s << std::endl
<< std::endl;
std::cerr << io::cli::to_red("ERROR: ") << s << std::endl << std::endl;
inference::apply("exec"s, "--help"s, VS());
return EXIT_FAILURE;
}

int exec(std::string&& str, VS&& vs) {
int exec(std::string&& str, VS&& vs)
{
namespace inference = poac::core::infer;
namespace except = poac::core::exception;
namespace cli = poac::io::cli;
namespace except = poac::core::exception;
namespace cli = poac::io::cli;
using namespace std::string_literals;

// TODO: 広い空間でcatchするのは危険.Result typeを使用したい
Expand All @@ -37,7 +37,7 @@ int exec(std::string&& str, VS&& vs) {
return error_handling(e.what());
}
catch (const except::invalid_second_arg& e) {
inference::apply("exec"s, "--help"s, VS({ e.what() }));
inference::apply("exec"s, "--help"s, VS({e.what()}));
return EXIT_FAILURE;
}
catch (const except::error& e) {
Expand All @@ -48,32 +48,35 @@ int exec(std::string&& str, VS&& vs) {
std::cout << cli::to_yellow("WARN: ") << e.what() << std::endl;
return EXIT_SUCCESS;
}
catch (const YAML::BadConversion& e) { // TODO: poac.yml OR poac.yaml?
std::cout << cli::to_red("ERROR: ") << "poac.yml " << e.what() << std::endl;
catch (const YAML::BadConversion& e) {
// TODO: poac.yml OR poac.yaml?
std::cout << cli::to_red("ERROR: ") << "poac.yml " << e.what()
<< std::endl;
return EXIT_SUCCESS;
}
catch (...) {
std::cerr << cli::to_red("ERROR: ")
<< "Unexpected error"
<< std::endl;
std::cerr << cli::to_red("ERROR: ") << "Unexpected error" << std::endl;
return EXIT_FAILURE;
}
}

bool equal_str(const std::string& s1, const std::string& s2, const std::string& s3) {
bool equal_str(const std::string& s1, const std::string& s2,
const std::string& s3)
{
return (s1 == s2) || (s1 == s3);
}

int main(int argc, const char** argv) {
int main(int argc, const char** argv)
{
// argv[0]: poac, argv[1]: install, argv[2]: 1, ...

//$ poac install --help => exec("--help", ["install"])
if (argc == 3 && equal_str(argv[2], "-h", "--help")) {
return exec(argv[2], VS({ argv[1] }));
return exec(argv[2], VS({argv[1]}));
}
//$ poac install 1 2 3 => exec("install", ["1", "2", "3"])
else if (argc >= 3) {
return exec(argv[1], VS(argv+2, argv+argc));
return exec(argv[1], VS(argv + 2, argv + argc));
}
//$ poac install => exec("install", [])
else if (argc >= 2) {
Expand Down

0 comments on commit e940720

Please sign in to comment.