summaryrefslogtreecommitdiff
path: root/src/cli.cc
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-07-03 19:44:59 -0700
committerFuwn <[email protected]>2022-07-03 19:44:59 -0700
commit9ab0f74aa643dc5d27508e9b2043f0c476f8f928 (patch)
tree28865c9003efc06615258a965b1d766386fb8805 /src/cli.cc
parentfix(cli): initialise padding (diff)
downloadcait-9ab0f74aa643dc5d27508e9b2043f0c476f8f928.tar.xz
cait-9ab0f74aa643dc5d27508e9b2043f0c476f8f928.zip
chore(ninja): rename src_dir
Diffstat (limited to 'src/cli.cc')
-rw-r--r--src/cli.cc147
1 files changed, 0 insertions, 147 deletions
diff --git a/src/cli.cc b/src/cli.cc
deleted file mode 100644
index 573b9a9..0000000
--- a/src/cli.cc
+++ /dev/null
@@ -1,147 +0,0 @@
-// This file is part of Cait <https://github.com/Fuwn/cait>.
-// Copyright (C) 2022-2022 Fuwn <[email protected]>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, version 3.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-//
-// Copyright (C) 2022-2022 Fuwn <[email protected]>
-// SPDX-License-Identifier: GPL-3.0-only
-
-#include <fstream>
-
-#include "cli.hh"
-#include "context.hh"
-#include "help.hh"
-#include "lexer.hh"
-#include "parser.hh"
-#include "utility.hh"
-
-namespace cait {
-
-cli::cli(int argc, char **argv) : _argc(argc), _argv(argv) {
- for (int i = 1; i < _argc; i++) {
- if (_argv[i][0] == '-') {
- std::string key = _argv[i];
- std::string value;
-
- if (i + 1 < _argc) {
- value = _argv[i + 1];
-
- i += 1;
- }
-
- options[key] = value.empty() ? std::nullopt : std::optional(value);
- }
- }
-}
-
-// auto cli::argc() const -> int { return this->_argc; }
-
-// auto cli::argv() const -> char ** { return this->_argv; }
-
-auto cli::arg(int i) -> std::optional<std::string> {
- if (i < this->_argc) {
- return std::string(this->_argv[i]);
- }
-
- return std::nullopt;
-}
-
-auto cli::option(const std::string &key)
- -> std::optional<std::optional<std::string>> {
- if (this->options.contains(key)) {
- return this->options[key];
- }
-
- return std::nullopt;
-}
-
-auto cli::look() -> int {
- switch (cait::utility::hash(this->arg(1).value_or("").c_str())) {
- case cait::utility::hash("--help"):
- case cait::utility::hash("-h"): {
- std::cout << cait::help_message() << '\n';
- } break;
- case cait::utility::hash("--version"): {
- std::cout << version::whole() << '\n';
- } break;
- default: {
- std::string cait_file_name = this->option("-f")->value_or("build.cait");
- std::ifstream cait_file(cait_file_name, std::ios::in);
-
- if (cait_file.is_open()) {
- lexer lexer(cait_file);
- parser parser(lexer.tree());
-
- try {
- parser.generate_nodes(cait_file_name, lexer.lines());
- } catch (const parser_exception &e) {
- std::cout << e.what() << '\n';
-
- return 1;
- }
-
- context context(parser);
-
- for (const auto &token_line : parser.tree()) {
- for (const auto &token : token_line) {
- std::cout << token.word << "(" << token.type.string() << ")";
- }
-
- std::cout << "\n\n";
- }
-
- for (const auto &token_line : parser.nodes()) {
- std::visit(
- [](const auto &node) -> void {
- std::cout << node.string() << '\n';
- },
- token_line);
- }
-
- // auto cc = context.rule("cc");
-
- // if (cc.has_value()) {
- // std::cout << "cc: '" << cc.value().string() << "'\n";
- // } else {
- // std::cout << "cc has no value\n";
- // }
-
- return 0;
- }
-
- std::cout << "cait: error: loading '" << cait_file_name
- << "': The system cannot find "
- "the file specified.\n\n";
-
- return 1;
- } // break;
- }
-
- // auto option = this->option("-h");
-
- // if (option.has_value()) {
- // std::cout << "option exists ";
-
- // if (option->has_value()) {
- // std::cout << "with value " << option->value() << std::endl;
- // } else {
- // std::cout << "with no value\n";
- // }
- // } else {
- // std::cout << "option does not exist\n";
- // }
-
- return 0;
-}
-
-} // namespace cait