@kud/cli-shot 0.2.0 → 0.2.1

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
@@ -42,11 +42,16 @@ cli-shot --out assets/screenshots -- pcloud
42
42
  Everything after `--` is the command being driven, so its own flags stay clear
43
43
  of cli-shot's.
44
44
 
45
- Two exceptions: cli-shot appends `--mock` and `--screen` to that command itself.
46
- Passing either one yourself leaves two in argv — the app reads the first while
47
- the filename comes from the second, which is how you get a `files.png` holding
48
- the Sync screen. cli-shot refuses rather than guessing, and points you at
49
- `--only` or `--no-mock`.
45
+ cli-shot adds `--mock` and `--screen` to that command, but only where you
46
+ haven't. Anything you pass wins:
47
+
48
+ ```sh
49
+ cli-shot --out shots -- pcloud --screen sync # shoots Sync, writes sync.png
50
+ cli-shot --out shots --only sync -- pcloud # the same thing, said from here
51
+ ```
52
+
53
+ Naming a screen yourself is already an answer to "which one", so cli-shot skips
54
+ the discovery loop and takes the filename from your value.
50
55
 
51
56
  ```sh
52
57
  cli-shot --out shots --only sync -- pcloud # one screen
@@ -161,18 +161,16 @@ var toImage = (ansi, output, { font = DEFAULT_FONT, freezeArgs = [] } = {}) => {
161
161
  };
162
162
 
163
163
  // src/index.ts
164
- var MANAGED_FLAGS = ["--screen", "--mock"];
165
- var assertNoManagedFlags = (args) => {
166
- const clash = MANAGED_FLAGS.find((flag) => args.includes(flag));
167
- if (!clash) return;
168
- throw new Error(
169
- `${clash} is set by cli-shot, so passing it to the driven command leaves two in argv.
170
- ` + (clash === "--screen" ? ` Use cli-shot's --only <screen> instead, before the --.` : ` Mock data is on by default; use cli-shot's --no-mock to turn it off.`)
171
- );
164
+ var drivenScreen = (args) => {
165
+ const at = args.indexOf("--screen");
166
+ return at === -1 ? void 0 : args[at + 1];
172
167
  };
173
- var screenArgs = (args, screen, mock) => [...args, ...mock ? ["--mock"] : [], "--screen", screen];
168
+ var screenArgs = (args, screen, mock) => [
169
+ ...args,
170
+ ...mock && !args.includes("--mock") ? ["--mock"] : [],
171
+ ...drivenScreen(args) === void 0 ? ["--screen", screen] : []
172
+ ];
174
173
  var shootScreen = async (screen, { command, args = [], out, mock = true, ...rest }) => {
175
- assertNoManagedFlags(args);
176
174
  const ansi = await capture(command, screenArgs(args, screen, mock), rest);
177
175
  return toImage(ansi, join(out, `${screen}.png`), rest);
178
176
  };
@@ -191,7 +189,8 @@ var pool = async (items, limit, run) => {
191
189
  return results;
192
190
  };
193
191
  var shootAll = async (options) => {
194
- assertNoManagedFlags(options.args ?? []);
192
+ const pinned = drivenScreen(options.args ?? []);
193
+ if (pinned) return [await shootScreen(pinned, options)];
195
194
  const screens = listScreens(options.command, options.args ?? []);
196
195
  return pool(
197
196
  screens,
@@ -200,4 +199,4 @@ var shootAll = async (options) => {
200
199
  );
201
200
  };
202
201
 
203
- export { DEFAULT_FONT, MANAGED_FLAGS, capture, listScreens, shootAll, shootScreen, toImage };
202
+ export { DEFAULT_FONT, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage };
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-NTFITNMX.js';
2
+ import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-TKCXCDP2.js';
3
3
  import { Command } from 'commander';
4
4
 
5
5
  var separator = process.argv.indexOf("--");
package/dist/index.d.ts CHANGED
@@ -38,8 +38,8 @@ type ShootOptions = CaptureOptions & RenderOptions & {
38
38
  /** How many screens to shoot at once. Defaults to the core count. */
39
39
  concurrency?: number;
40
40
  };
41
- declare const MANAGED_FLAGS: readonly ["--screen", "--mock"];
41
+ declare const drivenScreen: (args: readonly string[]) => string | undefined;
42
42
  declare const shootScreen: (screen: string, { command, args, out, mock, ...rest }: ShootOptions) => Promise<string>;
43
43
  declare const shootAll: (options: ShootOptions) => Promise<string[]>;
44
44
 
45
- export { type CaptureOptions, DEFAULT_FONT, MANAGED_FLAGS, type RenderOptions, type ShootOptions, capture, listScreens, shootAll, shootScreen, toImage };
45
+ export { type CaptureOptions, DEFAULT_FONT, type RenderOptions, type ShootOptions, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { DEFAULT_FONT, MANAGED_FLAGS, capture, listScreens, shootAll, shootScreen, toImage } from './chunk-NTFITNMX.js';
1
+ export { DEFAULT_FONT, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage } from './chunk-TKCXCDP2.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/cli-shot",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Automatic screenshots of interactive CLIs — pty capture, terminal emulation, PNG out",
6
6
  "license": "MIT",