aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp95
1 files changed, 83 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index e3f927f..151e5a5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,13 +11,13 @@ using namespace sibs;
void usage()
{
- printf("Simple build system for native languages\n");
- printf("usage:\n");
- printf(" sibs <project path>\n");
- printf("option:\n");
- printf(" project path: Path containing project.conf\n");
- printf("examples:\n");
- printf(" sibs myProject\n");
+ printf("usage: sibs COMMAND\n\n");
+ printf("Simple Build System for Native Languages\n\n");
+ printf("Options:\n");
+ printf(" -p\t\tPath to project (directory that contains main project.conf file)\n");
+ printf(" -h\t\tPrint this help menu\n\n");
+ printf("Commands:\n");
+ printf(" build\t\tBuild a project that contains a project.conf file\n");
exit(1);
}
@@ -66,12 +66,8 @@ bool isSourceFile(tinydir_file *file)
return false;
}
-int main(int argc, const char **argv)
+void build(string projectPath)
{
- if(argc != 2)
- usage();
-
- string projectPath = argv[1];
validateDirectoryPath(projectPath.c_str());
if(projectPath.back() != '/')
projectPath += "/";
@@ -124,6 +120,81 @@ int main(int argc, const char **argv)
{
exit(8);
}
+}
+
+int main(int argc, const char **argv)
+{
+ string projectPath;
+ string command;
+ for(int i = 1; i < argc; ++i)
+ {
+ const char *arg = argv[i];
+ if(arg[0] == '-')
+ {
+ // Option
+ if(strcmp(arg, "-p") == 0)
+ {
+ if(!projectPath.empty())
+ {
+ printf("-p option defined twice, should only be defined once\n");
+ exit(1);
+ }
+
+ if(i < argc - 1)
+ {
+ projectPath = argv[i + 1];
+ ++i;
+ }
+ else
+ {
+ printf("Expected project path after option -p\n");
+ exit(1);
+ }
+ }
+ else if(strcmp(arg, "-h") == 0)
+ {
+ usage();
+ }
+ else
+ {
+ printf("Invalid option %s, type sibs -h to see valid options\n", arg);
+ exit(1);
+ }
+ }
+ else
+ {
+ if(!command.empty())
+ {
+ printf("Found command twice. First as %s, then as %s\n", command.c_str(), arg);
+ exit(1);
+ }
+ command = arg;
+ }
+ }
+
+ if(projectPath.empty())
+ {
+ Result<string> projectPathResult = getCwd();
+ if(projectPathResult.isErr())
+ {
+ printf("%s\n", projectPathResult.getErrMsg().c_str());
+ exit(11);
+ }
+ projectPath = projectPathResult.unwrap();
+ }
+
+ if(command == "build")
+ build(projectPath);
+ else if(command.empty())
+ {
+ printf("No command provided, type sibs -h to see valid commands\n");
+ exit(1);
+ }
+ else
+ {
+ printf("Invalid command %s, expected: build\n", command.c_str());
+ exit(1);
+ }
return 0;
}