Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,32 @@ int main(void) {

/* 注册文件系统命令 */
shellRegister("mkfile", doMkfile,
"mkfile <path> <size>\nCreate a file with given size");
shellRegister("mkdir", doMkdir, "mkdir <path>\nCreate a subdirectory");
shellRegister("rm", doRm, "rm <path>\nDelete a file");
UNDERLINE "mkfile <path> <size>\n" COLOR_RESET
"Create a file with given size");
shellRegister("mkdir", doMkdir,
UNDERLINE "mkdir <path>\n" COLOR_RESET "Create a subdirectory");
shellRegister("rm", doRm,
UNDERLINE "rm <path>\n" COLOR_RESET "Delete a file");
shellRegister("rmdir", doRmdir,
"rmdir <path>\nDelete a subdirectory (must be empty)");
shellRegister("ls", doLs, "ls [path]\nList directory contents");
shellRegister("open", doOpen, "open <path>\nOpen a file, returns fd");
shellRegister("close", doClose, "close <fd>\nClose a file by fd");
shellRegister("read", doRead, "read <path> <size>\nRead from file and print");
shellRegister("write", doWrite, "write <path> <data>\nWrite data to file");
shellRegister("df", doDf, "df\nShow disk usage statistics");
shellRegister("viz", doViz, "viz\nToggle visualization on/off");
UNDERLINE "rmdir <path>\n" COLOR_RESET
"Delete a subdirectory (must be empty)");
shellRegister("ls", doLs,
UNDERLINE "ls [path]\n" COLOR_RESET "List directory contents");
shellRegister("open", doOpen,
UNDERLINE "open <path>\n" COLOR_RESET
"Open a file, returns fd");
shellRegister("close", doClose,
UNDERLINE "close <fd>\n" COLOR_RESET "Close a file by fd");
shellRegister("read", doRead,
UNDERLINE "read <path> <size>\n" COLOR_RESET
"Read from file and print");
shellRegister("write", doWrite,
UNDERLINE "write <path> <data>\n" COLOR_RESET
"Write data to file");
shellRegister("df", doDf,
UNDERLINE "df\n" COLOR_RESET "Show disk usage statistics");
shellRegister("viz", doViz,
UNDERLINE "viz\n" COLOR_RESET "Toggle visualization on/off");

/* 初始化 Shell */
if (shellInit("root") != 0) {
Expand Down
14 changes: 9 additions & 5 deletions src/shell.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "shell.h"
#include "common.h"
#include "log.h"
#include <errno.h>
#include <stdio.h>
Expand Down Expand Up @@ -186,10 +187,14 @@ int shellInit(char *username) {
return EXIT_FAILURE;
}

shellRegister("echo", doEcho, "echo <text> \nEcho what you input");
shellRegister("help", doHelp, "help <command> \nShow helptext of command");
shellRegister("echo", doEcho,
UNDERLINE "echo <text> \n" COLOR_RESET "Echo what you input");
shellRegister("help", doHelp,
UNDERLINE "help <command> \n" COLOR_RESET
"Show helptext of command");
shellRegister("exit", doExit,
"exit <exitcode>\nExit shell with <code(default=0)>");
UNDERLINE "exit <exitcode>\n" COLOR_RESET
"Exit shell with <code(default=0)>");

return 0;
}
Expand Down Expand Up @@ -257,7 +262,7 @@ static int doHelp(int argc, char **argv) {
if (argc == 1) {
for (int idx = 0; idx < CMDSIZE_MAX; idx++) {
if (cmdBucket[idx].occupied == 1) {
printf("%s\n", cmdBucket[idx].help);
printf("%s\n\n", cmdBucket[idx].help);
}
}
}
Expand All @@ -270,7 +275,6 @@ static int doHelp(int argc, char **argv) {
goto err;
}

printf("%s\n", cmdBucket[idx].help);
return 0;

err:
Expand Down
Loading