@lsst/pik 0.5.0 → 0.5.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/dist/bin/pik.js CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import { program } from '../lib/program.js';
2
+ import { program, initializeProgram } from '../lib/program.js';
3
+ await initializeProgram();
3
4
  program.parse();
@@ -1,3 +1,8 @@
1
1
  import { Command } from 'commander';
2
+ import { type PikPlugin } from '@lsst/pik-core';
2
3
  export declare const program: Command;
4
+ /**
5
+ * Initialize the program by loading config and registering enabled plugins.
6
+ */
7
+ export declare function initializeProgram(): Promise<PikPlugin[]>;
3
8
  //# sourceMappingURL=program.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWpC,eAAO,MAAM,OAAO,SAGG,CAAC"}
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAuB5D,eAAO,MAAM,OAAO,SAGG,CAAC;AAExB;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAgE9D"}
@@ -1,49 +1,87 @@
1
1
  import { Command } from 'commander';
2
2
  import { select, Separator } from '@inquirer/prompts';
3
3
  import pc from 'picocolors';
4
+ import { loadConfig } from '@lsst/pik-core';
4
5
  import { selectPlugin } from '@lsst/pik-plugin-select';
5
6
  import { worktreePlugin } from '@lsst/pik-plugin-worktree';
6
7
  import pkg from '../../package.json' with { type: 'json' };
7
- // List of available plugins
8
- const plugins = [selectPlugin, worktreePlugin];
8
+ // List of all available plugins
9
+ const allPlugins = [selectPlugin, worktreePlugin];
10
+ /**
11
+ * Get plugins that are enabled in the config.
12
+ * A plugin is enabled if its command key exists in the config (even as empty object).
13
+ */
14
+ async function getEnabledPlugins() {
15
+ const config = await loadConfig();
16
+ if (!config) {
17
+ // No config - no plugins enabled for interactive mode
18
+ return [];
19
+ }
20
+ return allPlugins.filter((plugin) => plugin.command in config);
21
+ }
9
22
  export const program = new Command()
10
23
  .name(pkg.name)
11
24
  .description(pkg.description)
12
25
  .version(pkg.version);
13
- // Register all plugins
14
- for (const plugin of plugins) {
15
- plugin.register(program);
16
- }
17
- // Default action: show main menu if multiple plugins, otherwise run default plugin
18
- program.action(async () => {
19
- if (plugins.length === 1) {
20
- // Single plugin - run its default command
21
- const plugin = plugins[0];
22
- const cmd = program.commands.find((c) => c.name() === plugin.command);
23
- if (cmd) {
24
- await cmd.parseAsync([], { from: 'user' });
25
- }
26
+ /**
27
+ * Initialize the program by loading config and registering enabled plugins.
28
+ */
29
+ export async function initializeProgram() {
30
+ const plugins = await getEnabledPlugins();
31
+ // Register only enabled plugins
32
+ for (const plugin of plugins) {
33
+ plugin.register(program);
26
34
  }
27
- else {
28
- // Multiple plugins - show selection menu
29
- const EXIT_VALUE = Symbol('exit');
30
- const selectedPlugin = await select({
31
- message: 'Select a tool',
32
- choices: [
33
- ...plugins.map((plugin) => ({
34
- name: `${pc.bold(plugin.name)} - ${plugin.description}`,
35
- value: plugin,
36
- })),
37
- new Separator(),
38
- { name: pc.dim('Exit'), value: EXIT_VALUE },
39
- ],
40
- });
41
- if (selectedPlugin === EXIT_VALUE) {
35
+ // Default action: show main menu with enabled plugins
36
+ program.action(async () => {
37
+ if (plugins.length === 0) {
38
+ console.log(pc.yellow('No plugins configured.'));
39
+ console.log(pc.dim('Add plugin config to pik.config.ts to enable plugins.'));
40
+ console.log(pc.dim('Example: { select: {}, worktree: {} }'));
42
41
  return;
43
42
  }
44
- const cmd = program.commands.find((c) => c.name() === selectedPlugin.command);
45
- if (cmd) {
46
- await cmd.parseAsync([], { from: 'user' });
43
+ if (plugins.length === 1) {
44
+ // Single plugin - run its default command
45
+ const plugin = plugins[0];
46
+ const cmd = program.commands.find((c) => c.name() === plugin.command);
47
+ if (cmd) {
48
+ await cmd.parseAsync([], { from: 'user' });
49
+ }
47
50
  }
48
- }
49
- });
51
+ else {
52
+ // Multiple plugins - show selection menu in a loop
53
+ const EXIT_VALUE = Symbol('exit');
54
+ while (true) {
55
+ let selectedPlugin;
56
+ try {
57
+ selectedPlugin = await select({
58
+ message: 'Select a tool',
59
+ choices: [
60
+ ...plugins.map((plugin) => ({
61
+ name: `${pc.bold(plugin.name)} - ${plugin.description}`,
62
+ value: plugin,
63
+ })),
64
+ new Separator(),
65
+ { name: pc.dim('Exit'), value: EXIT_VALUE },
66
+ ],
67
+ });
68
+ }
69
+ catch (error) {
70
+ // Handle Ctrl+C
71
+ if (error instanceof Error && error.name === 'ExitPromptError') {
72
+ return;
73
+ }
74
+ throw error;
75
+ }
76
+ if (selectedPlugin === EXIT_VALUE) {
77
+ return;
78
+ }
79
+ const cmd = program.commands.find((c) => c.name() === selectedPlugin.command);
80
+ if (cmd) {
81
+ await cmd.parseAsync([], { from: 'user' });
82
+ }
83
+ }
84
+ }
85
+ });
86
+ return plugins;
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "description": "CLI tool for switching config options in source files",
5
5
  "type": "module",
6
6
  "license": "MIT",