cd fixed and cleaned up. Shell started, needs data fetching code to initialize properly, added the approperiate db_manager file to implement that.
This commit is contained in:
+20
-24
@@ -32,30 +32,26 @@ function main(state: ShellState, __flags: string[], args: string[]): CommandOutp
|
||||
let inode: number;
|
||||
const session = getCurrentSession(state);
|
||||
|
||||
switch (args[0]) {
|
||||
case undefined:
|
||||
inode = session.user.home;
|
||||
break;
|
||||
case "-":
|
||||
inode = session.pwd;
|
||||
break;
|
||||
default:
|
||||
const result = safeResolvePath(state.filesystem, session.cwd, args[0]);
|
||||
if (result.type === "error") {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult(
|
||||
"PathResolutionError",
|
||||
"No such file or directory",
|
||||
{ path: args[0]! },
|
||||
createImmutableBuffer(new Uint8Array()),
|
||||
createImmutableBuffer(new Uint8Array()),
|
||||
COMMAND_NAME,
|
||||
),
|
||||
} satisfies CommandOutput<PathResolutionError>;
|
||||
}
|
||||
inode = result.inode;
|
||||
break;
|
||||
if (args[0] === undefined) {
|
||||
inode = session.user.home;
|
||||
} else if (args[0] === "-") {
|
||||
inode = session.pwd;
|
||||
} else {
|
||||
const result = safeResolvePath(state.filesystem, session.cwd, args[0]);
|
||||
if (result.type === "error") {
|
||||
return {
|
||||
state,
|
||||
result: createErrorResult(
|
||||
"PathResolutionError",
|
||||
"No such file or directory",
|
||||
{ path: args[0]! },
|
||||
createImmutableBuffer(new Uint8Array()),
|
||||
createImmutableBuffer(new Uint8Array()),
|
||||
COMMAND_NAME,
|
||||
),
|
||||
} satisfies CommandOutput<PathResolutionError>;
|
||||
}
|
||||
inode = result.inode;
|
||||
}
|
||||
|
||||
if (state.filesystem.isFile(inode)) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/*
|
||||
Create an interface for the rest of the library to use to fetch nessesary data.
|
||||
To do that, implement a termos config that will contain the table and db names, aswell as other relevant information -
|
||||
maybe a flag for headless mode (uses the built-in console frontend module - need to evaluate this idea more)
|
||||
*/
|
||||
@@ -0,0 +1,49 @@
|
||||
import type { Result } from "@core/result";
|
||||
import { type ShellState } from "@core/shell_state";
|
||||
import type { ShellError } from "@core/util/errors";
|
||||
|
||||
export class Shell {
|
||||
static #instance: Shell;
|
||||
static #promise: Promise<Shell> | null = null;
|
||||
private readonly state: Readonly<ShellState>;
|
||||
|
||||
private constructor(state: ShellState) {
|
||||
this.state = Object.freeze(state);
|
||||
}
|
||||
|
||||
static async init(): Promise<Shell> {
|
||||
if (Shell.#instance) {
|
||||
console.warn("Shell already initialized");
|
||||
return this.#instance;
|
||||
}
|
||||
|
||||
if (Shell.#promise) return Shell.#promise;
|
||||
|
||||
const state; //Create initial shell state,
|
||||
|
||||
Shell.#promise = (async () => {
|
||||
try {
|
||||
Shell.#instance = new Shell();
|
||||
return Shell.#instance;
|
||||
} finally {
|
||||
Shell.#promise = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return Shell.#promise;
|
||||
}
|
||||
|
||||
public async Execute(input: string): Promise<Result<ShellError>> {}
|
||||
|
||||
public get State(): Readonly<ShellState> {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public static get Instance(): Shell | undefined {
|
||||
if (!Shell.#instance) {
|
||||
console.error("Shell has not been initialised yet. Call `await Singleton.init()` first.");
|
||||
return;
|
||||
}
|
||||
return Shell.#instance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user