Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor some files #176

Merged
merged 35 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8405380
Update appveyor.yml
ken-matsui Aug 24, 2019
3fb515c
test pretty.cpp
ken-matsui Aug 25, 2019
cd2610f
Fix unused variables warning
ken-matsui Aug 25, 2019
20ef578
Improve tests/project.cpp
ken-matsui Aug 25, 2019
4400e36
Fix warning: control reaches end of non-void function
ken-matsui Aug 25, 2019
0907e3d
Improve include/poac/opts/new.hpp
ken-matsui Aug 25, 2019
919742e
Merge branch 'develop' of github.com:poacpm/poac into fix/cygwin-ctest
ken-matsui Aug 26, 2019
d695c5e
Fix include/poac/util/pretty.hpp
ken-matsui Aug 26, 2019
d37f0bf
Fix some files
ken-matsui Aug 26, 2019
fb43f9c
Improve CMakeLists.txt
ken-matsui Aug 26, 2019
1f40c01
Improve include/poac/util/pretty.hpp
ken-matsui Aug 26, 2019
f1cd9f7
Improve include/poac/io/term.hpp
ken-matsui Aug 26, 2019
e394cab
Improve include/poac/io/filesystem.hpp
ken-matsui Aug 26, 2019
0779b69
Improve include/poac/core/cli.hpp
ken-matsui Aug 26, 2019
41cf1db
Improve include/poac/opts/*
ken-matsui Aug 26, 2019
f682de4
Merge branch 'develop' of github.com:poacpm/poac into fix/cygwin-ctest
ken-matsui Sep 2, 2019
59c6473
Improve include/poac/util/semver
ken-matsui Sep 3, 2019
ffbce33
Fix include/poac/util/semver
ken-matsui Sep 3, 2019
de638e2
Update CMakeLists.txt
ken-matsui Sep 3, 2019
6e01e82
Update cli.cpp
ken-matsui Sep 3, 2019
976fa71
Update CMakeLists.txt
ken-matsui Sep 3, 2019
8b9b69e
Update CMakeLists.txt
ken-matsui Sep 3, 2019
ebd7569
Update cli.hpp
ken-matsui Sep 3, 2019
2145cb1
Update version.hpp
ken-matsui Sep 3, 2019
3ca7f9e
Update version.hpp
ken-matsui Sep 3, 2019
ac8bb16
Improve appveyor.yml
ken-matsui Nov 16, 2019
6a517b3
Merge branch 'fix/cygwin-ctest' of github.com:poacpm/poac into fix/cy…
ken-matsui Nov 16, 2019
9ea9005
Fix conflict in include/poac/util/cfg.hpp
ken-matsui Nov 16, 2019
bd959ed
Update exception.hpp
ken-matsui Nov 16, 2019
d0d2809
Merge branch 'develop' into fix/cygwin-ctest
ken-matsui Nov 17, 2019
42e89f8
Improve tests/semver/CMakeLists.txt
ken-matsui Nov 17, 2019
90f9403
Merge branch 'fix/cygwin-ctest' of github.com:poacpm/poac into fix/cy…
ken-matsui Nov 17, 2019
01832f5
Merge branch 'develop' into fix/cygwin-ctest
ken-matsui Nov 18, 2019
6431e0e
Improve tests/cfg.cpp
ken-matsui Nov 18, 2019
d5048a1
Update cfg.cpp
ken-matsui Nov 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/poac/core/builder/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdint>
#include <chrono>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <optional>
Expand Down Expand Up @@ -32,6 +33,10 @@ namespace poac::core::builder {
return (os << "dev");
case Mode::Release:
return (os << "release");
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
5 changes: 5 additions & 0 deletions include/poac/core/builder/standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define POAC_CORE_BUILDER_STANDARD_HPP

#include <cstdint>
#include <stdexcept>
#include <string>
#include <string_view>
#include <regex>
Expand Down Expand Up @@ -227,6 +228,10 @@ namespace poac::core::builder::standard {
// Support OS: Only macos
case util::cfg::compiler::apple_clang:
return apple_llvm_convert(cpp_version, enable_gnu);
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
45 changes: 22 additions & 23 deletions include/poac/core/cli.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@
#include <poac/util/clap/clap.hpp>

namespace poac::core::cli {
std::vector<clap::subcommand> builtin() {
return {
opts::build::cli,
opts::cache::cli,
opts::clean::cli,
opts::graph::cli,
opts::help::cli,
opts::init::cli,
opts::install::cli,
opts::_new::cli,
opts::publish::cli,
opts::run::cli,
opts::search::cli,
opts::test::cli,
opts::uninstall::cli,
opts::update::cli,
opts::version::cli,
};
}
inline std::vector<clap::subcommand>
builtin{
opts::build::cli,
opts::cache::cli,
opts::clean::cli,
opts::graph::cli,
opts::help::cli,
opts::init::cli,
opts::install::cli,
opts::_new::cli,
opts::publish::cli,
opts::run::cli,
opts::search::cli,
opts::test::cli,
opts::uninstall::cli,
opts::update::cli,
opts::version::cli,
};

const clap::app cli =
inline const clap::app cli =
clap::app("poac")
.version(POAC_VERSION)
.arg(clap::opt("version", "Print version info and exit").short_("V"))
Expand All @@ -51,7 +50,7 @@ namespace poac::core::cli {
.global(true)
)
.arg(clap::opt("quiet", "No output printed to stdout").short_("q"))
.subcommands(cli::builtin())
.subcommands(cli::builtin)
// .fooks(cli::builtin_exec())
;

Expand All @@ -60,7 +59,7 @@ namespace poac::core::cli {
using ret_type = std::optional<except::Error>;
using fn_type = std::function<ret_type(arg1_type, arg2_type)>;

const std::unordered_map<std::string_view, fn_type>
inline const std::unordered_map<std::string_view, fn_type>
opts_map{
{ "build", opts::build::exec },
{ "cache", opts::cache::exec },
Expand All @@ -87,7 +86,7 @@ namespace poac::core::cli {
exec(std::string_view cmd, std::vector<std::string>&& args) {
try {
opts_map.at(cmd);
} catch(std::out_of_range&) {
} catch (std::out_of_range&) {
return except::Error::InvalidFirstArg;
}
return opts_map.at(cmd)(
Expand Down
16 changes: 10 additions & 6 deletions include/poac/core/except.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ namespace poac::core::except {
std::string to_string(const Arg& str) {
return std::to_string(str);
}

template<>
std::string to_string(const std::string& str) {
return str;
}

std::string to_string(std::string_view str) {
return std::string(str);
}

template<typename CharT, std::size_t N>
std::string to_string(const CharT(&str)[N]) {
return str;
Expand Down Expand Up @@ -49,7 +46,6 @@ namespace poac::core::except {
(... + detail::to_string(s))
) // delegation
{}

virtual ~General() noexcept = default;

virtual std::string what() const {
Expand Down Expand Up @@ -109,16 +105,20 @@ namespace poac::core::except {
return s.what();
}
std::string
what(NoStates err) const noexcept {
what(NoStates err) const {
switch (err) {
case NoStates::InterruptedByUser:
return "Interrupted by user";
case NoStates::InvalidFirstArg:
return "Invalid arguments";
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}
std::string
what(InvalidSecondArg err) const noexcept {
what(InvalidSecondArg err) const {
switch (err) {
case InvalidSecondArg::Build:
return "build";
Expand All @@ -138,6 +138,10 @@ namespace poac::core::except {
return "search";
case InvalidSecondArg::Uninstall:
return "uninstall";
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
1 change: 1 addition & 0 deletions include/poac/core/resolver/resolve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ namespace poac::core::resolver::resolve {
for (const auto& [name, package] : deps) {
// Check if root package is resolved dependency (by interval)
for (const auto& [n, i, versions] : interval_cache) {
static_cast<void>(versions);
if (name == n && package.version == i) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions include/poac/io/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace poac::io::filesystem {
inline const io::filesystem::path current_build_test_dir(current_build_dir / "test");
inline const io::filesystem::path current_build_test_bin_dir(current_build_test_dir / "bin");

bool validate_dir(const io::filesystem::path& path) {
inline bool validate_dir(const io::filesystem::path& path) {
namespace fs = io::filesystem;
return fs::exists(path) && fs::is_directory(path) && !fs::is_empty(path);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ namespace poac::io::filesystem {
}
#endif

std::string
inline std::string
time_to_string(const std::time_t& time) {
return std::to_string(time);
}
Expand Down
7 changes: 6 additions & 1 deletion include/poac/io/lockfile.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef POAC_IO_LOCKFILE_HPP
#define POAC_IO_LOCKFILE_HPP

#include <stdexcept>
#include <string>
#include <string_view>
#include <unordered_map>
Expand All @@ -21,14 +22,18 @@ namespace poac::io::lockfile {
};

std::string
to_string(PackageType package_type) noexcept {
to_string(PackageType package_type) {
switch (package_type) {
case PackageType::HeaderOnlyLib:
return "header-only library";
case PackageType::BuildReqLib:
return "build-required library";
case PackageType::Application:
return "application";
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/poac/opts/build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <poac/util/clap/clap.hpp>

namespace poac::opts::build {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("build")
.about("Compile a project and all sources that depend on its")
.arg(clap::opt("release", "Build artifacts in release mode, with optimizations"))
Expand Down
7 changes: 6 additions & 1 deletion include/poac/opts/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <future>
#include <iostream>
#include <stdexcept>
#include <string>
#include <regex>
#include <optional>
Expand All @@ -17,7 +18,7 @@
#include <poac/util/termcolor2/termcolor2.hpp>

namespace poac::opts::cache {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("cache")
.about("Manipulate cache files")
.arg(clap::opt("all", "Manipulate all caches").short_("a"))
Expand Down Expand Up @@ -92,6 +93,10 @@ namespace poac::opts::cache {
return list(std::move(opts));
case cache::Options::SubCmd::Clean:
return clean(std::move(opts));
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/poac/opts/clean.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <poac/opts/uninstall.hpp>

namespace poac::opts::clean {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("clean")
.about("Delete unnecessary things")
;
Expand Down
2 changes: 1 addition & 1 deletion include/poac/opts/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <poac/util/shell.hpp>

namespace poac::opts::graph {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("graph")
.about("Create a dependency graph")
.arg(clap::opt("output", "Output file name").short_("o").value_name("NAME"))
Expand Down
4 changes: 2 additions & 2 deletions include/poac/opts/help.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <poac/util/clap/clap.hpp>

namespace poac::opts::help {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("help")
.about("Prints this message or the help of the given subcommand(s)")
.arg(clap::arg("subcommand").multiple(true))
Expand All @@ -41,7 +41,7 @@ namespace poac::opts::help {
std::string cmd;
};

const std::unordered_map<std::string_view, clap::subcommand>
inline const std::unordered_map<std::string_view, clap::subcommand>
subcommands{
{ "build", opts::build::cli },
{ "cache", opts::cache::cli },
Expand Down
2 changes: 1 addition & 1 deletion include/poac/opts/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <poac/util/termcolor2/termcolor2.hpp>

namespace poac::opts::init {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("init")
.about("Create a new poac package in an existing directory")
.arg(clap::opt("bin", "Use a binary (application) template [default]"))
Expand Down
2 changes: 1 addition & 1 deletion include/poac/opts/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <poac/util/shell.hpp>

namespace poac::opts::install {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("install")
.about("Install a C++ binary. Default location is $HOME/.poac/bin")
.arg(clap::opt("verbose", "Use verbose output").short_("v"))
Expand Down
20 changes: 15 additions & 5 deletions include/poac/opts/new.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <future>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <map>
Expand All @@ -21,7 +22,7 @@
#include <poac/util/termcolor2/termcolor2.hpp>

namespace poac::opts::_new {
const clap::subcommand cli =
inline const clap::subcommand cli =
clap::subcommand("new")
.about("Create a new poac package at <path>")
.arg(clap::opt("quiet", "No output printed to stdout").short_("q"))
Expand Down Expand Up @@ -56,21 +57,22 @@ namespace poac::opts::_new {

namespace files {
namespace bin {
std::string poac_toml(const std::string&) {
inline std::string
poac_toml(const std::string&) {
return "cpp = 17";
}
const std::string main_cpp(
inline const std::string main_cpp(
"#include <iostream>\n\n"
"int main(int argc, char** argv) {\n"
" std::cout << \"Hello, world!\" << std::endl;\n"
"}"
);
}
namespace lib {
const std::string poac_toml(
inline const std::string poac_toml(
"cpp = 17"
);
std::string include_hpp(std::string project_name) {
inline std::string include_hpp(std::string project_name) {
std::transform(project_name.cbegin(), project_name.cend(), project_name.begin(), ::toupper);
return "#ifndef " + project_name + "_HPP\n"
"#define " + project_name + "_HPP\n\n"
Expand All @@ -91,6 +93,10 @@ namespace poac::opts::_new {
return (os << "binary (application)");
case ProjectType::Lib:
return (os << "library");
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down Expand Up @@ -129,6 +135,10 @@ namespace poac::opts::_new {
files::lib::include_hpp(opts.project_name)
},
};
default:
throw std::logic_error(
"To access out of range of the "
"enumeration values is undefined behavior.");
}
}

Expand Down
Loading