Skip to content

Commit

Permalink
Help restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-matsui committed Dec 16, 2023
1 parent 3666529 commit f89fd2e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 18 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(OUT_DIR):
$(OUT_DIR)/Cmd:
mkdir -p $@

$(PROJ_NAME): $(OUT_DIR)/Cmd/Build.o $(OUT_DIR)/Cmd/Test.o $(OUT_DIR)/BuildConfig.o $(OUT_DIR)/Logger.o $(OUT_DIR)/TermColor.o $(OUT_DIR)/main.o
$(PROJ_NAME): $(OUT_DIR)/Cmd/Build.o $(OUT_DIR)/Cmd/Test.o $(OUT_DIR)/Cmd/Run.o $(OUT_DIR)/BuildConfig.o $(OUT_DIR)/Logger.o $(OUT_DIR)/TermColor.o $(OUT_DIR)/main.o
$(CC) $(CFLAGS) $^ -o $@

$(OUT_DIR)/TermColor.o: src/TermColor.cc src/TermColor.hpp
Expand All @@ -44,6 +44,9 @@ $(OUT_DIR)/Cmd/Build.o: src/Cmd/Build.cc src/Cmd/Build.hpp src/Rustify.hpp src/A
$(OUT_DIR)/Cmd/Test.o: src/Cmd/Test.cc src/Cmd/Test.hpp src/Rustify.hpp src/Algos.hpp src/Logger.hpp src/TermColor.hpp
$(CC) $(CFLAGS) -c $< -o $@

$(OUT_DIR)/Cmd/Run.o: src/Cmd/Run.cc src/Cmd/Run.hpp src/Rustify.hpp src/Algos.hpp src/Logger.hpp src/TermColor.hpp
$(CC) $(CFLAGS) -c $< -o $@

$(OUT_DIR)/BuildConfig.o: src/BuildConfig.cc src/BuildConfig.hpp
$(CC) $(CFLAGS) -c $< -o $@

Expand Down
8 changes: 3 additions & 5 deletions src/Cmd/Build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "../BuildConfig.hpp"

#include <cstdlib>
#include <iostream>

int build(Vec<String> args) {
Expand All @@ -11,12 +10,11 @@ int build(Vec<String> args) {
}

void buildHelp() {
std::cout << "poac-build" << '\n';
std::cout << buildDesc << '\n';
std::cout << '\n';
std::cout << "USAGE:" << '\n';
std::cout << " poac build [OPTIONS]" << '\n';
std::cout << "Usage: poac build [OPTIONS]" << '\n';
std::cout << '\n';
std::cout << "OPTIONS:" << '\n';
std::cout << "Options:" << '\n';
std::cout << " -d, --debug\t\tBuild with debug information (default)"
<< '\n';
std::cout << " -r, --release\tBuild with optimizations" << '\n';
Expand Down
3 changes: 3 additions & 0 deletions src/Cmd/Build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

#include "../Rustify.hpp"

static inline constexpr StringRef buildDesc =
"Compile a local package and all of its dependencies";

int build(Vec<String> args);
void buildHelp();
33 changes: 33 additions & 0 deletions src/Cmd/Run.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "Run.hpp"

#include "../BuildConfig.hpp"
#include "../Logger.hpp"

#include <cstdlib>
#include <iostream>

int run(Vec<String> args) {
const String outDir = emitMakefile(args);
const int exitCode = std::system(("make -C " + outDir).c_str());
if (exitCode != EXIT_SUCCESS) {
Logger::error("Build failed with exit code ", exitCode);
return exitCode;
}

const String projectName = "poac"; // TODO: get from poac.toml
return std::system((outDir + "/" + projectName).c_str());
}

void runHelp() {
std::cout << runDesc << '\n';
std::cout << '\n';
std::cout << "Usage: poac run [OPTIONS] [args]..." << '\n';
std::cout << '\n';
std::cout << "Arguments:" << '\n';
std::cout << " [args]...\t\tArguments passed to the program" << '\n';
std::cout << '\n';
std::cout << "Options:" << '\n';
std::cout << " -d, --debug\t\tBuild with debug information (default)"
<< '\n';
std::cout << " -r, --release\tBuild with optimizations" << '\n';
}
8 changes: 8 additions & 0 deletions src/Cmd/Run.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "../Rustify.hpp"

static inline constexpr StringRef runDesc = "Build and execute src/main.cc";

int run(Vec<String> args);
void runHelp();
7 changes: 3 additions & 4 deletions src/Cmd/Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ int test(Vec<String> args) {
}

void testHelp() {
std::cout << "poac-test" << '\n';
std::cout << testDesc << '\n';
std::cout << '\n';
std::cout << "USAGE:" << '\n';
std::cout << " poac test [OPTIONS]" << '\n';
std::cout << "Usage: poac test [OPTIONS]" << '\n';
std::cout << '\n';
std::cout << "OPTIONS:" << '\n';
std::cout << "Options:" << '\n';
std::cout << " -d, --debug\t\tTest with debug information (default)"
<< '\n';
std::cout << " -r, --release\tTest with optimizations" << '\n';
Expand Down
2 changes: 2 additions & 0 deletions src/Cmd/Test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

#include "../Rustify.hpp"

static inline constexpr StringRef testDesc = "Run the tests of a local package";

int test(Vec<String> args);
void testHelp();
17 changes: 9 additions & 8 deletions src/main.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Cmd/Build.hpp"
#include "Cmd/Run.hpp"
#include "Cmd/Test.hpp"
#include "Logger.hpp"
#include "Rustify.hpp"
Expand All @@ -13,28 +14,27 @@ int help(Vec<String> args) {
std::cout << "poac " << POAC_VERSION << '\n';
std::cout << "A package manager and build system for C++" << '\n';
std::cout << '\n';
std::cout << "USAGE:" << '\n';
std::cout << " poac <SUBCOMMAND> [OPTIONS]" << '\n';
std::cout << "Usage: poac [OPTIONS] [COMMAND]" << '\n';
std::cout << '\n';
std::cout << "OPTIONS:" << '\n';
std::cout << "Options:" << '\n';
std::cout << " -v, --version\tPrint version info and exit" << '\n';
std::cout << " --verbose\t\tUse verbose output" << '\n';
std::cout << " -q, --quiet\t\tNo output printed to stdout" << '\n';
std::cout << '\n';
std::cout << "SUBCOMMANDS:" << '\n';
std::cout << "Commands:" << '\n';
std::cout
<< " help\tPrints this message or the help of the given subcommand(s)"
<< '\n';
std::cout
<< " build\tCompile a local package and all of its dependencies"
<< '\n';
std::cout << " test\tRun the tests of a local package" << '\n';
std::cout << " build\t" << buildDesc << '\n';
std::cout << " test\t" << testDesc << '\n';
std::cout << " run\t" << runDesc << '\n';
return EXIT_SUCCESS;
}

HashMap<StringRef, Fn<void()>> helps;
helps["build"] = buildHelp;
helps["test"] = testHelp;
helps["run"] = runHelp;

StringRef subcommand = args[0];
if (helps.count(subcommand) == 0) {
Expand Down Expand Up @@ -79,6 +79,7 @@ int main(int argc, char* argv[]) {
cmds["help"] = help;
cmds["build"] = build;
cmds["test"] = test;
cmds["run"] = run;

StringRef subcommand = args[0];
if (cmds.count(subcommand) == 0) {
Expand Down

0 comments on commit f89fd2e

Please sign in to comment.