Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(cli): make recovery commands copy-paste safe

Andrej988c945db7ad
diff --git a/packages/cli/src/commands/task/create.ts b/packages/cli/src/commands/task/create.ts
index 25c868306..500e09ae9 100644
--- a/packages/cli/src/commands/task/create.ts
+++ b/packages/cli/src/commands/task/create.ts
@@ -35,6 +35,7 @@ import { renderTaskChange } from "../../tasks/render-task-change.js";
import { resolveAssignee } from "../../tasks/resolve-assignee.js";
import { toTaskDetailJson } from "../../tasks/task-detail-json.js";
import { readTextInput } from "../../input/read-text-input.js";
+import { shellQuote } from "../../input/shell-quote.js";
import { ApiLayer } from "../api-layer.js";
const PRIORITIES = ["no-priority", "low", "medium", "high", "urgent"] as const;
@@ -148,8 +149,7 @@ export const runTaskCreate = Effect.fn("command.task.create")(
const created = yield* withSpinner("Creating task")(
createTask(project.id, body),
);
- const createdLabel =
- ticketId(project.slug, created.number) ?? created.id.slice(0, 8);
+ const createdLabel = ticketId(project.slug, created.number) ?? created.id;
const attached: ReadonlyArray<Label> =
labels.length > 0
? yield* withSpinner("Adding labels")(
@@ -161,7 +161,7 @@ export const runTaskCreate = Effect.fn("command.task.create")(
(error) =>
new InvalidArgument({
message: `Created ${createdLabel}, but could not add the labels: ${describeError(error).message}`,
- hint: `Add them with kaneo task edit ${createdLabel} ${labels.map((label) => `--add-label "${label.name}"`).join(" ")}`,
+ hint: `Add them with kaneo task edit ${shellQuote(createdLabel)} ${labels.map((label) => `--add-label ${shellQuote(label.name)}`).join(" ")}`,
}),
),
)
diff --git a/packages/cli/src/input/shell-quote.test.ts b/packages/cli/src/input/shell-quote.test.ts
new file mode 100644
index 000000000..7cdedc11c
--- /dev/null
+++ b/packages/cli/src/input/shell-quote.test.ts
@@ -0,0 +1,16 @@
+import { describe, expect, it } from "vite-plus/test";
+import { shellQuote } from "./shell-quote.js";
+
+describe("shellQuote", () => {
+ it("leaves simple words alone", () => {
+ expect(shellQuote("Bug")).toBe("Bug");
+ expect(shellQuote("KAN-12")).toBe("KAN-12");
+ });
+
+ it("single quotes anything the shell would interpret", () => {
+ expect(shellQuote('Needs "QA"')).toBe(`'Needs "QA"'`);
+ expect(shellQuote("$(rm -rf ~)")).toBe(`'$(rm -rf ~)'`);
+ expect(shellQuote("it's done")).toBe(`'it'\\''s done'`);
+ expect(shellQuote("")).toBe("''");
+ });
+});
diff --git a/packages/cli/src/input/shell-quote.ts b/packages/cli/src/input/shell-quote.ts
new file mode 100644
index 000000000..6041ca37c
--- /dev/null
+++ b/packages/cli/src/input/shell-quote.ts
@@ -0,0 +1,6 @@
+const SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
+
+export function shellQuote(value: string): string {
+ if (SAFE.test(value)) return value;
+ return `'${value.replaceAll("'", `'\\''`)}'`;
+}
diff --git a/packages/cli/src/relations/link-subtask.ts b/packages/cli/src/relations/link-subtask.ts
index 9551c3b30..132c340b0 100644
--- a/packages/cli/src/relations/link-subtask.ts
+++ b/packages/cli/src/relations/link-subtask.ts
@@ -2,10 +2,11 @@ import { Effect, Option } from "effect";
import { createTaskRelation } from "../api/task-relations.js";
import { describeError } from "../errors/describe.js";
import { InvalidArgument } from "../errors/errors.js";
+import { shellQuote } from "../input/shell-quote.js";
import { withSpinner } from "../output/spinner.js";
import { type ResolvedTask, resolveTask } from "../tasks/resolve-task.js";
import { toApiRelation } from "./relation-types.js";
-import { type TaskRef, taskLabel, taskRef } from "./task-ref.js";
+import { type TaskRef, taskArgument, taskLabel, taskRef } from "./task-ref.js";
export const resolveParent = Effect.fn("relations.resolveParent")(function* (
reference: Option.Option<string>,
@@ -47,7 +48,7 @@ export const linkToParent = Effect.fn("relations.linkToParent")(function* (
(error) =>
new InvalidArgument({
message: `Created ${child.label}, but could not make it a subtask of ${parentLabel}: ${describeError(error).message}`,
- hint: `Link it with kaneo task relation add ${child.label} subtask-of ${parentLabel}`,
+ hint: `Link it with kaneo task relation add ${shellQuote(child.label)} subtask-of ${shellQuote(taskArgument(ref))}`,
}),
),
);
diff --git a/packages/cli/src/relations/task-ref.ts b/packages/cli/src/relations/task-ref.ts
index 918ff3416..11c4ee1c4 100644
--- a/packages/cli/src/relations/task-ref.ts
+++ b/packages/cli/src/relations/task-ref.ts
@@ -19,3 +19,7 @@ export function taskRef(resolved: ResolvedTask): TaskRef {
export function taskLabel(task: TaskRef): string {
return task.ticketId ?? task.id.slice(0, 8);
}
+
+export function taskArgument(task: TaskRef): string {
+ return task.ticketId ?? task.id;
+}