refactor(cli)!: renamed status command to files and changed directory structure for the .merk dir
This commit is contained in:
parent
483cb08a83
commit
e52740a03b
2 changed files with 26 additions and 6 deletions
|
|
@ -8,6 +8,7 @@
|
|||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "file.h"
|
||||
#include "action_list.h"
|
||||
|
|
|
|||
31
src/main.c
31
src/main.c
|
|
@ -12,7 +12,11 @@
|
|||
#include "tree.h"
|
||||
|
||||
static void usage(int exitcode) {
|
||||
printf("usage: merk <command> [<args>]\n\n init Initializes a repository in the current directory\n diff Displays the difference between the given two files\n status Displays a list of modified and untracked files in the repository\n");
|
||||
printf("usage: merk <command> [<args>]\n\
|
||||
\n init Initializes a repository in the current directory\
|
||||
\n diff Displays the difference between the given two files\
|
||||
\n files Displays a list of modified and untracked files in the repository\
|
||||
\n commit Record changes made to the repository\n");
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +27,11 @@ int main(int argc, char **argv) {
|
|||
|
||||
const char* subcmd = argv[1];
|
||||
|
||||
if (strcmp(subcmd, "diff") != 0 && strcmp(subcmd, "init") != 0 && strcmp(subcmd, "status") != 0) {
|
||||
if (strcmp(subcmd, "diff") != 0 &&
|
||||
strcmp(subcmd, "init") != 0 &&
|
||||
strcmp(subcmd, "files") != 0 &&
|
||||
strcmp(subcmd, "commit") != 0
|
||||
) {
|
||||
fprintf(stderr, "ERROR: Unknown subcommand: '%s'\n", subcmd);
|
||||
usage(2);
|
||||
}
|
||||
|
|
@ -48,9 +56,13 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
mkdir(".merk/files", 0700);
|
||||
mkdir(".merk/trees", 0700);
|
||||
mkdir(".merk/branches", 0700);
|
||||
int fd = open(".merk/HEAD", O_WRONLY | O_CREAT, 0666);
|
||||
if (fd < 0) return -1;
|
||||
close(fd);
|
||||
|
||||
mkdir(".merk/objects", 0755);
|
||||
mkdir(".merk/refs", 0755);
|
||||
mkdir(".merk/refs/branches", 0755);
|
||||
}
|
||||
|
||||
// Prints out a visual representation of the diff of the files provided
|
||||
|
|
@ -84,7 +96,7 @@ int main(int argc, char **argv) {
|
|||
else visualize_diff(file1, file2, actions);
|
||||
}
|
||||
// Gives a list of untracked files in the repo
|
||||
else if (strcmp(subcmd, "status") == 0) {
|
||||
else if (strcmp(subcmd, "files") == 0) {
|
||||
if (argc != 2) {
|
||||
printf("ERROR: too many arguments given!\n");
|
||||
printf("Usage: merk status");
|
||||
|
|
@ -110,6 +122,13 @@ int main(int argc, char **argv) {
|
|||
free(root);
|
||||
return 0;
|
||||
}
|
||||
else if (strcmp(subcmd, "commit") == 0) {
|
||||
if (argc == 2) {
|
||||
printf("ERROR: too little arguments given!\n");
|
||||
printf("Usage: merk commit [-m <COMMIT MESSAGE>] <FILE> ...");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
usage(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue