BashSpark
Loading...
Searching...
No Matches
shell_arg.h
Go to the documentation of this file.
1
29#pragma once
30
31#include <memory>
32#include <string>
33#include <vector>
34
35namespace bs {
42 class shell_arg {
43 public:
45 shell_arg() = default;
46
51 explicit shell_arg(std::vector<std::string> &&vArgVariables)
52 : m_vArgVariables(std::move(vArgVariables)) {
53 }
54
55 public:
61 [[nodiscard]] std::string get_arg(const std::size_t nArg) const {
62 return nArg < this->m_vArgVariables.size() ? m_vArgVariables.at(nArg) : "";
63 }
64
70 [[nodiscard]] bool has_arg(const std::size_t nArg) const noexcept {
71 return nArg < this->m_vArgVariables.size();
72 }
73
78 [[nodiscard]] std::size_t get_arg_size() const noexcept {
79 return this->m_vArgVariables.size();
80 }
81
86 [[nodiscard]] const std::vector<std::string> &get_args() const noexcept {
87 return this->m_vArgVariables;
88 }
89
90 private:
92 std::vector<std::string> m_vArgVariables;
93 };
94} // namespace bs
Represents a command line argument list for shell commands.
Definition shell_arg.h:42
bool has_arg(const std::size_t nArg) const noexcept
Checks if a command-line argument exists at the given index.
Definition shell_arg.h:70
shell_arg(std::vector< std::string > &&vArgVariables)
Constructs an shell_arg object with command-line arguments.
Definition shell_arg.h:51
const std::vector< std::string > & get_args() const noexcept
Retrieves all command-line arguments.
Definition shell_arg.h:86
std::size_t get_arg_size() const noexcept
Gets the number of command-line arguments.
Definition shell_arg.h:78
std::string get_arg(const std::size_t nArg) const
Retrieves a command-line argument by its index.
Definition shell_arg.h:61
shell_arg()=default
Default constructor (no args)
BashSpark main namespace.
Definition command.h:39