Commit fca05f57 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

cli stub

parent 989b8755
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11,5 +11,6 @@ test:

clean:
	(cd build/cmake && make clean)
	rm -rf build/test/tmp*

.PHONY: all test clean
+8 −0
Original line number Diff line number Diff line
@@ -46,6 +46,10 @@ set(FNORDMETRIC_QUERY_SOURCES
    stage/src/fnordmetric/query/token.cc
    stage/src/fnordmetric/query/tokenize.cc)

set(FNORDMETRIC_CLI_SOURCES
    ${FNORDMETRIC_QUERY_SOURCES}
    stage/src/fnordmetric/cli/cli.cc)

include_directories(stage/src)
set(CMAKE_CXX_FLAGS "-std=c++0x -stdlib=libc++")

@@ -60,6 +64,10 @@ add_executable(tests/test-ui
    ${FNORDMETRIC_UI_SOURCES}
    stage/src/fnordmetric/ui/ui_test.cc)

add_executable(tests/test-cli
    ${FNORDMETRIC_CLI_SOURCES}
    stage/src/fnordmetric/cli/cli_test.cc)

add_executable(tests/test-input-stream
    ${FNORDMETRIC_SOURCES}
    stage/src/fnordmetric/util/inputstream_test.cc)

src/cli/cli.cc

0 → 100644
+34 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * Licensed under the MIT license (see LICENSE).
 */
#include <vector>
#include <string>
#include <fnordmetric/cli/cli.h>
#include <fnordmetric/util/inputstream.h>
#include <fnordmetric/util/outputstream.h>
#include <fnordmetric/util/runtimeexception.h>

namespace fnordmetric {
namespace cli {

void CLI::execute(std::vector<std::string> args) {
  std::unique_ptr<util::InputStream> input;

  switch (args.size()) {
    case 0:
      input = std::move(util::InputStream::getStdin());
      break;
    case 1:
      input = std::move(util::FileInputStream::openFile(args[0]));
      break;
    default:
      RAISE(UsageError);
  }

}

}
}

src/cli/cli.h

0 → 100644
+31 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * Licensed under the MIT license (see LICENSE).
 */
#ifndef _FNORDMETRIC_CLI_H
#define _FNORDMETRIC_CLI_H
#include <fnordmetric/util/runtimeexception.h>

namespace fnordmetric {
namespace cli {

class CLI {
public:
  struct UsageError : public fnordmetric::util::RuntimeException {
    UsageError() : RuntimeException("usage error") {}
  };

  /**
   * Execute a command line
   *
   * May throw an exception!
   */
  static void execute(std::vector<std::string> args);
}
;

}
}
#endif

src/cli/cli_test.cc

0 → 100644
+31 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2014 Paul Asmuth, Google Inc.
 *
 * Licensed under the MIT license (see LICENSE).
 */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fnordmetric/util/unittest.h>
#include <fnordmetric/cli/cli.h>

using namespace fnordmetric::cli;

UNIT_TEST(CLITest);

static fnordmetric::util::UnitTest::TestCase __test_simple_sql_to_svg_(
    &CLITest, "TestSimpleSQLToSVG", [] () {
  std::vector<std::string> args = {
    "test/fixtures/gdp_bar_chart.sql",
    "-f", "svg",
    "-o", "build/test/tmp/CLITest_TestSimpleSQLToSVG_out.svg.html"
  };

  CLI::execute(args);

  EXPECT_FILES_EQ(
    "test/fixtures/CLITest_TestSimpleSQLToSVG_out.svg.html",
    "build/test/tmp/CLITest_TestSimpleSQLToSVG_out.svg.html");
});
Loading