@apet97/clockify-cli-115 5.0.0 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Command-line interface for [Clockify](https://clockify.me/), built on
4
4
  top of `clockify-sdk-ts-115`.
5
5
 
6
- Current release: `5.0.0`. Requires Node.js `>=22.13.0` and
6
+ Current release: `5.0.2`. Requires Node.js `>=22.13.0` and
7
7
  `clockify-sdk-ts-115 ^5`.
8
8
 
9
9
  Two binaries, identical behavior:
@@ -57,6 +57,9 @@ Rc file shape:
57
57
  }
58
58
  ```
59
59
 
60
+ For each unknown rc-file key, the CLI writes one warning to stderr, names the
61
+ nearest known key, ignores the unknown key, and continues.
62
+
60
63
  Legacy rc files containing `apiKey` are rejected with migration guidance. Remove the secret and
61
64
  set `CLOCKIFY_API_KEY` in the process environment instead.
62
65
 
@@ -73,6 +76,9 @@ touching production credentials.
73
76
  - **`--select <path>`:** print a dot-path (e.g. `--select data.id` or
74
77
  `--select 0.name`) before emitting JSON or NDJSON.
75
78
 
79
+ With `--output ndjson`, the CLI writes each array item as one JSON value on its
80
+ own line, without a wrapping array; a non-array result is one line.
81
+
76
82
  In `json` and `ndjson` modes, errors go to stderr as `{"ok": false, "error":
77
83
  "...", "code": "...", "recovery": "...", "retryable": true|false}`.
78
84
  Successful write commands in JSON and NDJSON include receipt fields:
@@ -7,6 +7,10 @@ const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
7
7
  export const registerApiCommand = (program, services) => {
8
8
  leafCommand(program, "api", "destructive")
9
9
  .description("Call a Clockify API path directly through the SDK client.")
10
+ .addHelpText("after", "\nExamples:\n" +
11
+ " $ clk115 api GET /workspaces/{workspaceId}/tags\n" +
12
+ " $ clk115 api POST /workspaces/{workspaceId}/tags --body '{\"name\":\"focus\"}'\n" +
13
+ " $ clk115 api GET /workspaces/{workspaceId}/projects --all --page-size 100\n")
10
14
  .argument("<method>", "HTTP method: GET, POST, PUT, PATCH, or DELETE.")
11
15
  .argument("<path>", "API path, e.g. /workspaces/{workspaceId}/tags.")
12
16
  .option("-q, --query <key=value>", "Query parameter (repeatable).", collect, [])
@@ -24,6 +24,8 @@ export const registerApprovalsCommand = (program, services) => {
24
24
  const approvals = program.command("approvals").description("Approval requests.");
25
25
  leafCommand(approvals, "submit-with-type", "write")
26
26
  .description("Submit the current user's approval request with an explicit type.")
27
+ .addHelpText("after", "\nExamples:\n" +
28
+ " $ clk115 approvals submit-with-type --type TIMESHEET --period-start 2026-06-01T00:00:00Z\n")
27
29
  .requiredOption("--type <type>", "Approval request type: TIMESHEET or EXPENSE.")
28
30
  .requiredOption("--period-start <date>", "Approval period start (RFC3339).")
29
31
  .option("--period <period>", "Approval period: WEEKLY, SEMI_MONTHLY, or MONTHLY.")
@@ -58,6 +60,9 @@ export const registerApprovalsCommand = (program, services) => {
58
60
  });
59
61
  leafCommand(approvals, "submit-for-user-with-type", "write")
60
62
  .description("Submit another user's approval request with an explicit type.")
63
+ .addHelpText("after", "\nExamples:\n" +
64
+ " $ clk115 approvals submit-for-user-with-type --user user_123 --type TIMESHEET \\\n" +
65
+ " --period-start 2026-06-01T00:00:00Z\n")
61
66
  .requiredOption("--user <id>", "User ID whose approval request is submitted.")
62
67
  .requiredOption("--type <type>", "Approval request type: TIMESHEET, EXPENSE, or TIMESHEET_AND_EXPENSE.")
63
68
  .requiredOption("--period-start <date>", "Approval period start (RFC3339).")
@@ -6,6 +6,8 @@ export const registerAuditLogCommand = (program, services) => {
6
6
  const audit = program.command("audit-log").description("Workspace audit log.");
7
7
  leafCommand(audit, "search", "read")
8
8
  .description("Search the workspace audit log.")
9
+ .addHelpText("after", "\nExamples:\n" +
10
+ " $ clk115 audit-log search --start 2026-06-01 --end 2026-06-30\n")
9
11
  .requiredOption("--start <date>", "Window start (YYYY-MM-DD or RFC3339, e.g. 2026-05-01T00:00:00Z).")
10
12
  .requiredOption("--end <date>", "Window end (YYYY-MM-DD or RFC3339); the server caps the window at 31 days.")
11
13
  .requiredOption("--actions <list>", "Comma-separated action names (e.g. CREATE_PROJECT,UPDATE_PROJECT).")
@@ -18,6 +18,8 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
18
18
  .description("Per-user, per-policy time-off balance assignments.");
19
19
  leafCommand(group, "list", "read")
20
20
  .description("List a user's balance assignments for one policy.")
21
+ .addHelpText("after", "\nExamples:\n" +
22
+ " $ clk115 timeoff balance-assignment list --user user_123 --policy policy_456\n")
21
23
  .requiredOption("--user <id>", "User ID.")
22
24
  .requiredOption("--policy <id>", "Time-off policy ID.")
23
25
  .action(async function (opts) {
@@ -38,6 +40,9 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
38
40
  });
39
41
  leafCommand(group, "create", "write")
40
42
  .description("Add balance for one or more users on a policy. Adds to an existing assignment; creates one when absent.")
43
+ .addHelpText("after", "\nExamples:\n" +
44
+ " $ clk115 timeoff balance-assignment create --policy policy_456 \\\n" +
45
+ " --user user_123 --balance 5\n")
41
46
  .requiredOption("--policy <id>", "Time-off policy ID.")
42
47
  .requiredOption("--user <ids>", "Comma-separated user IDs.")
43
48
  .requiredOption("--balance <amount>", "Balance to add (may be negative).", parseSignedFloatArg)
@@ -79,6 +84,9 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
79
84
  });
80
85
  leafCommand(group, "update", "write")
81
86
  .description("Apply a balance delta to one assignment. The change adds to the current balance.")
87
+ .addHelpText("after", "\nExamples:\n" +
88
+ " $ clk115 timeoff balance-assignment update --id ba_123 --user user_123 \\\n" +
89
+ " --policy policy_456 --change -2\n")
82
90
  .requiredOption("--id <id>", "Balance assignment ID.")
83
91
  .requiredOption("--user <id>", "User ID.")
84
92
  .requiredOption("--policy <id>", "Time-off policy ID.")
@@ -118,6 +126,9 @@ export function registerBalanceAssignmentCommands(timeoff, services) {
118
126
  });
119
127
  leafCommand(group, "delete", "destructive")
120
128
  .description("Delete a balance assignment. The API requires a note.")
129
+ .addHelpText("after", "\nExamples:\n" +
130
+ " $ clk115 timeoff balance-assignment delete --id ba_123 --user user_123 \\\n" +
131
+ " --policy policy_456 --note \"Correcting overage\"\n")
121
132
  .requiredOption("--id <id>", "Balance assignment ID.")
122
133
  .requiredOption("--user <id>", "User ID.")
123
134
  .requiredOption("--policy <id>", "Time-off policy ID.")
@@ -3,6 +3,9 @@ import { printObject, printRecords } from "../output.js";
3
3
  import { printReceipt } from "../receipt.js";
4
4
  import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
5
  import { leafCommand } from "./leaf-command.js";
6
+ function quoteShellArgument(value) {
7
+ return `'${value.replaceAll("'", "'\"'\"'")}'`;
8
+ }
6
9
  function requireClientName(value, source) {
7
10
  if (typeof value !== "string" || value.trim() === "") {
8
11
  throw new Error(`${source} is missing the required client name; refusing to mutate.`);
@@ -52,6 +55,9 @@ export const registerClientsCommand = (program, services) => {
52
55
  const clients = program.command("clients").description("Manage clients.");
53
56
  leafCommand(clients, "list", "read")
54
57
  .description("List clients in the workspace.")
58
+ .addHelpText("after", "\nExamples:\n" +
59
+ " $ clk115 clients list\n" +
60
+ " $ clk115 clients list --name Acme --archived\n")
55
61
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
56
62
  .option("--page <n>", "Page number.", parseIntArg, 1)
57
63
  .option("--name <text>", "Filter by client name substring.")
@@ -83,6 +89,9 @@ export const registerClientsCommand = (program, services) => {
83
89
  .argument("<name>", "Client name.")
84
90
  .option("--note <text>", "Client note.")
85
91
  .description("Create a client in the workspace.")
92
+ .addHelpText("after", "\nExamples:\n" +
93
+ " $ clk115 clients create Acme\n" +
94
+ " $ clk115 clients create Acme --note \"Preferred vendor\"\n")
86
95
  .action(async function (name, opts) {
87
96
  const { client, workspaceId, output } = await resolveContext(this, services);
88
97
  const req = {
@@ -100,7 +109,7 @@ export const registerClientsCommand = (program, services) => {
100
109
  changed: { created: [{ type: "client", id: data.id, name: data.name }] },
101
110
  next: [
102
111
  {
103
- command: `clk115 projects create ${JSON.stringify(`Project for ${data.name}`)} --client ${data.id}`,
112
+ command: `clk115 projects create ${quoteShellArgument(`Project for ${data.name}`)} --client ${quoteShellArgument(data.id)}`,
104
113
  reason: "Create a project for this client.",
105
114
  },
106
115
  ],
@@ -109,6 +118,7 @@ export const registerClientsCommand = (program, services) => {
109
118
  leafCommand(clients, "get", "read")
110
119
  .argument("<id>", "Client ID.")
111
120
  .description("Get one client by ID.")
121
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 clients get client_123\n")
112
122
  .action(async function (id) {
113
123
  const { client, workspaceId, output } = await resolveContext(this, services);
114
124
  const result = await client.clients.get({ workspaceId, clientId: id });
@@ -122,6 +132,9 @@ export const registerClientsCommand = (program, services) => {
122
132
  .option("--archived", "Archive the client.")
123
133
  .option("--no-archived", "Unarchive the client.")
124
134
  .description("Update a client by ID.")
135
+ .addHelpText("after", "\nExamples:\n" +
136
+ " $ clk115 clients update client_123 --name \"New name\"\n" +
137
+ " $ clk115 clients update client_123 --archived\n")
125
138
  .action(async function (id, opts) {
126
139
  const { client, workspaceId, output } = await resolveContext(this, services);
127
140
  const hasChanges = opts.name !== undefined ||
@@ -177,6 +190,7 @@ export const registerClientsCommand = (program, services) => {
177
190
  leafCommand(clients, "delete", "destructive")
178
191
  .argument("<id>", "Client ID.")
179
192
  .description("Delete a client by ID (archives first; an active client cannot be deleted).")
193
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 clients delete client_123\n")
180
194
  .action(async function (id) {
181
195
  const { client, workspaceId, output } = await resolveContext(this, services);
182
196
  await archiveThenDeleteClient({
@@ -8,6 +8,9 @@ const DEFAULT_CLOCKIFY_BASE_URL = "https://api.clockify.me/api/v1";
8
8
  export const registerDoctorCommand = (program, services) => {
9
9
  leafCommand(program, "doctor", "read")
10
10
  .description("Check local CLI configuration without contacting Clockify.")
11
+ .addHelpText("after", "\nExamples:\n" +
12
+ " $ clk115 doctor\n" +
13
+ " $ clk115 doctor --json\n")
11
14
  .action(function () {
12
15
  const root = rootProgram(this);
13
16
  const flags = globalFlags(root);
@@ -7,6 +7,9 @@ export const registerEntriesCommand = (program, services) => {
7
7
  const entries = program.command("entries").description("Manage time entries.");
8
8
  leafCommand(entries, "list", "read")
9
9
  .description("List the current user's time entries.")
10
+ .addHelpText("after", "\nExamples:\n" +
11
+ " $ clk115 entries list --limit 10\n" +
12
+ " $ clk115 entries list --from 2026-06-01 --to 2026-06-30\n")
10
13
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
11
14
  .option("--page <n>", "Page number (default 1).", parseIntArg, 1)
12
15
  .option("--from <date>", "Inclusive start bound (YYYY-MM-DD or RFC3339).")
@@ -49,6 +52,9 @@ export const registerEntriesCommand = (program, services) => {
49
52
  });
50
53
  leafCommand(entries, "get-many", "read")
51
54
  .description("Look up several time entries by ID in one call.")
55
+ .addHelpText("after", "\nExamples:\n" +
56
+ " $ clk115 entries get-many --ids entry_1,entry_2\n" +
57
+ " $ clk115 entries get-many --ids entry_1,entry_2 --hydrated\n")
52
58
  .requiredOption("--ids <ids>", "Comma-separated time-entry IDs.")
53
59
  .option("--hydrated", "Include project, task, and tag detail.", false)
54
60
  .action(async function (opts) {
@@ -75,6 +81,7 @@ export const registerEntriesCommand = (program, services) => {
75
81
  leafCommand(entries, "delete", "destructive")
76
82
  .argument("<id>", "Time-entry ID.")
77
83
  .description("Delete a time entry by ID.")
84
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 entries delete entry_123\n")
78
85
  .action(async function (id) {
79
86
  const { client, workspaceId, output } = await resolveContext(this, services);
80
87
  await client.timeEntries.delete({ workspaceId, timeEntryId: id });
@@ -22,6 +22,9 @@ export const registerExpensesCommand = (program, services) => {
22
22
  const expenses = program.command("expenses").description("Inspect workspace expenses.");
23
23
  leafCommand(expenses, "list", "read")
24
24
  .description("List expenses in the workspace.")
25
+ .addHelpText("after", "\nExamples:\n" +
26
+ " $ clk115 expenses list\n" +
27
+ " $ clk115 expenses list --start 2026-06-01 --end 2026-06-30\n")
25
28
  .option("--limit <n>", "Total records to return (default 25, max 10000).", parseIntArg, 25)
26
29
  .option("--page-size <n>", "Records fetched per page (default 50, max 200).", parseIntArg, 50)
27
30
  .option("--max-pages <n>", "Maximum pages to scan (default 100, max 1000).", parseIntArg, 100)
@@ -70,6 +73,8 @@ export const registerExpensesCommand = (program, services) => {
70
73
  .option("--billable", "Mark as billable.")
71
74
  .option("--no-billable", "Mark as non-billable.")
72
75
  .description("Create an expense from amount, category, and date; defaults the user to the API-key owner.")
76
+ .addHelpText("after", "\nExamples:\n" +
77
+ " $ clk115 expenses create --amount 42.50 --category cat_123 --date 2026-06-01\n")
73
78
  .action(async function (opts) {
74
79
  const { client, workspaceId, output } = await resolveContext(this, services);
75
80
  let userId = opts.user;
@@ -116,6 +121,7 @@ export const registerExpensesCommand = (program, services) => {
116
121
  leafCommand(expenses, "get", "read")
117
122
  .argument("<id>", "Expense ID.")
118
123
  .description("Get one expense by ID.")
124
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 expenses get expense_123\n")
119
125
  .action(async function (id) {
120
126
  const { client, workspaceId, output } = await resolveContext(this, services);
121
127
  const expense = await client.expenses.get({ workspaceId, expenseId: id });
@@ -133,6 +139,9 @@ export const registerExpensesCommand = (program, services) => {
133
139
  .option("--billable", "Mark as billable.")
134
140
  .option("--no-billable", "Mark as non-billable.")
135
141
  .description("Update an expense by ID (full replace of amount, category, date, plus any optional fields supplied).")
142
+ .addHelpText("after", "\nExamples:\n" +
143
+ " $ clk115 expenses update expense_123 --amount 50 --category cat_123 \\\n" +
144
+ " --date 2026-06-01 --user user_123\n")
136
145
  .action(async function (id, opts) {
137
146
  const { client, workspaceId, output } = await resolveContext(this, services);
138
147
  const fields = {
@@ -174,6 +183,7 @@ export const registerExpensesCommand = (program, services) => {
174
183
  leafCommand(expenses, "delete", "destructive")
175
184
  .argument("<id>", "Expense ID.")
176
185
  .description("Delete an expense by ID.")
186
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 expenses delete expense_123\n")
177
187
  .action(async function (id) {
178
188
  const { client, workspaceId, output } = await resolveContext(this, services);
179
189
  await client.expenses.delete({ workspaceId, expenseId: id });
@@ -38,19 +38,62 @@ export function splitList(value) {
38
38
  .map((s) => s.trim())
39
39
  .filter((s) => s.length > 0);
40
40
  }
41
- export function promoteDateBoundary(value, flag, edge) {
42
- if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
43
- const probe = new Date(`${value}T00:00:00Z`);
44
- if (Number.isNaN(probe.getTime()) || probe.toISOString().slice(0, 10) !== value) {
41
+ const BARE_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
42
+ const RFC3339_TIMESTAMP_PATTERN = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/;
43
+ function hasValidCalendarDate(yearText, monthText, dayText) {
44
+ const year = Number(yearText);
45
+ const month = Number(monthText);
46
+ const day = Number(dayText);
47
+ const probe = new Date(0);
48
+ probe.setUTCFullYear(year, month - 1, day);
49
+ probe.setUTCHours(0, 0, 0, 0);
50
+ return (probe.getUTCFullYear() === year &&
51
+ probe.getUTCMonth() === month - 1 &&
52
+ probe.getUTCDate() === day);
53
+ }
54
+ function isRfc3339Timestamp(value) {
55
+ const match = RFC3339_TIMESTAMP_PATTERN.exec(value);
56
+ if (match === null || !hasValidCalendarDate(match[1], match[2], match[3])) {
57
+ return false;
58
+ }
59
+ const hour = Number(match[4]);
60
+ const minute = Number(match[5]);
61
+ const second = Number(match[6]);
62
+ const offsetHour = match[7] === undefined ? 0 : Number(match[7]);
63
+ const offsetMinute = match[8] === undefined ? 0 : Number(match[8]);
64
+ return (hour <= 23 &&
65
+ minute <= 59 &&
66
+ second <= 59 &&
67
+ offsetHour <= 23 &&
68
+ offsetMinute <= 59 &&
69
+ !Number.isNaN(Date.parse(value)));
70
+ }
71
+ export function requireRfc3339Timestamp(value, flag) {
72
+ if (!isRfc3339Timestamp(value)) {
73
+ throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid RFC3339 timestamp; provide a value such as 2026-06-22T09:30:00Z`);
74
+ }
75
+ return value;
76
+ }
77
+ export function requireDateOrRfc3339(value, flag) {
78
+ const bareDate = BARE_DATE_PATTERN.exec(value);
79
+ if (bareDate !== null) {
80
+ if (!hasValidCalendarDate(bareDate[1], bareDate[2], bareDate[3])) {
45
81
  throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
46
82
  }
47
- return edge === "start" ? `${value}T00:00:00Z` : `${value}T23:59:59Z`;
83
+ return value;
48
84
  }
49
- if (Number.isNaN(Date.parse(value))) {
85
+ if (!isRfc3339Timestamp(value)) {
50
86
  throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid date (YYYY-MM-DD) or RFC3339 timestamp; provide YYYY-MM-DD or an RFC3339 timestamp`);
51
87
  }
52
88
  return value;
53
89
  }
90
+ export function promoteDateBoundary(value, flag, edge) {
91
+ const validValue = requireDateOrRfc3339(value, flag);
92
+ if (BARE_DATE_PATTERN.test(validValue)) {
93
+ return edge === "start" ? `${value}T00:00:00Z` : `${value}T23:59:59Z`;
94
+ }
95
+ return validValue;
96
+ }
54
97
  export function rootProgram(cmd) {
55
98
  let current = cmd;
56
99
  while (current.parent != null) {
@@ -10,6 +10,7 @@ export const registerInvoicesCommand = (program, services) => {
10
10
  const invoices = program.command("invoices").description("Manage invoices.");
11
11
  leafCommand(invoices, "list", "read")
12
12
  .description("List invoices in the workspace.")
13
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 invoices list\n")
13
14
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
14
15
  .option("--page <n>", "Page number.", parseIntArg, 1)
15
16
  .action(async function (opts) {
@@ -37,6 +38,9 @@ export const registerInvoicesCommand = (program, services) => {
37
38
  });
38
39
  leafCommand(invoices, "create", "write")
39
40
  .description("Create an invoice draft.")
41
+ .addHelpText("after", "\nExamples:\n" +
42
+ " $ clk115 invoices create --client client_123 --number INV-001 \\\n" +
43
+ " --currency USD --issued 2026-06-01 --due 2026-06-15\n")
40
44
  .requiredOption("--client <id>", "Client ID.")
41
45
  .requiredOption("--number <text>", "Invoice number.")
42
46
  .requiredOption("--currency <code>", "ISO currency code (e.g. USD, EUR).")
@@ -1,11 +1,14 @@
1
1
  import { parseDuration } from "../duration.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { resolveContext } from "./helpers.js";
3
+ import { requireRfc3339Timestamp, resolveContext } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
5
  import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
6
6
  export const registerLogCommand = (program, services) => {
7
7
  leafCommand(program, "log", "write")
8
8
  .description("Log a finished time entry. Duration accepts 1h30m / 90m / PT1H30M.")
9
+ .addHelpText("after", "\nExamples:\n" +
10
+ " $ clk115 log 1h30m \"Client call\"\n" +
11
+ " $ clk115 log 45m \"Code review\" --project Website --billable\n")
9
12
  .argument("<duration>", "Duration like '1h30m', '45m', or ISO 8601 'PT1H30M'.")
10
13
  .argument("<description>", "What you worked on.")
11
14
  .option("-p, --project <name|id>", "Project name or ID.")
@@ -14,10 +17,15 @@ export const registerLogCommand = (program, services) => {
14
17
  .option("--billable", "Mark the entry as billable.", false)
15
18
  .option("--end <iso>", "End timestamp (ISO 8601). Defaults to now.")
16
19
  .action(async function (duration, description, opts) {
17
- const { client, workspaceId, output } = await resolveContext(this, services);
18
20
  if (opts.task && !opts.project) {
19
21
  throw new Error("--task requires --project: a task entry must be scoped to its project.");
20
22
  }
23
+ const seconds = parseDuration(duration);
24
+ const endInput = requireRfc3339Timestamp(opts.end ?? new Date().toISOString(), "end");
25
+ const endMs = Date.parse(endInput);
26
+ const endIso = new Date(endMs).toISOString();
27
+ const startIso = new Date(endMs - seconds * 1000).toISOString();
28
+ const { client, workspaceId, output } = await resolveContext(this, services);
21
29
  const projectId = opts.project
22
30
  ? await resolveProjectId(client, workspaceId, opts.project)
23
31
  : undefined;
@@ -27,14 +35,6 @@ export const registerLogCommand = (program, services) => {
27
35
  const tagIds = opts.tag && opts.tag.length > 0
28
36
  ? await resolveTagIds(client, workspaceId, opts.tag)
29
37
  : undefined;
30
- const seconds = parseDuration(duration);
31
- const endInput = opts.end ?? new Date().toISOString();
32
- const endMs = Date.parse(endInput);
33
- if (Number.isNaN(endMs)) {
34
- throw new Error(`--end ${JSON.stringify(opts.end)} is not a valid ISO 8601 timestamp; provide an RFC3339 timestamp`);
35
- }
36
- const endIso = new Date(endMs).toISOString();
37
- const startIso = new Date(endMs - seconds * 1000).toISOString();
38
38
  const body = {
39
39
  start: startIso,
40
40
  end: endIso,
@@ -13,6 +13,9 @@ export const registerProjectsCommand = (program, services) => {
13
13
  const projects = program.command("projects").description("Manage projects.");
14
14
  leafCommand(projects, "list", "read")
15
15
  .description("List projects in the workspace.")
16
+ .addHelpText("after", "\nExamples:\n" +
17
+ " $ clk115 projects list\n" +
18
+ " $ clk115 projects list --name Website --archived\n")
16
19
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
17
20
  .option("--page <n>", "Page number.", parseIntArg, 1)
18
21
  .option("--name <text>", "Filter by project name substring.")
@@ -51,6 +54,9 @@ export const registerProjectsCommand = (program, services) => {
51
54
  .option("--color <hex>", "Hex color (e.g. #4caf50).")
52
55
  .option("--billable", "Mark as billable.", false)
53
56
  .description("Create a project in the workspace.")
57
+ .addHelpText("after", "\nExamples:\n" +
58
+ " $ clk115 projects create Website\n" +
59
+ " $ clk115 projects create Website --client client_123 --billable\n")
54
60
  .action(async function (name, opts) {
55
61
  const { client, workspaceId, output } = await resolveContext(this, services);
56
62
  const req = {
@@ -87,6 +93,7 @@ export const registerProjectsCommand = (program, services) => {
87
93
  leafCommand(projects, "get", "read")
88
94
  .argument("<id>", "Project ID.")
89
95
  .description("Get one project by ID.")
96
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 projects get project_123\n")
90
97
  .action(async function (id) {
91
98
  const { client, workspaceId, output } = await resolveContext(this, services);
92
99
  const project = await client.projects.get({ workspaceId, projectId: id });
@@ -103,6 +110,9 @@ export const registerProjectsCommand = (program, services) => {
103
110
  .option("--archived", "Archive the project.")
104
111
  .option("--no-archived", "Unarchive the project.")
105
112
  .description("Update a project by ID.")
113
+ .addHelpText("after", "\nExamples:\n" +
114
+ " $ clk115 projects update project_123 --name \"New name\"\n" +
115
+ " $ clk115 projects update project_123 --archived\n")
106
116
  .action(async function (id, opts) {
107
117
  const hasChanges = Boolean(opts.name) ||
108
118
  Boolean(opts.client) ||
@@ -149,6 +159,7 @@ export const registerProjectsCommand = (program, services) => {
149
159
  leafCommand(projects, "delete", "destructive")
150
160
  .argument("<id>", "Project ID.")
151
161
  .description("Delete a project by ID (archives first; an active project cannot be deleted).")
162
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 projects delete project_123\n")
152
163
  .action(async function (id) {
153
164
  const { client, workspaceId, output } = await resolveContext(this, services);
154
165
  await archiveThenDeleteProject({
@@ -89,6 +89,9 @@ export const registerReportsCommand = (program, services) => {
89
89
  const reports = program.command("reports").description("Run Clockify reports (read-only).");
90
90
  leafCommand(reports, "summary", "read")
91
91
  .description("Summary report totals over a date range, grouped per --groups.")
92
+ .addHelpText("after", "\nExamples:\n" +
93
+ " $ clk115 reports summary --period this_month\n" +
94
+ " $ clk115 reports summary --from 2026-06-01 --to 2026-06-30 --groups PROJECT,TASK\n")
92
95
  .option("--period <p>", PERIOD_HELP)
93
96
  .option("--from <date>", "Range start (YYYY-MM-DD, ISO, or a period); overrides --period.")
94
97
  .option("--to <date>", "Range end (YYYY-MM-DD, ISO, or a period); overrides --period.")
@@ -121,6 +124,7 @@ export const registerReportsCommand = (program, services) => {
121
124
  });
122
125
  leafCommand(reports, "detailed", "read")
123
126
  .description("Detailed report listing individual time entries over a date range.")
127
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 reports detailed --period this_week\n")
124
128
  .option("--period <p>", PERIOD_HELP)
125
129
  .option("--from <date>", "Range start; overrides --period.")
126
130
  .option("--to <date>", "Range end; overrides --period.")
@@ -143,6 +147,7 @@ export const registerReportsCommand = (program, services) => {
143
147
  });
144
148
  leafCommand(reports, "weekly", "read")
145
149
  .description("Weekly report for one exact seven-day interval.")
150
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 reports weekly\n")
146
151
  .option("--period <p>", "Named period (default last_week).", "last_week")
147
152
  .option("--from <date>", "Range start; overrides --period.")
148
153
  .option("--to <date>", "Range end; overrides --period.")
@@ -163,6 +168,7 @@ export const registerReportsCommand = (program, services) => {
163
168
  });
164
169
  leafCommand(reports, "attendance", "read")
165
170
  .description("Attendance report of clock-in/out activity over a date range.")
171
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 reports attendance --period this_month\n")
166
172
  .option("--period <p>", PERIOD_HELP)
167
173
  .option("--from <date>", "Range start; overrides --period.")
168
174
  .option("--to <date>", "Range end; overrides --period.")
@@ -1,6 +1,6 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, resolveContext, } from "./helpers.js";
3
+ import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, requireRfc3339Timestamp, resolveContext, } from "./helpers.js";
4
4
  import { leafCommand } from "./leaf-command.js";
5
5
  export const registerSchedulingCommand = (program, services) => {
6
6
  const scheduling = program
@@ -8,6 +8,8 @@ export const registerSchedulingCommand = (program, services) => {
8
8
  .description("Capacity scheduling assignments.");
9
9
  leafCommand(scheduling, "list", "read")
10
10
  .description("List scheduling assignments over a date range. --from/--to are required (the endpoint 400s without them).")
11
+ .addHelpText("after", "\nExamples:\n" +
12
+ " $ clk115 scheduling list --from 2026-06-01 --to 2026-06-30\n")
11
13
  .requiredOption("--from <date>", "Range start (YYYY-MM-DD or RFC3339). Required.")
12
14
  .requiredOption("--to <date>", "Range end (YYYY-MM-DD or RFC3339). Required.")
13
15
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
@@ -43,6 +45,9 @@ export const registerSchedulingCommand = (program, services) => {
43
45
  });
44
46
  leafCommand(scheduling, "create", "write")
45
47
  .description("Create a scheduling assignment (defaults to draft; pass --publish to publish).")
48
+ .addHelpText("after", "\nExamples:\n" +
49
+ " $ clk115 scheduling create --user user_123 --project project_456 \\\n" +
50
+ " --start 2026-06-01T00:00:00Z --end 2026-06-05T00:00:00Z --hours-per-day 6\n")
46
51
  .requiredOption("--user <id>", "User ID to assign.")
47
52
  .requiredOption("--project <id>", "Project ID.")
48
53
  .requiredOption("--start <date>", "Period start (RFC3339, e.g. 2026-05-01T00:00:00Z).")
@@ -54,13 +59,15 @@ export const registerSchedulingCommand = (program, services) => {
54
59
  .option("--include-non-working-days", "Include weekends/non-working days.", false)
55
60
  .option("--publish", "Publish immediately (default is draft).", false)
56
61
  .action(async function (opts) {
62
+ const start = requireRfc3339Timestamp(opts.start, "start");
63
+ const end = requireRfc3339Timestamp(opts.end, "end");
57
64
  const { client, workspaceId, output } = await resolveContext(this, services);
58
65
  const body = {
59
66
  userId: opts.user,
60
67
  projectId: opts.project,
61
68
  hoursPerDay: opts.hoursPerDay,
62
- start: opts.start,
63
- end: opts.end,
69
+ start,
70
+ end,
64
71
  };
65
72
  if (opts.task)
66
73
  body.taskId = opts.task;
@@ -76,8 +83,8 @@ export const registerSchedulingCommand = (program, services) => {
76
83
  if (opts.publish === true) {
77
84
  await client.scheduling.publish({
78
85
  workspaceId,
79
- start: opts.start,
80
- end: opts.end,
86
+ start,
87
+ end,
81
88
  userFilter: { contains: "CONTAINS", ids: [opts.user] },
82
89
  });
83
90
  }
@@ -86,8 +93,8 @@ export const registerSchedulingCommand = (program, services) => {
86
93
  user: created.userId ?? "",
87
94
  project: created.projectId ?? "",
88
95
  hoursPerDay: created.hoursPerDay ?? 0,
89
- start: created.start ?? created.period?.start ?? opts.start ?? "",
90
- end: created.end ?? created.period?.end ?? opts.end ?? "",
96
+ start: created.start ?? created.period?.start ?? start,
97
+ end: created.end ?? created.period?.end ?? end,
91
98
  published: opts.publish === true,
92
99
  };
93
100
  printReceipt({
@@ -261,6 +261,7 @@ export const registerSharedReportsCommand = (program, services) => {
261
261
  .description("Manage shared (public-link) reports.");
262
262
  leafCommand(shared, "list", "read")
263
263
  .description("List the workspace's shared (public-link) reports.")
264
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 shared-reports list\n")
264
265
  .action(async function () {
265
266
  const { client, workspaceId, output } = await resolveContext(this, services);
266
267
  const response = await client.sharedReports.list({ workspaceId });
@@ -277,6 +278,9 @@ export const registerSharedReportsCommand = (program, services) => {
277
278
  .argument("<id>", "Shared-report ID.")
278
279
  .option("--export-type <type>", "Text-safe export type: JSON_V1, JSON, or CSV (default JSON_V1).")
279
280
  .description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
281
+ .addHelpText("after", "\nExamples:\n" +
282
+ " $ clk115 shared-reports view report_123\n" +
283
+ " $ clk115 shared-reports view report_123 --export-type CSV\n")
280
284
  .action(async function (id, opts) {
281
285
  const candidate = opts.exportType ? String(opts.exportType).toUpperCase() : "JSON_V1";
282
286
  if (candidate === "XLSX" || candidate === "PDF") {
@@ -300,6 +304,9 @@ export const registerSharedReportsCommand = (program, services) => {
300
304
  .option("--public", "Make the report publicly accessible.")
301
305
  .option("--no-public", "Make the report private (no public link).")
302
306
  .description("Create a shared (public-link) report.")
307
+ .addHelpText("after", "\nExamples:\n" +
308
+ " $ clk115 shared-reports create --name \"Q3 Summary\" --type SUMMARY \\\n" +
309
+ " --filter '{}' --public\n")
303
310
  .action(async function (opts) {
304
311
  const { client, workspaceId, output } = await resolveContext(this, services);
305
312
  const body = parseSharedReportBody(sharedReportCreateBodySchema, opts, "shared-reports.create");
@@ -329,6 +336,9 @@ export const registerSharedReportsCommand = (program, services) => {
329
336
  .option("--public", "Make the report publicly accessible.")
330
337
  .option("--no-public", "Make the report private (no public link).")
331
338
  .description("Replace a shared report by ID (full replace of name, type, and filter).")
339
+ .addHelpText("after", "\nExamples:\n" +
340
+ " $ clk115 shared-reports update report_123 --name \"Q3 Summary\" \\\n" +
341
+ " --type SUMMARY --filter '{}'\n")
332
342
  .action(async function (id, opts) {
333
343
  const { client, workspaceId, output } = await resolveContext(this, services);
334
344
  const body = parseSharedReportBody(sharedReportUpdateBodySchema, opts, "shared-reports.update");
@@ -357,6 +367,7 @@ export const registerSharedReportsCommand = (program, services) => {
357
367
  leafCommand(shared, "delete", "destructive")
358
368
  .argument("<id>", "Shared-report ID.")
359
369
  .description("Delete a shared report by ID.")
370
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 shared-reports delete report_123\n")
360
371
  .action(async function (id) {
361
372
  const { client, workspaceId, output } = await resolveContext(this, services);
362
373
  await client.sharedReports.delete({ workspaceId, sharedReportId: id });
@@ -5,6 +5,9 @@ import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.j
5
5
  export const registerStartCommand = (program, services) => {
6
6
  leafCommand(program, "start", "write")
7
7
  .description("Start a running time entry. Resolves project/task/tag names to IDs automatically.")
8
+ .addHelpText("after", "\nExamples:\n" +
9
+ " $ clk115 start \"Writing docs\"\n" +
10
+ " $ clk115 start \"Fix bug\" --project Website --tag urgent --billable\n")
8
11
  .argument("[description]", "Description for the time entry.")
9
12
  .option("-p, --project <name>", "Project name or ID.")
10
13
  .option("-t, --task <name>", "Task name or ID.")
@@ -7,6 +7,9 @@ import { leafCommand } from "./leaf-command.js";
7
7
  export const registerStatusCommand = (program, services) => {
8
8
  leafCommand(program, "status", "read")
9
9
  .description("Show the configured workspace, current user, and running timer.")
10
+ .addHelpText("after", "\nExamples:\n" +
11
+ " $ clk115 status\n" +
12
+ " $ clk115 status --json\n")
10
13
  .action(async function () {
11
14
  const { client, config, output } = await resolveBaseContext(this, services);
12
15
  const user = await client.users.getCurrentUser();
@@ -6,6 +6,9 @@ import { leafCommand } from "./leaf-command.js";
6
6
  export const registerStopCommand = (program, services) => {
7
7
  leafCommand(program, "stop", "write")
8
8
  .description("Stop the running timer for the current user.")
9
+ .addHelpText("after", "\nExamples:\n" +
10
+ " $ clk115 stop\n" +
11
+ " $ clk115 stop --json\n")
9
12
  .action(async function () {
10
13
  const { client, workspaceId, output } = await resolveContext(this, services);
11
14
  const user = await client.users.getCurrentUser();
@@ -6,6 +6,9 @@ export const registerTagsCommand = (program, services) => {
6
6
  const tags = program.command("tags").description("Manage tags.");
7
7
  leafCommand(tags, "list", "read")
8
8
  .description("List tags in the workspace.")
9
+ .addHelpText("after", "\nExamples:\n" +
10
+ " $ clk115 tags list\n" +
11
+ " $ clk115 tags list --name urgent --archived\n")
9
12
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
10
13
  .option("--page <n>", "Page number.", parseIntArg, 1)
11
14
  .option("--name <text>", "Filter by tag name substring.")
@@ -35,6 +38,7 @@ export const registerTagsCommand = (program, services) => {
35
38
  leafCommand(tags, "create", "write")
36
39
  .argument("<name>", "Tag name.")
37
40
  .description("Create a tag in the workspace.")
41
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 tags create urgent\n")
38
42
  .action(async function (name) {
39
43
  const { client, workspaceId, output } = await resolveContext(this, services);
40
44
  const req = { workspaceId, body: { name } };
@@ -55,6 +59,7 @@ export const registerTagsCommand = (program, services) => {
55
59
  leafCommand(tags, "get", "read")
56
60
  .argument("<id>", "Tag ID.")
57
61
  .description("Get one tag by ID.")
62
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 tags get tag_123\n")
58
63
  .action(async function (id) {
59
64
  const { client, workspaceId, output } = await resolveContext(this, services);
60
65
  const tag = await client.tags.get({ workspaceId, tagId: id });
@@ -66,6 +71,9 @@ export const registerTagsCommand = (program, services) => {
66
71
  .option("--archived", "Archive the tag.")
67
72
  .option("--no-archived", "Unarchive the tag.")
68
73
  .description("Update a tag by ID.")
74
+ .addHelpText("after", "\nExamples:\n" +
75
+ " $ clk115 tags update tag_123 --name focus\n" +
76
+ " $ clk115 tags update tag_123 --archived\n")
69
77
  .action(async function (id, opts) {
70
78
  if (!opts.name && opts.archived === undefined) {
71
79
  throw new Error("tags.update needs a change: provide at least one tag field.");
@@ -94,6 +102,7 @@ export const registerTagsCommand = (program, services) => {
94
102
  leafCommand(tags, "delete", "destructive")
95
103
  .argument("<id>", "Tag ID.")
96
104
  .description("Delete a tag by ID.")
105
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 tags delete tag_123\n")
97
106
  .action(async function (id) {
98
107
  const { client, workspaceId, output } = await resolveContext(this, services);
99
108
  await client.tags.delete({ workspaceId, tagId: id });
@@ -86,6 +86,9 @@ export const registerTasksCommand = (program, services) => {
86
86
  leafCommand(tasks, "list", "read")
87
87
  .argument("<projectId>", "Project ID.")
88
88
  .description("List tasks for a project.")
89
+ .addHelpText("after", "\nExamples:\n" +
90
+ " $ clk115 tasks list project_123\n" +
91
+ " $ clk115 tasks list project_123 --name Design\n")
89
92
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
90
93
  .option("--page <n>", "Page number.", parseIntArg, 1)
91
94
  .option("--name <text>", "Filter by task name substring.")
@@ -118,6 +121,9 @@ export const registerTasksCommand = (program, services) => {
118
121
  .option("--estimate <iso>", "ISO-8601 duration estimate (e.g. PT8H).")
119
122
  .option("--assignee <id...>", "Assignee user ID(s).")
120
123
  .description("Create a task under a project.")
124
+ .addHelpText("after", "\nExamples:\n" +
125
+ " $ clk115 tasks create project_123 Design\n" +
126
+ " $ clk115 tasks create project_123 Design --billable --estimate PT8H\n")
121
127
  .action(async function (projectId, name, opts) {
122
128
  const { client, workspaceId, output } = await resolveContext(this, services);
123
129
  requireTaskName(name, "Task create request");
@@ -154,6 +160,7 @@ export const registerTasksCommand = (program, services) => {
154
160
  .argument("<projectId>", "Project ID.")
155
161
  .argument("<id>", "Task ID.")
156
162
  .description("Get one task by project ID and task ID.")
163
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 tasks get project_123 task_456\n")
157
164
  .action(async function (projectId, id) {
158
165
  const { client, workspaceId, output } = await resolveContext(this, services);
159
166
  const task = await client.tasks.get({ workspaceId, projectId, taskId: id });
@@ -169,6 +176,9 @@ export const registerTasksCommand = (program, services) => {
169
176
  .option("--no-billable", "Mark as non-billable.")
170
177
  .option("--assignee <id...>", "Assignee user ID(s).")
171
178
  .description("Update a task by project ID and task ID.")
179
+ .addHelpText("after", "\nExamples:\n" +
180
+ " $ clk115 tasks update project_123 task_456 --status DONE\n" +
181
+ " $ clk115 tasks update project_123 task_456 --name \"New name\"\n")
172
182
  .action(async function (projectId, id, opts) {
173
183
  const { client, workspaceId, output } = await resolveContext(this, services);
174
184
  const hasChanges = opts.name !== undefined ||
@@ -233,6 +243,7 @@ export const registerTasksCommand = (program, services) => {
233
243
  .argument("<projectId>", "Project ID.")
234
244
  .argument("<id>", "Task ID.")
235
245
  .description("Delete a task by project ID and task ID (marks DONE first; an active task cannot be deleted).")
246
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 tasks delete project_123 task_456\n")
236
247
  .action(async function (projectId, id) {
237
248
  const { client, workspaceId, output } = await resolveContext(this, services);
238
249
  const current = (await client.tasks.get({
@@ -1,13 +1,16 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
3
  import { registerBalanceAssignmentCommands } from "./balanceAssignment.js";
4
- import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList } from "./helpers.js";
4
+ import { clampPageSize, parseIntArg, promoteDateBoundary, requireDateOrRfc3339, requireRfc3339Timestamp, resolveContext, splitList, } from "./helpers.js";
5
5
  import { leafCommand } from "./leaf-command.js";
6
6
  export const registerTimeOffCommand = (program, services) => {
7
7
  const timeoff = program.command("timeoff").description("Time-off requests.");
8
8
  registerBalanceAssignmentCommands(timeoff, services);
9
9
  leafCommand(timeoff, "list", "read")
10
10
  .description("List time-off requests in the workspace.")
11
+ .addHelpText("after", "\nExamples:\n" +
12
+ " $ clk115 timeoff list\n" +
13
+ " $ clk115 timeoff list --status PENDING --user user_123\n")
11
14
  .option("--page <n>", "Page number.", parseIntArg, 1)
12
15
  .option("--limit <n>", "Items per page (default 50, max 200).", parseIntArg, 50)
13
16
  .option("--start <date>", "Window start (YYYY-MM-DD or RFC3339).")
@@ -58,6 +61,8 @@ export const registerTimeOffCommand = (program, services) => {
58
61
  });
59
62
  leafCommand(timeoff, "submit", "write")
60
63
  .description("Submit a time-off request against a policy.")
64
+ .addHelpText("after", "\nExamples:\n" +
65
+ " $ clk115 timeoff submit --policy policy_456 --start 2026-07-01\n")
61
66
  .requiredOption("--policy <id>", "Time-off policy ID.")
62
67
  .requiredOption("--start <date>", "Period start (date-only YYYY-MM-DD for DAYS-unit policies, RFC3339 for HOURS-unit).")
63
68
  .option("--end <date>", "Period end (RFC3339); HOURS-unit policies need it, DAYS-unit use --days. Provide --end or --days.")
@@ -76,10 +81,14 @@ export const registerTimeOffCommand = (program, services) => {
76
81
  if (!["FIRST_HALF", "SECOND_HALF", "NOT_DEFINED"].includes(halfDayPeriod)) {
77
82
  throw new Error(`--half-day-period must be FIRST_HALF, SECOND_HALF, or NOT_DEFINED (got "${String(opts.halfDayPeriod)}").`);
78
83
  }
84
+ const start = requireDateOrRfc3339(opts.start, "start");
85
+ const end = opts.end === undefined
86
+ ? undefined
87
+ : requireRfc3339Timestamp(opts.end, "end");
79
88
  const { client, workspaceId, output } = await resolveContext(this, services);
80
- const period = { start: opts.start };
81
- if (opts.end !== undefined)
82
- period.end = opts.end;
89
+ const period = { start };
90
+ if (end !== undefined)
91
+ period.end = end;
83
92
  if (Number.isFinite(opts.days))
84
93
  period.days = opts.days;
85
94
  const body = {
@@ -24,6 +24,7 @@ export const registerUsersCommand = (program, services) => {
24
24
  const users = program.command("users").description("Inspect workspace users.");
25
25
  leafCommand(users, "me", "read")
26
26
  .description("Show the current authenticated user (the API-key owner).")
27
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 users me\n")
27
28
  .action(async function () {
28
29
  const { client, output } = await resolveBaseContext(this, services);
29
30
  const me = await client.users.getCurrentUser();
@@ -31,6 +32,7 @@ export const registerUsersCommand = (program, services) => {
31
32
  });
32
33
  leafCommand(users, "list", "read")
33
34
  .description("List members of the workspace.")
35
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 users list\n" + " $ clk115 users list --name jane\n")
34
36
  .option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
35
37
  .option("--page <n>", "Page number.", parseIntArg, 1)
36
38
  .option("--name <text>", "Filter by name/email substring.")
@@ -60,6 +62,7 @@ export const registerUsersCommand = (program, services) => {
60
62
  .argument("<email>", "Email address of the user to invite.")
61
63
  .option("--no-send-email", "Do not send the invitation email.")
62
64
  .description("Invite (add) a user to the workspace by email.")
65
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 users invite jane@example.com\n")
63
66
  .action(async function (email, opts) {
64
67
  const { client, workspaceId, output } = await resolveContext(this, services);
65
68
  const sendEmail = opts.sendEmail !== false;
@@ -96,6 +99,9 @@ export const registerUsersCommand = (program, services) => {
96
99
  .option("--work-capacity <iso>", "Daily work capacity, ISO-8601 duration (e.g. PT8H).")
97
100
  .option("--working-days <days...>", "Working days: MONDAY, TUESDAY, ... SUNDAY (space-separated).")
98
101
  .description("Update one user's member profile (name, image, week start, work capacity, working days).")
102
+ .addHelpText("after", "\nExamples:\n" +
103
+ " $ clk115 users update-profile user_123 --name \"Jane Doe\"\n" +
104
+ " $ clk115 users update-profile user_123 --week-start MONDAY --work-capacity PT8H\n")
99
105
  .action(async function (userId, opts) {
100
106
  const hasChanges = opts.name !== undefined ||
101
107
  opts.imageUrl !== undefined ||
@@ -101,6 +101,9 @@ export const registerWebhooksCommand = (program, services) => {
101
101
  const webhooks = program.command("webhooks").description("Manage outbound webhooks.");
102
102
  leafCommand(webhooks, "list", "read")
103
103
  .description("List webhooks in the workspace.")
104
+ .addHelpText("after", "\nExamples:\n" +
105
+ " $ clk115 webhooks list\n" +
106
+ " $ clk115 webhooks list --type ADDON\n")
104
107
  .option("--type <type>", "Filter by webhook type (USER_CREATED, SYSTEM, ADDON).")
105
108
  .action(async function (opts) {
106
109
  const { client, workspaceId, output } = await resolveContext(this, services);
@@ -130,6 +133,9 @@ export const registerWebhooksCommand = (program, services) => {
130
133
  });
131
134
  leafCommand(webhooks, "create", "write")
132
135
  .description("Create a webhook subscription.")
136
+ .addHelpText("after", "\nExamples:\n" +
137
+ " $ clk115 webhooks create --name \"New entries\" --url https://example.com/hook \\\n" +
138
+ " --event NEW_TIME_ENTRY --trigger-source-type WORKSPACE_ID\n")
133
139
  .requiredOption("--name <text>", "Webhook label.")
134
140
  .requiredOption("--url <url>", "Target URL (HTTPS).")
135
141
  .requiredOption("--event <event>", "Webhook event (e.g. NEW_PROJECT, NEW_TIME_ENTRY, NEW_INVOICE).")
@@ -192,6 +198,7 @@ export const registerWebhooksCommand = (program, services) => {
192
198
  leafCommand(webhooks, "delete", "destructive")
193
199
  .argument("<id>", "Webhook ID.")
194
200
  .description("Delete a webhook subscription.")
201
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 webhooks delete webhook_123\n")
195
202
  .action(async function (id) {
196
203
  const { client, workspaceId, output } = await resolveContext(this, services);
197
204
  await client.webhooks.delete({ workspaceId, webhookId: id });
package/dist/config.js CHANGED
@@ -1,6 +1,32 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
+ const KNOWN_RC_FILE_KEYS = ["workspaceId", "baseUrl", "region", "subdomain"];
5
+ function editDistance(left, right) {
6
+ let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
7
+ for (let leftIndex = 0; leftIndex < left.length; leftIndex += 1) {
8
+ const current = [leftIndex + 1];
9
+ for (let rightIndex = 0; rightIndex < right.length; rightIndex += 1) {
10
+ current.push(Math.min(current[rightIndex] + 1, previous[rightIndex + 1] + 1, previous[rightIndex] +
11
+ (left[leftIndex] === right[rightIndex] ? 0 : 1)));
12
+ }
13
+ previous = current;
14
+ }
15
+ return previous[right.length];
16
+ }
17
+ function nearestRcFileKey(input) {
18
+ const normalized = input.toLowerCase();
19
+ let nearest = KNOWN_RC_FILE_KEYS[0];
20
+ let smallestDistance = editDistance(normalized, nearest.toLowerCase());
21
+ for (const candidate of KNOWN_RC_FILE_KEYS.slice(1)) {
22
+ const distance = editDistance(normalized, candidate.toLowerCase());
23
+ if (distance < smallestDistance) {
24
+ nearest = candidate;
25
+ smallestDistance = distance;
26
+ }
27
+ }
28
+ return nearest;
29
+ }
4
30
  export function loadConfig(flags = {}, env = process.env) {
5
31
  const file = loadRcFile(env);
6
32
  const apiKey = firstPresent(env.CLOCKIFY_API_KEY);
@@ -50,15 +76,18 @@ function loadRcFile(env) {
50
76
  if (Object.prototype.hasOwnProperty.call(parsed, "apiKey")) {
51
77
  throw new Error("legacy rc-file secret detected: remove apiKey from the rc file and set CLOCKIFY_API_KEY in the process environment");
52
78
  }
79
+ for (const key of Object.keys(parsed)) {
80
+ if (KNOWN_RC_FILE_KEYS.includes(key))
81
+ continue;
82
+ const suggestion = nearestRcFileKey(key);
83
+ process.stderr.write(`WARN clk115: ignoring unknown rc-file key ${JSON.stringify(key)}. Did you mean ${JSON.stringify(suggestion)}?\n`);
84
+ }
53
85
  const out = {};
54
- if (typeof parsed.workspaceId === "string")
55
- out.workspaceId = parsed.workspaceId;
56
- if (typeof parsed.baseUrl === "string")
57
- out.baseUrl = parsed.baseUrl;
58
- if (typeof parsed.region === "string")
59
- out.region = parsed.region;
60
- if (typeof parsed.subdomain === "string")
61
- out.subdomain = parsed.subdomain;
86
+ for (const key of KNOWN_RC_FILE_KEYS) {
87
+ const value = parsed[key];
88
+ if (typeof value === "string")
89
+ out[key] = value;
90
+ }
62
91
  return out;
63
92
  }
64
93
  return {};
package/dist/duration.js CHANGED
@@ -9,19 +9,19 @@ export function parseDuration(input) {
9
9
  if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
10
10
  return requirePositive(Math.round(Number(trimmed) * 60), input);
11
11
  }
12
- const compact = trimmed.replace(/\s+/g, "");
13
- const re = /(\d+(?:\.\d+)?)([dhms])/gi;
12
+ const re = /(\d+(?:\.\d+)?)\s*([dhms])\s*/giy;
14
13
  let total = 0;
15
- let consumed = 0;
16
- let match;
17
- while ((match = re.exec(compact)) !== null) {
14
+ let offset = 0;
15
+ while (offset < trimmed.length) {
16
+ re.lastIndex = offset;
17
+ const match = re.exec(trimmed);
18
+ if (match === null) {
19
+ throw new Error(`could not parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
20
+ }
18
21
  const value = Number(match[1]);
19
22
  const unit = (match[2] ?? "").toLowerCase();
20
23
  total += value * unitToSeconds(unit);
21
- consumed += match[0].length;
22
- }
23
- if (consumed === 0 || consumed < compact.length) {
24
- throw new Error(`could not parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
24
+ offset = re.lastIndex;
25
25
  }
26
26
  return requirePositive(Math.round(total), input);
27
27
  }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = "5.0.0";
1
+ export const PACKAGE_VERSION = "5.0.2";
package/dist/index.js CHANGED
@@ -74,6 +74,9 @@ export function buildProgram(services = defaultServices) {
74
74
  leafCommand(program, "completion", "read")
75
75
  .argument("[shell]", "Shell to generate completion for: zsh, bash, or fish.", "zsh")
76
76
  .description("Print shell completion script for zsh, bash, or fish.")
77
+ .addHelpText("after", "\nExamples:\n" +
78
+ " $ clk115 completion zsh >> ~/.zshrc\n" +
79
+ " $ clk115 completion bash\n")
77
80
  .action((shell) => {
78
81
  console.log(renderCompletion(parseCompletionShell(shell)));
79
82
  });
package/dist/output.js CHANGED
@@ -78,7 +78,7 @@ export function selectValue(value, selector) {
78
78
  current = current[index];
79
79
  continue;
80
80
  }
81
- if (current !== null && typeof current === "object" && part in current) {
81
+ if (current !== null && typeof current === "object" && Object.hasOwn(current, part)) {
82
82
  current = current[part];
83
83
  continue;
84
84
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "description": "Unofficial, community-built \u2014 not affiliated with CAKE.com or Clockify. Command-line interface for Clockify, built on clockify-sdk-ts-115.",
5
5
  "license": "MIT",
6
6
  "author": "Aleksandar Petkovi\u0107 <petkovic.aleksandar037@gmail.com>",