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:
@@ -32,14 +32,11 @@ function main(state: ShellState, __flags: string[], args: string[]): CommandOutp
|
|||||||
let inode: number;
|
let inode: number;
|
||||||
const session = getCurrentSession(state);
|
const session = getCurrentSession(state);
|
||||||
|
|
||||||
switch (args[0]) {
|
if (args[0] === undefined) {
|
||||||
case undefined:
|
|
||||||
inode = session.user.home;
|
inode = session.user.home;
|
||||||
break;
|
} else if (args[0] === "-") {
|
||||||
case "-":
|
|
||||||
inode = session.pwd;
|
inode = session.pwd;
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
const result = safeResolvePath(state.filesystem, session.cwd, args[0]);
|
const result = safeResolvePath(state.filesystem, session.cwd, args[0]);
|
||||||
if (result.type === "error") {
|
if (result.type === "error") {
|
||||||
return {
|
return {
|
||||||
@@ -55,7 +52,6 @@ function main(state: ShellState, __flags: string[], args: string[]): CommandOutp
|
|||||||
} satisfies CommandOutput<PathResolutionError>;
|
} satisfies CommandOutput<PathResolutionError>;
|
||||||
}
|
}
|
||||||
inode = result.inode;
|
inode = result.inode;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.filesystem.isFile(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