vortex-cli 8.4.2__py3-none-any.whl → 8.6.0__py3-none-any.whl

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.
vortex/cli.py CHANGED
@@ -18,6 +18,9 @@ from typing import NamedTuple
18
18
  from vortex.models import DesignType
19
19
  from vortex.models import PuakmaApplication
20
20
 
21
+ _PMA_SUFFIX = re.compile(r"\.pma$", re.IGNORECASE)
22
+ _PMA_SEP = re.compile(r"\.pma/", re.IGNORECASE)
23
+
21
24
 
22
25
  class AppRef(NamedTuple):
23
26
  """
@@ -203,6 +206,116 @@ def positive_id(val: str) -> int:
203
206
  return _app_id(val)
204
207
 
205
208
 
209
+ def app_path(val: str) -> str:
210
+ """'group/app' ('app' when ungrouped), as typed or as AGENDA prints it: /group/app.pma"""
211
+ parts = val.removeprefix("/").split("/")
212
+ parts[-1] = _PMA_SUFFIX.sub("", parts[-1])
213
+ if not all(parts) or "?" in val or val.isdigit():
214
+ raise ArgumentTypeError(
215
+ f"invalid application '{val}': expected GROUP/APP (e.g. bettrackr/app), "
216
+ "or --app for a numeric ID"
217
+ + (
218
+ f" (an ungrouped application named {val} is /{val})"
219
+ if val.isdigit()
220
+ else ""
221
+ )
222
+ )
223
+ return "/".join(parts)
224
+
225
+
226
+ def app_or_id(val: str) -> int | str:
227
+ """
228
+ A numeric application ID, or a path that registry.resolve_app_args turns
229
+ into one. A bare word stays an error: it is far more often a typo than an
230
+ ungrouped application, which is /NAME.
231
+ """
232
+ if val.isdigit():
233
+ return _app_id(val)
234
+ if "/" not in val:
235
+ raise ArgumentTypeError(
236
+ f"invalid application '{val}': expected GROUP/APP (e.g. bettrackr/app) "
237
+ "or a numeric ID (e.g. 61). An ungrouped application is /NAME"
238
+ )
239
+ return app_path(val)
240
+
241
+
242
+ class ObjectPath(NamedTuple):
243
+ """A design object by path: its 'group/app', its name and, if named, its type."""
244
+
245
+ app: str
246
+ name: str
247
+ design_type: DesignType | None = None
248
+ # when the folder before the name was read as a type: the app it would be
249
+ # read as a name (group/app/PAGE/Home -> 'group/app/PAGE'), which must not
250
+ # also exist - registry checks, so a path never picks one of two apps
251
+ app_if_untyped: str | None = None
252
+
253
+ def __str__(self) -> str:
254
+ kind = f"{self.design_type.name}/" if self.design_type is not None else ""
255
+ return f"{self.app}/{kind}{self.name}"
256
+
257
+
258
+ def object_ref(val: str) -> int | ObjectPath:
259
+ """
260
+ A numeric design ID, or a path that registry.run turns into one:
261
+ group/app/Name (or /group/app.pma/Name, app/Name when ungrouped), with the
262
+ type after the app as in a clone (group/app/PAGE/Name) when a name is shared.
263
+ A name holding '/' needs the .pma form: /group/app.pma/sub/Name.
264
+ Only an upper case type counts, so a group 'site' with an app 'page' still works.
265
+ """
266
+ if val.isdigit():
267
+ return _app_id(val)
268
+ design_type = None
269
+ untyped = None
270
+ pma = _PMA_SEP.search(val)
271
+ if pma is not None:
272
+ # AGENDA's form: everything after '.pma/' is the name, which may hold '/'
273
+ head, name = val[: pma.start()], val[pma.end() :]
274
+ else:
275
+ head, _, name = val.rpartition("/")
276
+ app, _, kind = head.rpartition("/")
277
+ if app and kind in DesignType.dirs():
278
+ untyped = head
279
+ head, design_type = app, DesignType[kind]
280
+ try:
281
+ if name and "?" not in name:
282
+ try:
283
+ other = app_path(untyped) if untyped is not None else None
284
+ except ArgumentTypeError:
285
+ other = None
286
+ return ObjectPath(app_path(head), name, design_type, other)
287
+ except ArgumentTypeError:
288
+ pass
289
+ raise ArgumentTypeError(
290
+ f"invalid object '{val}': expected GROUP/APP/NAME (e.g. bettrackr/app/Nightly) "
291
+ "or a numeric ID with --app. Parameters go in --param"
292
+ + (
293
+ f". An ungrouped application named {head} is /{head}"
294
+ if head.isdigit()
295
+ else ""
296
+ )
297
+ )
298
+
299
+
300
+ def add_app_option(
301
+ parser: ArgumentParser | _ArgumentGroup | _MutuallyExclusiveGroup,
302
+ help_: str,
303
+ *,
304
+ required: bool = False,
305
+ flag: str = "--app",
306
+ ) -> None:
307
+ """--app (and its older spelling --app-id), read into args.app_id."""
308
+ parser.add_argument(
309
+ flag,
310
+ f"{flag}-id",
311
+ dest=f"{flag.lstrip('-').replace('-', '_')}_id",
312
+ type=app_or_id,
313
+ metavar="APP",
314
+ required=required,
315
+ help=f"{help_} (GROUP/APP or numeric ID)",
316
+ )
317
+
318
+
206
319
  def _pmx_type(val: str) -> Path:
207
320
  path = Path(val).resolve()
208
321
  if path.suffix != ".pmx" or not path.is_file():
@@ -481,13 +594,7 @@ def add_compile_parser(
481
594
  "error: nothing is written to zbin/ for it and it is never uploaded."
482
595
  ),
483
596
  )
484
- compile_parser.add_argument(
485
- "--app-id",
486
- type=_app_id,
487
- metavar="ID",
488
- required=True,
489
- help="The cloned application to compile (numeric)",
490
- )
597
+ add_app_option(compile_parser, "The cloned application to compile", required=True)
491
598
  compile_parser.add_argument(
492
599
  "--object",
493
600
  type=_app_id,
@@ -537,7 +644,9 @@ def add_compile_parser(
537
644
  return compile_parser
538
645
 
539
646
 
540
- def add_clean_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
647
+ def add_clean_parser(
648
+ command_parser: _SubParsersAction[ArgumentParser],
649
+ ) -> ArgumentParser:
541
650
  clean_parser = command_parser.add_parser(
542
651
  "clean",
543
652
  help=(
@@ -545,14 +654,10 @@ def add_clean_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
545
654
  "workspace. There is no undo - local changes are discarded"
546
655
  ),
547
656
  )
548
- clean_parser.add_argument(
549
- "--app-id",
550
- metavar="ID",
551
- type=_app_id,
552
- help=(
553
- "The locally cloned application to clean "
554
- "(default: every app cloned from the server)"
555
- ),
657
+ add_app_option(
658
+ clean_parser,
659
+ "The locally cloned application to clean, default every app cloned from "
660
+ "the server",
556
661
  )
557
662
  clean_parser.add_argument(
558
663
  "--all",
@@ -569,6 +674,7 @@ def add_clean_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
569
674
  ),
570
675
  )
571
676
  _add_server_option(clean_parser)
677
+ return clean_parser
572
678
 
573
679
 
574
680
  def add_log_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None:
@@ -862,7 +968,8 @@ def add_server_parser(command_parser: _SubParsersAction[ArgumentParser]) -> None
862
968
  "get",
863
969
  help=(
864
970
  "Show a server's every option, its value and where it comes from "
865
- "(no request)"
971
+ "(no request). scheme defaults to https, and an unset port to the "
972
+ "scheme's (443 / 80)"
866
973
  ),
867
974
  )
868
975
  get_parser.add_argument(
vortex/commands/agenda.py CHANGED
@@ -16,6 +16,19 @@ an app with scheduled actions disabled, or one created since the last
16
16
  refresh (every 15 minutes) is not on it. No console command says which
17
17
  actions are running - only how many.
18
18
 
19
+ 'run' names the action by path (grp/app/Name, as 'list' shows it, or
20
+ /grp/app.pma/Name, matched ignoring case, an exact match winning) or by ID
21
+ --app N. A path is looked up in the inventory and the app's design rows
22
+ (GET designs, or on an older gateway GET {app}/design with every blob), so the
23
+ design row's
24
+ Options are checked even when AGENDA's list is stale.
25
+
26
+ AGENDA's paths come from new RequestPath(group/app.pma/name), which URL-DECODES
27
+ all three, then prints group and app URL-encoded (java.net.URLEncoder) and the
28
+ name decoded. So an app 'a+b' prints as 'a+b' (decoded to 'a b', re-encoded)
29
+ and a name 'x+y' as 'x y'. _agenda_path builds that same text; parse_schedule
30
+ and _same_app compare decoded names, as AGENDA itself does.
31
+
19
32
  'run' sends 'tell agenda run /grp/app.pma/Name', which AGENDA matches
20
33
  against its loaded list and queues (AGENDA.forceRun). That command
21
34
  answers nothing either way, so 'run' checks first what AGENDA would do:
@@ -39,13 +52,18 @@ import argparse
39
52
  import datetime
40
53
  import logging
41
54
  import re
55
+ import urllib.parse
42
56
  from typing import Any
43
57
 
44
58
  from vortex import cli
45
59
  from vortex import registry
46
60
  from vortex.commands import execute
61
+ from vortex.commands.app import app_label
62
+ from vortex.commands.app import find_app_by_path
63
+ from vortex.commands.app import find_app_row
47
64
  from vortex.models import DesignType
48
65
  from vortex.output import CommandError
66
+ from vortex.output import one_match
49
67
  from vortex.output import render_table
50
68
  from vortex.output import text
51
69
  from vortex.registry import Command
@@ -62,9 +80,10 @@ WAITLIST_CMD = "tell agenda waitlist status"
62
80
  RUN_CMD = "tell agenda run %s"
63
81
 
64
82
  # AgendaItem.getSchedule(): path, interval + type letter, next run
65
- _SCHEDULE_LINE = re.compile(r"^(/\S+)\s+(\d+)([A-Z])\s+NextRun=(.+?)\s*$")
83
+ # (the design name is not encoded, so the path may hold spaces)
84
+ _SCHEDULE_LINE = re.compile(r"^(/.+?)\s+(\d+)([A-Z])\s+NextRun=(.+?)\s*$")
66
85
  # AgendaAction.toString(): path, Running=, LastRun=
67
- _WAITLIST_LINE = re.compile(r"^(/\S+)\s+Running=")
86
+ _WAITLIST_LINE = re.compile(r"^(/.+?)\s+Running=")
68
87
  _STATUS_LINE = re.compile(r"^([A-Za-z][A-Za-z ]+):\s*(\d+)\s*$")
69
88
  # AgendaItem's SimpleDateFormat for NextRun
70
89
  _NEXT_RUN_FORMAT = "%a %d.%b.%y %H:%M:%S"
@@ -78,13 +97,59 @@ _UNITS = {
78
97
  "M": "month",
79
98
  "Y": "year",
80
99
  }
81
- _PARAM = re.compile(r"^[A-Za-z0-9_.-]+=[A-Za-z0-9_.:-]*$")
100
+ _PARAM = re.compile(r"[A-Za-z0-9_.-]+=[A-Za-z0-9_.:-]*")
101
+ _PMA_SEP = re.compile(r"\.pma/", re.IGNORECASE)
102
+
103
+
104
+ def _list_app_path(val: str) -> str:
105
+ """_app_path, refusing a bare number: 'list 9' means --app 9 (/2024 is an app)."""
106
+ if val.isdigit():
107
+ raise argparse.ArgumentTypeError(
108
+ f"invalid application '{val}': use --app {val} for a numeric ID, "
109
+ f"or /{val} for an ungrouped application named {val}"
110
+ )
111
+ return cli.app_path(val)
112
+
113
+
114
+ def _action_target(val: str) -> int | cli.ObjectPath:
115
+ """cli.object_ref, where a type in the path can only be SCHEDULED_ACTION."""
116
+ target = cli.object_ref(val)
117
+ if isinstance(target, cli.ObjectPath) and target.design_type not in (
118
+ None,
119
+ DesignType.SCHEDULED_ACTION,
120
+ ):
121
+ raise argparse.ArgumentTypeError(
122
+ f"invalid action '{val}': only a SCHEDULED_ACTION runs through AGENDA"
123
+ )
124
+ return target
82
125
 
83
126
 
84
127
  def _console(ctx: Context, command: str) -> str:
85
128
  return execute.console_command(ctx.server, command) or ""
86
129
 
87
130
 
131
+ def _encode(part: str) -> str:
132
+ """java.net.URLEncoder.encode(part, "UTF-8"), as AGENDA encodes group and app."""
133
+ return urllib.parse.quote_plus(part, safe="*").replace("~", "%7E")
134
+
135
+
136
+ def _decode(part: str) -> str:
137
+ """java.net.URLDecoder.decode(part, "UTF-8"), as RequestPath decodes each part."""
138
+ return urllib.parse.unquote_plus(part)
139
+
140
+
141
+ def _agenda_path(group: str, app: str, name: str) -> str:
142
+ """The path AGENDA prints for a design row: AgendaItem's RequestPath."""
143
+ prefix = f"/{_encode(_decode(group))}" if group else ""
144
+ return f"{prefix}/{_encode(_decode(app))}.pma/{_decode(name)}"
145
+
146
+
147
+ def _same_app(item_app: str, app_path: str) -> bool:
148
+ """A schedule item's (decoded) app is this 'group/app', as AGENDA would read it."""
149
+ want = "/".join(_decode(p) for p in app_path.split("/"))
150
+ return item_app.lower() == want.lower()
151
+
152
+
88
153
  def parse_schedule(reply: str) -> list[dict[str, Any]]:
89
154
  """The items of a 'tell agenda schedule' reply (lines that don't parse are skipped)."""
90
155
  items = []
@@ -93,8 +158,12 @@ def parse_schedule(reply: str) -> list[dict[str, Any]]:
93
158
  if m is None:
94
159
  continue
95
160
  path, interval, unit, next_run = m.groups()
96
- app_path, _, name = path.rpartition("/")
97
- app = app_path.lstrip("/").removesuffix(".pma")
161
+ pma = _PMA_SEP.search(path)
162
+ if pma is None:
163
+ continue
164
+ # group and app are URL-encoded, the design name isn't (and may hold '/')
165
+ app_path, name = path[: pma.start()], path[pma.end() :]
166
+ app = "/".join(_decode(p) for p in app_path[1:].split("/"))
98
167
  items.append(
99
168
  {
100
169
  "path": path,
@@ -164,12 +233,13 @@ def _list(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
164
233
  items = parse_schedule(_console(ctx, SCHEDULE_CMD))
165
234
  queued = {p.lower() for p in parse_waitlist(_console(ctx, WAITLIST_CMD))}
166
235
  if args.app_id is not None:
167
- from vortex.commands.app import find_app_row
168
-
169
- app = find_app_row(ctx, args.app_id)
170
- group = text(app.get("appgroup"))
171
- want = f"{group + '/' if group else ''}{text(app.get('appname'))}".lower()
172
- items = [i for i in items if i["app"].lower() == want]
236
+ want = app_label(find_app_row(ctx, args.app_id))
237
+ items = [i for i in items if _same_app(i["app"], want)]
238
+ elif args.app is not None:
239
+ items = [i for i in items if _same_app(i["app"], args.app)]
240
+ if not items:
241
+ # nothing loaded, or a typo: only the inventory can tell
242
+ find_app_by_path(ctx, args.app)
173
243
  for item in items:
174
244
  item["waitlisted"] = item["path"].lower() in queued
175
245
  return {
@@ -206,12 +276,15 @@ def _render_list(ctx: Context, args: argparse.Namespace, data: Any) -> None:
206
276
 
207
277
 
208
278
  def _configure_list(parser: argparse.ArgumentParser) -> None:
209
- parser.add_argument(
210
- "--app-id",
211
- metavar="ID",
212
- type=cli.positive_id,
213
- help="Only this application's scheduled actions",
279
+ which = parser.add_mutually_exclusive_group()
280
+ which.add_argument(
281
+ "app",
282
+ nargs="?",
283
+ metavar="GROUP/APP",
284
+ type=_list_app_path,
285
+ help="Only this application's scheduled actions (e.g. bettrackr/app)",
214
286
  )
287
+ cli.add_app_option(which, "Only this application's scheduled actions")
215
288
 
216
289
 
217
290
  # -- run -------------------------------------------------------------------
@@ -220,7 +293,7 @@ def _configure_list(parser: argparse.ArgumentParser) -> None:
220
293
  def _params(args: argparse.Namespace) -> str:
221
294
  """'?&k=v&k2=v2' for --param, as 'app refresh' sends RefreshDesign?&AppID=N."""
222
295
  for param in args.param:
223
- if not _PARAM.match(param):
296
+ if not _PARAM.fullmatch(param):
224
297
  usage(
225
298
  args,
226
299
  f"--param '{param}' must be KEY=VALUE (letters, digits, '_', '.', "
@@ -229,12 +302,91 @@ def _params(args: argparse.Namespace) -> str:
229
302
  return "?&" + "&".join(args.param) if args.param else ""
230
303
 
231
304
 
232
- def _run(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
233
- from vortex.commands.app import find_app_row
305
+ def _check_target(args: argparse.Namespace) -> None:
306
+ if isinstance(args.action, cli.ObjectPath):
307
+ if args.app_id is not None:
308
+ usage(args, f"--app goes with a numeric ID, not the path {args.action}")
309
+ elif args.app_id is None:
310
+ usage(
311
+ args,
312
+ f"the numeric ID {args.action} needs --app, or name the action "
313
+ "GROUP/APP/ACTION",
314
+ )
234
315
 
235
- query = _params(args)
236
- app = find_app_row(ctx, args.app_id)
237
- row = ctx.client.get_design(args.app_id, args.id)
316
+
317
+ def _app_or_none(ctx: Context, app_path: str) -> dict[str, Any] | None:
318
+ try:
319
+ return find_app_by_path(ctx, app_path)
320
+ except CommandError as e:
321
+ if e.code == "NOT_FOUND":
322
+ return None
323
+ raise
324
+
325
+
326
+ def _design_by_path(
327
+ ctx: Context, target: cli.ObjectPath
328
+ ) -> tuple[dict[str, Any], dict[str, Any]]:
329
+ """
330
+ The inventory and design rows of a path that AGENDA hasn't loaded. A name
331
+ can belong to several types (design elements are keyed by name and type),
332
+ so the scheduled action wins, then an ACTION for the WRONG_TYPE hint.
333
+ """
334
+ if target.app_if_untyped is not None:
335
+ # 'site/SCHEDULED_ACTION/Nightly': app 'site' typed, or app
336
+ # 'site/SCHEDULED_ACTION' - as for 'object', never one of two
337
+ typed = _app_or_none(ctx, target.app)
338
+ other = _app_or_none(ctx, target.app_if_untyped)
339
+ if typed is not None and other is not None:
340
+ raise CommandError(
341
+ f"{target} names an action in '{target.app}' or in "
342
+ f"'{target.app_if_untyped}', and both applications exist",
343
+ "AMBIGUOUS",
344
+ hint=(
345
+ f"name it with .pma: /{target.app}.pma/{target.name} or "
346
+ f"/{target.app_if_untyped}.pma/{target.name}"
347
+ ),
348
+ )
349
+ if typed is None and other is not None:
350
+ target = cli.ObjectPath(target.app_if_untyped, target.name)
351
+ app = typed if typed is not None else other
352
+ if app is None:
353
+ app = find_app_by_path(ctx, target.app) # NOT_FOUND, as usual
354
+ else:
355
+ app = find_app_by_path(ctx, target.app)
356
+ app_id = to_int(app.get("appid"))
357
+ rows = [
358
+ row
359
+ for row in ctx.client.list_design_rows(app_id)
360
+ if text(row.get("name")).lower() == target.name.lower()
361
+ ]
362
+ if not rows:
363
+ raise CommandError(
364
+ f"No design object '{target.name}' in {app_label(app)} on "
365
+ f"'{ctx.server.name}'",
366
+ "NOT_FOUND",
367
+ hint=(
368
+ f"see its objects with: vortex object list --app-id {app_id} "
369
+ f"-s {ctx.server.name}"
370
+ ),
371
+ )
372
+
373
+ def rank(row: dict[str, Any]) -> tuple[bool, bool]:
374
+ design_type = to_int(row.get("designtype") or 0)
375
+ return (
376
+ design_type != DesignType.SCHEDULED_ACTION,
377
+ design_type != DesignType.ACTION,
378
+ )
379
+
380
+ best = min(map(rank, rows))
381
+ rows = [row for row in rows if rank(row) == best]
382
+ return app, one_match(
383
+ rows, lambda row: text(row.get("name")), target.name, "design objects"
384
+ )
385
+
386
+
387
+ def _check_design(app: dict[str, Any], row: dict[str, Any], design_id: int) -> str:
388
+ """The row's /group/app.pma/Name as AGENDA prints it, when AGENDA would load it."""
389
+ app_id = to_int(app.get("appid"))
238
390
  name = text(row.get("name"))
239
391
  design_type = to_int(row.get("designtype") or 0)
240
392
  if design_type != DesignType.SCHEDULED_ACTION:
@@ -243,19 +395,16 @@ def _run(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
243
395
  except ValueError:
244
396
  type_name = text(row.get("designtype"))
245
397
  raise CommandError(
246
- f"[{args.id}] {name} is a {type_name}: only a SCHEDULED_ACTION runs "
398
+ f"[{design_id}] {name} is a {type_name}: only a SCHEDULED_ACTION runs "
247
399
  "through AGENDA",
248
400
  "WRONG_TYPE",
249
401
  hint=(
250
- f"run an ACTION with: vortex object run {args.id} --app-id "
251
- f"{args.app_id}"
402
+ f"run an ACTION with: vortex object run {design_id} --app-id {app_id}"
252
403
  if design_type == DesignType.ACTION
253
404
  else None
254
405
  ),
255
406
  )
256
- group = text(app.get("appgroup"))
257
- path = f"/{group + '/' if group else ''}{text(app.get('appname'))}.pma/{name}"
258
- sent = path + query
407
+ path = _agenda_path(text(app.get("appgroup")), text(app.get("appname")), name)
259
408
  if "schedule=n" in text(row.get("options")).lower():
260
409
  # AGENDA.refreshActionList skips 'Schedule=N' outright (empty Options
261
410
  # load as on-demand instead), so --refresh can't help
@@ -264,10 +413,30 @@ def _run(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
264
413
  "ignore the run (silently) - nothing was sent",
265
414
  "NOT_ON_AGENDA",
266
415
  hint=(
267
- f"give it a schedule first: vortex object update {args.id} "
268
- f"--app-id {args.app_id} --schedule D --start-time 03:00 ..."
416
+ f"give it a schedule first: vortex object update {design_id} "
417
+ f"--app-id {app_id} --schedule D --start-time 03:00 ..."
269
418
  ),
270
419
  )
420
+ return path
421
+
422
+
423
+ def _run(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
424
+ query = _params(args)
425
+ _check_target(args)
426
+ target = args.action
427
+ # always the design row, never only AGENDA's list: that list can be up to
428
+ # 15 minutes stale, and a run queued from it writes its cached Options back
429
+ # (AGENDA.forceRun -> updateDesignBucket), undoing a newer Schedule=N
430
+ if isinstance(target, cli.ObjectPath):
431
+ app, row = _design_by_path(ctx, target)
432
+ design_id = to_int(row.get("designbucketid"))
433
+ else:
434
+ app = find_app_row(ctx, args.app_id)
435
+ row = ctx.client.get_design(args.app_id, target)
436
+ design_id = to_int(row.get("designbucketid") or target)
437
+ path = _check_design(app, row, design_id)
438
+ name = text(row.get("name"))
439
+ sent = path + query
271
440
 
272
441
  items = parse_schedule(_console(ctx, SCHEDULE_CMD))
273
442
  refreshed = False
@@ -312,7 +481,7 @@ def _run(ctx: Context, args: argparse.Namespace) -> dict[str, Any]:
312
481
  command = RUN_CMD % sent
313
482
  _console(ctx, command)
314
483
  return {
315
- "designbucketid": row.get("designbucketid"),
484
+ "designbucketid": design_id,
316
485
  "name": name,
317
486
  "path": sent,
318
487
  "command": command,
@@ -335,14 +504,16 @@ def _render_run(ctx: Context, args: argparse.Namespace, data: Any) -> None:
335
504
 
336
505
 
337
506
  def _configure_run(parser: argparse.ArgumentParser) -> None:
338
- parser.add_argument("id", metavar="ID", type=cli.positive_id)
339
507
  parser.add_argument(
340
- "--app-id",
341
- metavar="ID",
342
- type=cli.positive_id,
343
- required=True,
344
- help="The scheduled action's application (numeric)",
508
+ "action",
509
+ metavar="ACTION",
510
+ type=_action_target,
511
+ help=(
512
+ "The scheduled action: GROUP/APP/ACTION (e.g. bettrackr/app/Nightly), or "
513
+ "a numeric ID with --app"
514
+ ),
345
515
  )
516
+ cli.add_app_option(parser, "The application of a numeric ACTION")
346
517
  parser.add_argument(
347
518
  "--param",
348
519
  metavar="KEY=VALUE",
@@ -371,7 +542,7 @@ COMMANDS = [
371
542
  routes=(registry.CONSOLE,),
372
543
  configure=_configure_list,
373
544
  render=_render_list,
374
- note="--app-id also reads the inventory",
545
+ note="--app, or a GROUP/APP with nothing loaded, also reads the inventory",
375
546
  description=(
376
547
  "The scheduled actions AGENDA has loaded ('tell agenda schedule'),\n"
377
548
  "sorted by next run, with the waitlist and AGENDA's counts. Only\n"
@@ -391,9 +562,11 @@ COMMANDS = [
391
562
  render=_render_run,
392
563
  description=(
393
564
  "Queue a SCHEDULED_ACTION with AGENDA now ('tell agenda run\n"
394
- "/group/app.pma/Name'). It runs as the system session when a slot\n"
395
- "is free; its result is only in 'vortex log'. Checked first,\n"
396
- "because AGENDA answers nothing: refused when the action is not on\n"
565
+ "/group/app.pma/Name'), named GROUP/APP/ACTION (as 'vortex agenda'\n"
566
+ "lists it, ignoring case) or by ID --app N. It runs as the system\n"
567
+ "session when a slot is free; its result is only in 'vortex log'.\n"
568
+ "Checked first, because AGENDA answers nothing: refused when the\n"
569
+ "action has Schedule=N or is not on\n"
397
570
  "AGENDA's list (NOT_ON_AGENDA; --refresh rereads it), already\n"
398
571
  "waitlisted (ALREADY_QUEUED), or would also match another action\n"
399
572
  "by prefix and run twice (PREFIX_COLLISION; --force sends it).\n"
vortex/commands/app.py CHANGED
@@ -31,6 +31,7 @@ from vortex.models import PuakmaServer
31
31
  from vortex.output import CommandError
32
32
  from vortex.output import Outcome
33
33
  from vortex.output import command_error
34
+ from vortex.output import one_match
34
35
  from vortex.output import render_kv
35
36
  from vortex.output import render_table
36
37
  from vortex.output import text
@@ -142,6 +143,28 @@ def find_app_row(ctx: Context, app_id: int) -> dict[str, Any]:
142
143
  return row
143
144
 
144
145
 
146
+ def app_label(row: dict[str, Any]) -> str:
147
+ """An inventory row's 'group/app' ('app' when ungrouped)."""
148
+ group = text(row.get("appgroup"))
149
+ return f"{group + '/' if group else ''}{text(row.get('appname'))}"
150
+
151
+
152
+ def find_app_by_path(ctx: Context, app_path: str) -> dict[str, Any]:
153
+ """The inventory row of 'group/app', ignoring case (an exact match wins)."""
154
+ apps = [
155
+ row
156
+ for row in ctx.client.list_apps()
157
+ if app_label(row).lower() == app_path.lower()
158
+ ]
159
+ if not apps:
160
+ raise CommandError(
161
+ f"No application '{app_path}' on '{ctx.server.name}'",
162
+ "NOT_FOUND",
163
+ hint=f"see them with: vortex app list --all -s {ctx.server.name}",
164
+ )
165
+ return one_match(apps, app_label, app_path, "applications")
166
+
167
+
145
168
  # -- list / ls -------------------------------------------------------------
146
169
 
147
170
 
@@ -613,7 +636,7 @@ def _render_refresh_design(ctx: Context, args: argparse.Namespace, data: Any) ->
613
636
 
614
637
 
615
638
  def _configure_refresh_design(parser: argparse.ArgumentParser) -> None:
616
- parser.add_argument("app_id", metavar="APP_ID", type=cli.positive_id)
639
+ parser.add_argument("app_id", metavar="APP", type=cli.app_or_id)
617
640
 
618
641
 
619
642
  def _configure_list(parser: argparse.ArgumentParser) -> None:
@@ -621,7 +644,7 @@ def _configure_list(parser: argparse.ArgumentParser) -> None:
621
644
 
622
645
 
623
646
  def _configure_get(parser: argparse.ArgumentParser) -> None:
624
- parser.add_argument("app_id", metavar="APP_ID", type=cli.positive_id)
647
+ parser.add_argument("app_id", metavar="APP", type=cli.app_or_id)
625
648
  parser.add_argument(
626
649
  "--show-params",
627
650
  action="store_true",
@@ -638,7 +661,7 @@ def _configure_create(parser: argparse.ArgumentParser) -> None:
638
661
 
639
662
 
640
663
  def _configure_update(parser: argparse.ArgumentParser) -> None:
641
- parser.add_argument("app_id", metavar="APP_ID", type=cli.positive_id)
664
+ parser.add_argument("app_id", metavar="APP", type=cli.app_or_id)
642
665
  parser.add_argument("--name", "-n")
643
666
  parser.add_argument("--group", "-g")
644
667
  parser.add_argument("--description")
@@ -663,7 +686,7 @@ def _configure_update(parser: argparse.ArgumentParser) -> None:
663
686
 
664
687
 
665
688
  def _configure_export(parser: argparse.ArgumentParser) -> None:
666
- parser.add_argument("app_ids", nargs="+", metavar="APP_ID", type=cli.positive_id)
689
+ parser.add_argument("app_ids", nargs="+", metavar="APP", type=cli.app_or_id)
667
690
  parser.add_argument(
668
691
  "--out-dir",
669
692
  "-o",