Skip to content

Commit

Permalink
✨ [CommandLineArgs] Added
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFouchy committed Jul 31, 2024
1 parent afb3bfa commit 17fb02b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Cool/CommandLineArgs/CommandLineArgs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "CommandLineArgs.h"

namespace Cool {

void CommandLineArgs::init(int argc, char** argv)
{
for (int i = 1; i < argc; ++i) // Skip the first argument, since we don't care about the path of the executable.
{
_args.emplace_back(argv[i]); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
}
}

} // namespace Cool
20 changes: 20 additions & 0 deletions src/Cool/CommandLineArgs/CommandLineArgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

namespace Cool {

class CommandLineArgs {
public:
[[nodiscard]] auto get() const -> auto const& { return _args; }
void init(int argc, char** argv);

private:
std::vector<std::string> _args{};
};

inline auto command_line_args() -> CommandLineArgs&
{
static auto instance = CommandLineArgs{};
return instance;
}

} // namespace Cool

0 comments on commit 17fb02b

Please sign in to comment.