@lsst/pik 0.6.1 → 0.6.3

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.
@@ -1,3 +1,3 @@
1
- import type { PikPlugin } from '@lsst/pik-core';
1
+ import { type PikPlugin } from '@lsst/pik-core';
2
2
  export declare const killportPlugin: PikPlugin;
3
3
  //# sourceMappingURL=killport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"killport.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/killport.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAuChD,eAAO,MAAM,cAAc,EAAE,SAsD5B,CAAC"}
1
+ {"version":3,"file":"killport.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/killport.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6E5D,eAAO,MAAM,cAAc,EAAE,SAgE5B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { execSync } from 'child_process';
2
- import { confirm } from '@inquirer/prompts';
2
+ import { confirm, input } from '@inquirer/prompts';
3
3
  import pc from 'picocolors';
4
+ import { loadConfig } from '@lsst/pik-core';
4
5
  function getProcessesOnPort(port) {
5
6
  try {
6
7
  const output = execSync(`lsof -ti:${port}`, { encoding: 'utf-8' });
@@ -33,6 +34,35 @@ function killProcess(pid) {
33
34
  return false;
34
35
  }
35
36
  }
37
+ async function killPortInteractive(port, skipConfirm) {
38
+ const processes = getProcessesOnPort(port);
39
+ if (processes.length === 0) {
40
+ console.log(pc.yellow(`No process found on port ${port}`));
41
+ return;
42
+ }
43
+ console.log(pc.bold(`Processes on port ${port}:`));
44
+ for (const proc of processes) {
45
+ console.log(` ${pc.cyan(proc.pid.toString())} - ${proc.command}`);
46
+ }
47
+ if (!skipConfirm) {
48
+ const shouldKill = await confirm({
49
+ message: `Kill ${processes.length} process${processes.length > 1 ? 'es' : ''}?`,
50
+ default: true,
51
+ });
52
+ if (!shouldKill) {
53
+ console.log(pc.dim('Cancelled'));
54
+ return;
55
+ }
56
+ }
57
+ for (const proc of processes) {
58
+ if (killProcess(proc.pid)) {
59
+ console.log(pc.green(`✓ Killed ${proc.pid} (${proc.command})`));
60
+ }
61
+ else {
62
+ console.log(pc.red(`✗ Failed to kill ${proc.pid}`));
63
+ }
64
+ }
65
+ }
36
66
  export const killportPlugin = {
37
67
  name: 'Killport',
38
68
  description: 'Kill processes on specific ports',
@@ -43,39 +73,53 @@ export const killportPlugin = {
43
73
  .command('killport')
44
74
  .alias('kp')
45
75
  .description('Kill process running on a specific port')
46
- .argument('<port>', 'Port number')
76
+ .argument('[port]', 'Port number (interactive if not provided)')
47
77
  .option('-y, --yes', 'Skip confirmation')
78
+ .option('--config', 'Output plugin config as JSON')
79
+ .option('--json', 'Use JSON output format')
48
80
  .action(async (portArg, options) => {
49
- const port = parseInt(portArg, 10);
50
- if (isNaN(port) || port < 1 || port > 65535) {
51
- console.error(pc.red(`Invalid port: ${portArg}`));
52
- process.exit(1);
53
- }
54
- const processes = getProcessesOnPort(port);
55
- if (processes.length === 0) {
56
- console.log(pc.yellow(`No process found on port ${port}`));
81
+ const pikConfig = await loadConfig();
82
+ const killportConfig = pikConfig?.killport || {};
83
+ const defaultPort = killportConfig.defaultPort;
84
+ if (options.config) {
85
+ if (options.json) {
86
+ console.log(JSON.stringify(killportConfig));
87
+ }
88
+ else {
89
+ console.log('defaultPort:', defaultPort ?? 'not set');
90
+ }
57
91
  return;
58
92
  }
59
- console.log(pc.bold(`Processes on port ${port}:`));
60
- for (const proc of processes) {
61
- console.log(` ${pc.cyan(proc.pid.toString())} - ${proc.command}`);
62
- }
63
- if (!options.yes) {
64
- const shouldKill = await confirm({
65
- message: `Kill ${processes.length} process${processes.length > 1 ? 'es' : ''}?`,
66
- default: true,
67
- });
68
- if (!shouldKill) {
69
- console.log(pc.dim('Cancelled'));
70
- return;
93
+ if (portArg) {
94
+ const port = parseInt(portArg, 10);
95
+ if (isNaN(port) || port < 1 || port > 65535) {
96
+ console.error(pc.red(`Invalid port: ${portArg}`));
97
+ process.exit(1);
71
98
  }
99
+ await killPortInteractive(port, options.yes ?? false);
72
100
  }
73
- for (const proc of processes) {
74
- if (killProcess(proc.pid)) {
75
- console.log(pc.green(`✓ Killed ${proc.pid} (${proc.command})`));
101
+ else {
102
+ // Interactive mode - prompt for port number with default
103
+ try {
104
+ const portInput = await input({
105
+ message: 'Port number:',
106
+ default: defaultPort?.toString(),
107
+ validate: (value) => {
108
+ const num = parseInt(value, 10);
109
+ if (isNaN(num) || num < 1 || num > 65535) {
110
+ return 'Please enter a valid port number (1-65535)';
111
+ }
112
+ return true;
113
+ },
114
+ });
115
+ const port = parseInt(portInput, 10);
116
+ await killPortInteractive(port, options.yes ?? false);
76
117
  }
77
- else {
78
- console.log(pc.red(`✗ Failed to kill ${proc.pid}`));
118
+ catch (error) {
119
+ if (error instanceof Error && error.name === 'ExitPromptError') {
120
+ return;
121
+ }
122
+ throw error;
79
123
  }
80
124
  }
81
125
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "CLI tool for switching config options in source files",
5
5
  "type": "module",
6
6
  "license": "MIT",