added external parser logic
This commit is contained in:
1850
Cargo.lock
generated
1850
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ deno_core = { version = "0.385.0", optional = true }
|
|||||||
flume = "0.12.0"
|
flume = "0.12.0"
|
||||||
futures = "0.3.32"
|
futures = "0.3.32"
|
||||||
mize = { path = "../mize/", default-features = false }
|
mize = { path = "../mize/", default-features = false }
|
||||||
|
rustyscript = "0.12.3"
|
||||||
tokio = "1.49.0"
|
tokio = "1.49.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
431
packages/marts/c2vi/deno.ts
Normal file
431
packages/marts/c2vi/deno.ts
Normal file
@@ -0,0 +1,431 @@
|
|||||||
|
import { createClient } from "@libsql/client";
|
||||||
|
import { drizzle } from "drizzle-orm/libsql";
|
||||||
|
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import fs from "node:fs";
|
||||||
|
import path from "node:path";
|
||||||
|
import os from "node:os";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
|
||||||
|
export async function init(ppc: PPC) {
|
||||||
|
ppc.c2vi = new C2vi(ppc);
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("bed", "command to run when c2vi goes to bed")
|
||||||
|
.action(async () => {
|
||||||
|
await save_habitica_dailies(ppc);
|
||||||
|
await save_habitica_logs(ppc);
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("clearTodos", "command to run when c2vi goes to bed")
|
||||||
|
.alias("clt")
|
||||||
|
.action(async () => {
|
||||||
|
const todos = await ppc.habitica.get_tasks();
|
||||||
|
for (const todo of todos) {
|
||||||
|
await ppc.habitica.delete_task(todo.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("listTodos", "command to run when c2vi goes to bed")
|
||||||
|
.alias("dut")
|
||||||
|
.action(async () => {
|
||||||
|
const todos = await ppc.habitica.get_tasks();
|
||||||
|
for (const todo of todos) {
|
||||||
|
console.log(todo.text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("buyHealthPotion", "command to run when c2vi goes to bed")
|
||||||
|
.alias("buyh")
|
||||||
|
.action(async () => {
|
||||||
|
await ppc.habitica.api_request("POST", "/user/buy-health-potion");
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("addActionItems", "command to run when c2vi goes to bed")
|
||||||
|
.alias("aal")
|
||||||
|
.action(async () => {
|
||||||
|
await add_action_items(ppc);
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("test", "a command to run some test code")
|
||||||
|
.alias("t")
|
||||||
|
.action(async () => {});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("skip [num]", "command to skip a habitica todo")
|
||||||
|
.alias("sk")
|
||||||
|
.action((num = 1) => {
|
||||||
|
skip_habitica_todo(ppc, parseInt(num));
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli.command("dumpLog", "dump the complete habitica log").action(() => {
|
||||||
|
dump_habitica_logs(ppc);
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("listDailies", "list all dailies")
|
||||||
|
.action(async (folder, options) => {
|
||||||
|
const allDailies = await ppc.c2vi.db.select().from(dailiesTable).all();
|
||||||
|
for (const task of allDailies) {
|
||||||
|
console.log(task.id + ": " + task.text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ppc.cli
|
||||||
|
.command("printTask <id>", "print a specific todo")
|
||||||
|
.action(async (id) => {
|
||||||
|
const data = await ppc.habitica.api_request("GET", `/tasks/${id}`, {});
|
||||||
|
console.log(data.history);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class C2vi {
|
||||||
|
[key: string]: any;
|
||||||
|
|
||||||
|
constructor(ppc: PPC) {
|
||||||
|
this.ppc = ppc;
|
||||||
|
this.db = drizzle(
|
||||||
|
createClient({
|
||||||
|
url: "file://" + ppc.config.local_storage_path + "/data.db",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(d) {
|
||||||
|
const pad = (n) => n.toString().padStart(2, "0");
|
||||||
|
|
||||||
|
// Custom YYYY-MM-DD format
|
||||||
|
const formatted = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||||
|
return formatted;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============= SCHEMA DEFINITION =============
|
||||||
|
const dailiesTable = sqliteTable("habitica_dailies", {
|
||||||
|
id: text("id").primaryKey(),
|
||||||
|
text: text("text").notNull(),
|
||||||
|
notes: text("notes"),
|
||||||
|
priority: text("priority"), // 0.1, 1, 1.5, 2
|
||||||
|
frequency: text("frequency"), // 'daily', 'weekly', etc.
|
||||||
|
});
|
||||||
|
const habiticaLogTable = sqliteTable("habitica_log", {
|
||||||
|
date: text("date").primaryKey(),
|
||||||
|
data: text("data").notNull(),
|
||||||
|
});
|
||||||
|
|
||||||
|
async function save_habitica_dailies(ppc) {
|
||||||
|
console.log("######### cli bed cmd #########");
|
||||||
|
await ppc.c2vi.db.run(
|
||||||
|
"CREATE TABLE IF NOT EXISTS habitica_dailies (id TEXT PRIMARY KEY, text TEXT NOT NULL, notes TEXT, priority TEXT, frequency TEXT)",
|
||||||
|
);
|
||||||
|
await ppc.c2vi.db.run(
|
||||||
|
"CREATE TABLE IF NOT EXISTS habitica_log (date TEXT PRIMARY KEY, data TEXT NOT NULL)",
|
||||||
|
);
|
||||||
|
|
||||||
|
// ============= DATABASE INITIALIZATION =============
|
||||||
|
if (!ppc.config.habitica.user_id || !ppc.config.habitica.api_token) {
|
||||||
|
console.error(
|
||||||
|
"Error: HABITICA_USER_ID and HABITICA_API_TOKEN env vars required",
|
||||||
|
);
|
||||||
|
console.error(
|
||||||
|
"Get these from Habitica Settings > API and configure them in the ppc.config",
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const dailies = await ppc.habitica.get_tasks("dailys");
|
||||||
|
|
||||||
|
await writeDailiesToDatabase(dailies, ppc);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function dump_habitica_logs(ppc) {
|
||||||
|
const entries = await ppc.c2vi.db.select().from(habiticaLogTable).all();
|
||||||
|
for (const entry of entries) {
|
||||||
|
console.log(entry.date + ": ", JSON.parse(entry.data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function skip_habitica_todo(ppc, num) {
|
||||||
|
await ppc.c2vi.db.run(
|
||||||
|
"CREATE TABLE IF NOT EXISTS habitica_dailies (id TEXT PRIMARY KEY, text TEXT NOT NULL, notes TEXT, priority TEXT, frequency TEXT)",
|
||||||
|
);
|
||||||
|
await ppc.c2vi.db.run(
|
||||||
|
"CREATE TABLE IF NOT EXISTS habitica_log (date TEXT PRIMARY KEY, data TEXT NOT NULL)",
|
||||||
|
);
|
||||||
|
|
||||||
|
const todos = await ppc.habitica.get_tasks("todos");
|
||||||
|
|
||||||
|
const date = new Date();
|
||||||
|
const save_for_yesterday = date.getHours() < 12;
|
||||||
|
if (save_for_yesterday) {
|
||||||
|
console.log(
|
||||||
|
"Saving logs for yesterday!!!! because it is " +
|
||||||
|
date.getHours() +
|
||||||
|
"hours of the day",
|
||||||
|
);
|
||||||
|
date.setDate(date.getDate() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await ppc.c2vi.db
|
||||||
|
.select()
|
||||||
|
.from(habiticaLogTable)
|
||||||
|
.where(eq(habiticaLogTable.date, formatDate(date)));
|
||||||
|
|
||||||
|
const data = result[0]
|
||||||
|
? JSON.parse(result[0].data)
|
||||||
|
: {
|
||||||
|
dailies_done: [],
|
||||||
|
dailies_skipped: [],
|
||||||
|
todos_done: [],
|
||||||
|
todos_skipped: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 0; i < num; i++) {
|
||||||
|
const todo = todos[i];
|
||||||
|
if (!todo) continue;
|
||||||
|
await ppc.habitica.delete_task(todo.id);
|
||||||
|
await incrementHabit(ppc);
|
||||||
|
|
||||||
|
data.todos_skipped.push({
|
||||||
|
id: todo.id,
|
||||||
|
text: todo.text,
|
||||||
|
notes: todo.notes || "",
|
||||||
|
checklist: todo.checklist || [],
|
||||||
|
tags: todo.tags || [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// saving to db
|
||||||
|
await ppc.c2vi.db
|
||||||
|
.insert(habiticaLogTable)
|
||||||
|
.values({ date: formatDate(date), data: JSON.stringify(data) })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: habiticaLogTable.date,
|
||||||
|
set: {
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save_habitica_logs(ppc) {
|
||||||
|
const date = new Date();
|
||||||
|
const save_for_yesterday = date.getHours() < 12;
|
||||||
|
if (save_for_yesterday) {
|
||||||
|
console.log(
|
||||||
|
"Saving logs for yesterday!!!! because it is " +
|
||||||
|
date.getHours() +
|
||||||
|
"hours of the day",
|
||||||
|
);
|
||||||
|
date.setDate(date.getDate() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await ppc.c2vi.db
|
||||||
|
.select()
|
||||||
|
.from(habiticaLogTable)
|
||||||
|
.where(eq(habiticaLogTable.date, formatDate(date)));
|
||||||
|
|
||||||
|
const data = result[0]
|
||||||
|
? JSON.parse(result[0].data)
|
||||||
|
: {
|
||||||
|
dailies_done: [],
|
||||||
|
dailies_skipped: [],
|
||||||
|
todos_done: [],
|
||||||
|
todos_skipped: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// dailies
|
||||||
|
const dailies = await ppc.habitica.get_tasks("dailys");
|
||||||
|
for (const daily of dailies) {
|
||||||
|
let completed = daily.completed;
|
||||||
|
let isDue = daily.isDue;
|
||||||
|
if (save_for_yesterday) {
|
||||||
|
const yesterday = daily.history.reduce((prev, current) => {
|
||||||
|
return prev.date > current.date ? prev : current;
|
||||||
|
});
|
||||||
|
completed = yesterday.completed;
|
||||||
|
isDue = yesterday.isDue;
|
||||||
|
}
|
||||||
|
if (!isDue) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (completed) {
|
||||||
|
data.dailies_done.push(daily.id);
|
||||||
|
console.log("daily-done: " + daily.text);
|
||||||
|
} else {
|
||||||
|
data.dailies_skipped.push(daily.id);
|
||||||
|
console.log("daily-skipped: " + daily.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// todos done
|
||||||
|
const todos = await ppc.habitica.get_tasks("completedTodos");
|
||||||
|
for (const todo of todos) {
|
||||||
|
const dateCompleted = new Date(todo.dateCompleted);
|
||||||
|
|
||||||
|
// check if this todo is already saved in yesterday's log entry
|
||||||
|
if (save_for_yesterday) {
|
||||||
|
// get yesterday log entry
|
||||||
|
const result = await ppc.c2vi.db
|
||||||
|
.select()
|
||||||
|
.from(habiticaLogTable)
|
||||||
|
.where(eq(habiticaLogTable.date, formatDate(date)));
|
||||||
|
|
||||||
|
const data = result[0]
|
||||||
|
? JSON.parse(result[0].data)
|
||||||
|
: {
|
||||||
|
dailies_done: [],
|
||||||
|
dailies_skipped: [],
|
||||||
|
todos_done: [],
|
||||||
|
todos_skipped: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// check if this todo is already saved in yesterday's log entry
|
||||||
|
const todoIndex = data.todos_done.findIndex((t) => t.id === todo.id);
|
||||||
|
if (todoIndex !== -1) {
|
||||||
|
continue; // skipp saving this todo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateCompleted.toDateString() == date.toDateString()) {
|
||||||
|
console.log("todo-done:", todo.text);
|
||||||
|
data.todos_done.push({
|
||||||
|
id: todo.id,
|
||||||
|
text: todo.text,
|
||||||
|
notes: todo.notes || "",
|
||||||
|
checklist: todo.checklist || [],
|
||||||
|
tags: todo.tags || [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// we save_for_yesterday but the todo was completed today... also save that for this day
|
||||||
|
if (
|
||||||
|
save_for_yesterday &&
|
||||||
|
dateCompleted.toDateString() == new Date().toDateString()
|
||||||
|
) {
|
||||||
|
console.log("todo-done:", todo.text);
|
||||||
|
data.todos_done.push({
|
||||||
|
id: todo.id,
|
||||||
|
text: todo.text,
|
||||||
|
notes: todo.notes || "",
|
||||||
|
checklist: todo.checklist || [],
|
||||||
|
tags: todo.tags || [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// saving to db
|
||||||
|
await ppc.c2vi.db
|
||||||
|
.insert(habiticaLogTable)
|
||||||
|
.values({ date: formatDate(date), data: JSON.stringify(data) })
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: habiticaLogTable.date,
|
||||||
|
set: {
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function writeDailiesToDatabase(dailies, ppc) {
|
||||||
|
console.log(`Syncing ${dailies.length} dailies to database...`);
|
||||||
|
|
||||||
|
const records = dailies.map((daily) => ({
|
||||||
|
id: daily.id,
|
||||||
|
text: daily.text,
|
||||||
|
notes: daily.notes || "",
|
||||||
|
priority: daily.priority?.toString() || null,
|
||||||
|
frequency: daily.frequency || "daily",
|
||||||
|
}));
|
||||||
|
|
||||||
|
async function upsertMany(records) {
|
||||||
|
for (const record of records) {
|
||||||
|
await ppc.c2vi.db
|
||||||
|
.insert(dailiesTable)
|
||||||
|
.values(record)
|
||||||
|
.onConflictDoUpdate({
|
||||||
|
target: dailiesTable.id,
|
||||||
|
set: {
|
||||||
|
text: record.text,
|
||||||
|
notes: record.notes,
|
||||||
|
priority: record.priority,
|
||||||
|
frequency: record.frequency,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await upsertMany(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function incrementHabit(ppc) {
|
||||||
|
const habits = await ppc.habitica.get_tasks("habits");
|
||||||
|
let id = "";
|
||||||
|
for (const habit of habits) {
|
||||||
|
if ((habit.text = "skipped a planned task")) {
|
||||||
|
id = habit.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await ppc.habitica.api_request("POST", `tasks/${id}/score/down`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function add_action_items(ppc: PPC) {
|
||||||
|
let task_ids = [];
|
||||||
|
|
||||||
|
const tmpFile = path.join(os.tmpdir(), `habitica-tasks-${Date.now()}.md`);
|
||||||
|
const initialContent = `
|
||||||
|
gu 10min TIMER
|
||||||
|
uw 15min FROG
|
||||||
|
b coffee/tee/kakau
|
||||||
|
uw FROG
|
||||||
|
b breakfast, brush teeth, lüften
|
||||||
|
uw FROG
|
||||||
|
|
||||||
|
lunch
|
||||||
|
|
||||||
|
uw 15min TIMER of next days FROG
|
||||||
|
fw
|
||||||
|
dt 30min TIMER
|
||||||
|
|
||||||
|
fun 20:00 (smth that can be stopped easily)
|
||||||
|
se 21:40
|
||||||
|
read
|
||||||
|
bed 22:10
|
||||||
|
`;
|
||||||
|
|
||||||
|
fs.writeFileSync(tmpFile, initialContent.trim());
|
||||||
|
|
||||||
|
spawnSync("nvim", [tmpFile], { stdio: "inherit" });
|
||||||
|
|
||||||
|
// read file
|
||||||
|
const listStr = fs.readFileSync(tmpFile, "utf8");
|
||||||
|
|
||||||
|
// delete file
|
||||||
|
fs.unlinkSync(tmpFile);
|
||||||
|
|
||||||
|
// Simple parser: filter out empty lines
|
||||||
|
const tasks = listStr
|
||||||
|
.split("\n")
|
||||||
|
.map((t) => t.trim())
|
||||||
|
.filter((t) => t.length > 0);
|
||||||
|
|
||||||
|
// 5. Add tasks to Habitica
|
||||||
|
for (const todoText of tasks) {
|
||||||
|
const data = await ppc.habitica.api_request(
|
||||||
|
"POST",
|
||||||
|
"tasks/user",
|
||||||
|
{},
|
||||||
|
{ text: todoText, type: "todo" },
|
||||||
|
);
|
||||||
|
task_ids.push(data.id);
|
||||||
|
console.log(`Added to-do: '${todoText}' with id '${data.id}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Move tasks to bottom
|
||||||
|
for (const taskId of task_ids) {
|
||||||
|
await ppc.habitica.api_request("POST", `tasks/${taskId}/move/to/-1`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,26 +9,53 @@ pub struct CliPart {
|
|||||||
mize: Mize,
|
mize: Mize,
|
||||||
cmd: Option<Command>,
|
cmd: Option<Command>,
|
||||||
actions: HashMap<String, fn(&ArgMatches) -> MizeResult<()>>,
|
actions: HashMap<String, fn(&ArgMatches) -> MizeResult<()>>,
|
||||||
|
parsers: Option<Vec<Box<dyn (FnOnce(Mize, Vec<String>) -> MizeResult<()>) + Send + Sync>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cli(mize: &mut Mize) -> MizeResult<()> {
|
pub fn cli(mize: &mut Mize) -> MizeResult<()> {
|
||||||
|
let command = Command::new("marts-cli").allow_external_subcommands(true);
|
||||||
let cli_part = CliPart {
|
let cli_part = CliPart {
|
||||||
mize: mize.clone(),
|
mize: mize.clone(),
|
||||||
cmd: Some(Command::new("marts-cli")),
|
cmd: Some(command),
|
||||||
actions: HashMap::new(),
|
actions: HashMap::new(),
|
||||||
|
parsers: Some(Vec::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
mize.register_part(Box::new(cli_part))
|
mize.add_part(Box::new(cli_part))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MizePart for CliPart {
|
impl MizePart for CliPart {
|
||||||
fn init(&mut self, _mize: &mut Mize) -> MizeResult<()> {
|
fn init(&mut self, _mize: &mut Mize) -> MizeResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn run(&mut self, _mize: &mut Mize) -> MizeResult<()> {
|
fn run(&mut self, mize: &mut Mize) -> MizeResult<()> {
|
||||||
let matches = self.cmd.take().unwrap().get_matches();
|
let matches = self.cmd.take().unwrap().get_matches();
|
||||||
let sub_cmd = matches.subcommand_name().unwrap();
|
let sub_cmd = match matches.subcommand_name() {
|
||||||
let action = self.actions.get(sub_cmd).unwrap();
|
Some(sub_cmd) => sub_cmd,
|
||||||
|
None => {
|
||||||
|
println!("No subcommand provided");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let action = match self.actions.get(sub_cmd) {
|
||||||
|
Some(action) => action,
|
||||||
|
None => {
|
||||||
|
// external parsers
|
||||||
|
for parser in self.parsers.take().unwrap() {
|
||||||
|
parser(
|
||||||
|
mize.clone(),
|
||||||
|
matches
|
||||||
|
.subcommand_matches(sub_cmd)
|
||||||
|
.unwrap()
|
||||||
|
.get_many::<String>("")
|
||||||
|
.unwrap()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.collect::<Vec<String>>(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
};
|
||||||
action(matches.subcommand_matches(sub_cmd).unwrap())?;
|
action(matches.subcommand_matches(sub_cmd).unwrap())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -49,6 +76,15 @@ impl CliPart {
|
|||||||
self.cmd = Some(cmd);
|
self.cmd = Some(cmd);
|
||||||
self.cmd.as_mut().unwrap()
|
self.cmd.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
|
pub fn add_sub_parser<
|
||||||
|
T: FnOnce(Mize, Vec<String>) -> MizeResult<()> + Send + Sync + 'static,
|
||||||
|
>(
|
||||||
|
&mut self,
|
||||||
|
parser: T,
|
||||||
|
) -> MizeResult<()> {
|
||||||
|
self.parsers.as_mut().unwrap().push(Box::new(parser));
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
pub fn with_cmd(
|
pub fn with_cmd(
|
||||||
&mut self,
|
&mut self,
|
||||||
func: fn(mize: Mize, cmd: Command) -> MizeResult<Command>,
|
func: fn(mize: Mize, cmd: Command) -> MizeResult<Command>,
|
||||||
|
|||||||
@@ -8,3 +8,8 @@ export class Mize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MizeError = string;
|
type MizeError = string;
|
||||||
|
|
||||||
|
export class Cli {
|
||||||
|
constructor(mize: Mize) {}
|
||||||
|
async sub_command(name: string, cmd: any): Promise<void> {}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
|
use mize::MizeResult;
|
||||||
|
|
||||||
#[cfg(feature = "target-os")]
|
#[cfg(feature = "target-os")]
|
||||||
mod cli;
|
mod cli;
|
||||||
#[cfg(feature = "target-os")]
|
#[cfg(feature = "target-os")]
|
||||||
pub use cli::cli;
|
pub use cli::*;
|
||||||
|
|
||||||
mod js;
|
pub mod js;
|
||||||
|
pub use js::*;
|
||||||
|
|
||||||
#[cfg(feature = "target-os")]
|
#[cfg(feature = "target-os")]
|
||||||
pub fn habitica(mize: &mut mize::Mize) {
|
pub fn habitica(mize: &mut mize::Mize) -> MizeResult<()> {
|
||||||
use deno_core::{ascii_str_include, include_js_files};
|
use deno_core::ascii_str_include;
|
||||||
|
|
||||||
js::part_from_file(
|
js::part_from_file(
|
||||||
mize,
|
mize,
|
||||||
"habitica",
|
"habitica",
|
||||||
ascii_str_include!("./deno_dist/habitica.js"),
|
ascii_str_include!("./deno_dist/habitica.js"),
|
||||||
);
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -315,6 +315,9 @@ impl Mize {
|
|||||||
None => Err(mize_err!("Part not found or currently taken")),
|
None => Err(mize_err!("Part not found or currently taken")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn has_part(&mut self, name: &str) -> bool {
|
||||||
|
self.parts.lock().unwrap().contains_key(name)
|
||||||
|
}
|
||||||
pub fn add_part(&mut self, part: Box<dyn MizePart + Send + Sync>) -> MizeResult<()> {
|
pub fn add_part(&mut self, part: Box<dyn MizePart + Send + Sync>) -> MizeResult<()> {
|
||||||
self.part_names.lock().unwrap().push(part.name());
|
self.part_names.lock().unwrap().push(part.name());
|
||||||
self.parts.lock().unwrap().insert(part.name(), Some(part));
|
self.parts.lock().unwrap().insert(part.name(), Some(part));
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ fn main() {
|
|||||||
#[cfg(feature = "target-os")]
|
#[cfg(feature = "target-os")]
|
||||||
fn os_main(mize: &mut Mize) -> MizeResult<()> {
|
fn os_main(mize: &mut Mize) -> MizeResult<()> {
|
||||||
marts::cli(mize)?;
|
marts::cli(mize)?;
|
||||||
|
marts::js(mize)?;
|
||||||
|
marts::habitica(mize)?;
|
||||||
|
|
||||||
let mut cli = mize.get_part_native::<marts::CliPart>("cli")?;
|
let mut cli = mize.get_part_native::<marts::CliPart>("cli")?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user