- cat added

- touch beginnings
- path resolver now returns a -1 on error
- added a command template file for easier copy-pasting
This commit is contained in:
2026-09-01 05:47:23 +02:00
parent 8e054a220d
commit 2e9227f6d8
7 changed files with 169 additions and 25 deletions
+59
View File
@@ -0,0 +1,59 @@
import type { CommandDescriptor, CommandOutput } from "@core/command";
import type { CommandIO } from "@core/command_io";
import { TreeNodeType } from "@core/filesystem/treenode";
import { createSuccessResult, type ResultSuccess } from "@core/result";
import { getCurrentSession } from "@core/session_manager";
import type { ShellState } from "@core/shell_state";
import type { ShellError } from "@core/util/errors";
import { resolvePath } from "@core/util/path_resolver";
export const COMMAND_NAME = "touch";
//Need to implement escape sequences
async function main(
io: CommandIO,
state: ShellState,
flags: string[],
args: string[],
): Promise<CommandOutput<ShellError>> {
for (const arg of args) {
const inode = resolvePath(state, arg);
const session = getCurrentSession(state);
let newState;
if (inode === -1) {
const index = arg.lastIndexOf("/");
let parentPath;
if (index === -1) {
parentPath = "./";
} else {
parentPath = arg.slice(0, index);
}
const fileName = arg.slice(index + 1);
const parent = resolvePath(state, parentPath);
newState = state.filesystem.createNode(
parent,
fileName,
TreeNodeType.File,
0o644,
session.user.uid,
session.user.gid,
);
} else {
}
}
const result: ResultSuccess = createSuccessResult(COMMAND_NAME);
return {
state: state,
result,
};
}
export const descriptor: CommandDescriptor = {
fn: main,
name: COMMAND_NAME,
};