cli: Ajoute une Factory
This commit is contained in:
@@ -30,4 +30,8 @@ namespace make {
|
|||||||
<< " return 0;\n"
|
<< " return 0;\n"
|
||||||
<< "}\n";
|
<< "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view CCompilatorStrategy::getMainName(){
|
||||||
|
return "main.c";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,5 +8,6 @@ namespace make {
|
|||||||
std::ostream &writeStart(std::ostream &out) override;
|
std::ostream &writeStart(std::ostream &out) override;
|
||||||
std::ostream &writeEnd(std::ostream &out) override;
|
std::ostream &writeEnd(std::ostream &out) override;
|
||||||
std::ostream &writeMain(std::ostream &out) override;
|
std::ostream &writeMain(std::ostream &out) override;
|
||||||
|
std::string_view getMainName() override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -8,6 +8,7 @@ namespace make {
|
|||||||
virtual std::ostream &writeStart(std::ostream &out) = 0;
|
virtual std::ostream &writeStart(std::ostream &out) = 0;
|
||||||
virtual std::ostream &writeEnd(std::ostream &out) = 0;
|
virtual std::ostream &writeEnd(std::ostream &out) = 0;
|
||||||
virtual std::ostream &writeMain(std::ostream &out) = 0;
|
virtual std::ostream &writeMain(std::ostream &out) = 0;
|
||||||
|
virtual std::string_view getMainName() = 0;
|
||||||
virtual ~CompilatorStrategy() = default;
|
virtual ~CompilatorStrategy() = default;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -30,4 +30,8 @@ namespace make {
|
|||||||
<< " return 0;\n"
|
<< " return 0;\n"
|
||||||
<< "}\n";
|
<< "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string_view CppCompilatorStrategy::getMainName(){
|
||||||
|
return "main.cpp";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,5 +8,7 @@ namespace make {
|
|||||||
std::ostream &writeStart(std::ostream &out) override;
|
std::ostream &writeStart(std::ostream &out) override;
|
||||||
std::ostream &writeEnd(std::ostream &out) override;
|
std::ostream &writeEnd(std::ostream &out) override;
|
||||||
std::ostream &writeMain(std::ostream &out) override;
|
std::ostream &writeMain(std::ostream &out) override;
|
||||||
|
std::string_view getMainName() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
18
cli/src/make/SourceFactory.cpp
Normal file
18
cli/src/make/SourceFactory.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "SourceFactory.h"
|
||||||
|
#include "../make/CppCompilatorStrategy.h"
|
||||||
|
#include "../make/CCompilatorStrategy.h"
|
||||||
|
|
||||||
|
namespace make {
|
||||||
|
std::unique_ptr<make::CompilatorStrategy> SourceFactory::fabrique(ProjectKind kind){
|
||||||
|
switch (kind) {
|
||||||
|
case make::ProjectKind::C:
|
||||||
|
return std::make_unique<make::CCompilatorStrategy>();
|
||||||
|
break;
|
||||||
|
case make::ProjectKind::Cpp:
|
||||||
|
return std::make_unique<make::CppCompilatorStrategy>();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
cli/src/make/SourceFactory.h
Normal file
13
cli/src/make/SourceFactory.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../make/CompilatorStrategy.h"
|
||||||
|
#include "ProjectKind.h"
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
namespace make {
|
||||||
|
class SourceFactory {
|
||||||
|
public:
|
||||||
|
static std::unique_ptr<make::CompilatorStrategy> fabrique(ProjectKind kind);
|
||||||
|
};
|
||||||
|
}
|
@@ -2,6 +2,7 @@
|
|||||||
#include "../io/oki.h"
|
#include "../io/oki.h"
|
||||||
#include "../make/CppCompilatorStrategy.h"
|
#include "../make/CppCompilatorStrategy.h"
|
||||||
#include "../make/CCompilatorStrategy.h"
|
#include "../make/CCompilatorStrategy.h"
|
||||||
|
#include "../make/SourceFactory.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -32,22 +33,13 @@ namespace op {
|
|||||||
manifest << "\n[dependencies]\n";
|
manifest << "\n[dependencies]\n";
|
||||||
|
|
||||||
std::unique_ptr<make::CompilatorStrategy> strategy;
|
std::unique_ptr<make::CompilatorStrategy> strategy;
|
||||||
switch (options.kind) {
|
strategy = make::SourceFactory::fabrique(options.kind);
|
||||||
case make::ProjectKind::C:
|
|
||||||
strategy = std::make_unique<make::CCompilatorStrategy>();
|
|
||||||
break;
|
|
||||||
case make::ProjectKind::Cpp:
|
|
||||||
strategy = std::make_unique<make::CppCompilatorStrategy>();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw std::range_error("Unknown project kind");
|
|
||||||
}
|
|
||||||
|
|
||||||
fs::path src{workingDirectory / "src"};
|
fs::path src{workingDirectory / "src"};
|
||||||
fs::create_directories(src);
|
fs::create_directories(src);
|
||||||
if(!options.lib) {
|
if(!options.lib) {
|
||||||
if(!fs::exists(src / "main.c")){
|
if(!fs::exists(src / strategy->getMainName())){
|
||||||
std::ofstream main{src / "main.c"};
|
std::ofstream main{src / strategy->getMainName()};
|
||||||
if (!main) {
|
if (!main) {
|
||||||
std::cerr << "Cannot write main source file: " << strerror(errno);
|
std::cerr << "Cannot write main source file: " << strerror(errno);
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user