File size: 2,194 Bytes
f778c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Top-level cron CLI registration and subcommand wiring.
import type { Command } from "commander";
import { formatDocsLink } from "../../../packages/terminal-core/src/links.js";
import { theme } from "../../../packages/terminal-core/src/theme.js";
import { inheritOptionFromParent } from "../command-options.js";
import { addGatewayClientOptions } from "../gateway-rpc.js";
import { setCommandJsonMode } from "../program/json-mode.js";
import { applyParentDefaultHelpAction } from "../program/parent-default-help.js";
import { CRON_GATEWAY_OPTION_NAMES, isCronMachineOutput } from "./output-mode.js";
import {
  registerCronAddCommand,
  registerCronListCommand,
  registerCronStatusCommand,
} from "./register.cron-add.js";
import { registerCronEditCommand } from "./register.cron-edit.js";
import { registerCronScratchCommand } from "./register.cron-scratch.js";
import { registerCronSimpleCommands } from "./register.cron-simple.js";

function inheritCronGatewayOptions(command: Command): void {
  for (const name of CRON_GATEWAY_OPTION_NAMES) {
    const inherited = inheritOptionFromParent(command, name);
    const source = command.parent?.getOptionValueSource(name);
    if (inherited !== undefined && source && source !== "default") {
      command.setOptionValueWithSource(name, inherited, source);
    }
  }
}

export function registerCronCli(program: Command) {
  const cron = program
    .command("cron")
    .alias("automations")
    .description("Manage automations (via Gateway)")
    .addHelpText(
      "after",
      () =>
        `\n${theme.muted("Docs:")} ${formatDocsLink("/cli/cron", "docs.openclaw.ai/cli/cron")}\n${theme.muted("Upgrade tip:")} run \`openclaw doctor --fix\` to normalize legacy automation storage.\n`,
    );

  addGatewayClientOptions(cron);
  cron.hook("preAction", (_parent, command) => inheritCronGatewayOptions(command));

  registerCronStatusCommand(cron);
  registerCronListCommand(cron);
  registerCronAddCommand(cron);
  registerCronSimpleCommands(cron);
  registerCronScratchCommand(cron);
  registerCronEditCommand(cron);
  setCommandJsonMode(cron, "output", ({ argv }) => isCronMachineOutput(argv));

  applyParentDefaultHelpAction(cron);
}