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:
@@ -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