start-command 0.6.0 → 0.7.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# start-command
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9e24fb5: Add --version flag to display comprehensive version and system information. Users can now run `$ --version` or `$ -v` to see the version of start-command, system details, and versions of isolation tools (screen, tmux, docker).
|
|
8
|
+
|
|
3
9
|
## 0.6.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# Case Study: Issue #18 - Missing `--version` Option Support
|
|
2
|
+
|
|
3
|
+
## Executive Summary
|
|
4
|
+
|
|
5
|
+
This case study documents the investigation, root cause analysis, and resolution of Issue #18, which identified the absence of a `--version` flag in the start-command CLI tool. The issue prevented users from easily determining the version of the tool and its dependencies, which is crucial for debugging and troubleshooting.
|
|
6
|
+
|
|
7
|
+
## Timeline of Events
|
|
8
|
+
|
|
9
|
+
### 2025-12-23 12:53:10 UTC - Issue Created
|
|
10
|
+
|
|
11
|
+
- **Reporter**: @konard
|
|
12
|
+
- **Issue**: [#18 - We need to ensure `start-command --version` option is supported](https://github.com/link-foundation/start/issues/18)
|
|
13
|
+
- **Labels**: bug, enhancement
|
|
14
|
+
|
|
15
|
+
### Initial Discovery
|
|
16
|
+
|
|
17
|
+
The user attempted to run `$ --version` expecting version information but instead received unexpected behavior:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
$ --version
|
|
21
|
+
[2025-12-23 12:51:15.314] Starting: --version
|
|
22
|
+
|
|
23
|
+
zsh 5.9 (arm64-apple-darwin24.0)
|
|
24
|
+
|
|
25
|
+
[2025-12-23 12:51:15.322] Finished
|
|
26
|
+
Exit code: 0
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The command was interpreted as trying to execute `--version` as a shell command, which fell through to the default shell (`zsh`) and displayed the shell's version instead of the start-command version.
|
|
30
|
+
|
|
31
|
+
### 2025-12-23 15:59:11 UTC - Issue Updated
|
|
32
|
+
|
|
33
|
+
The issue was updated with additional context and requirements.
|
|
34
|
+
|
|
35
|
+
## Problem Analysis
|
|
36
|
+
|
|
37
|
+
### Root Cause
|
|
38
|
+
|
|
39
|
+
The `start-command` CLI tool (`src/bin/cli.js`) did not have a dedicated handler for the `--version` or `-v` flags. The argument parser treated any unknown flags as potential commands, leading to:
|
|
40
|
+
|
|
41
|
+
1. **Unexpected behavior**: `$ --version` executed `--version` as a shell command
|
|
42
|
+
2. **Poor user experience**: No standard way to check the tool version
|
|
43
|
+
3. **Debugging challenges**: Users couldn't easily verify which version they were running
|
|
44
|
+
4. **Missing dependency information**: No visibility into isolation tool versions (screen, tmux, docker)
|
|
45
|
+
|
|
46
|
+
### Impact Assessment
|
|
47
|
+
|
|
48
|
+
**Severity**: Medium
|
|
49
|
+
|
|
50
|
+
- **User Experience**: Users had no standard way to check version information
|
|
51
|
+
- **Debugging**: Troubleshooting was more difficult without version info
|
|
52
|
+
- **Best Practices**: Missing a fundamental CLI feature expected by users
|
|
53
|
+
|
|
54
|
+
**Affected Components**:
|
|
55
|
+
|
|
56
|
+
- `src/bin/cli.js` - Main CLI entry point
|
|
57
|
+
- Documentation/Help text
|
|
58
|
+
- CI/CD testing coverage
|
|
59
|
+
|
|
60
|
+
## Investigation Process
|
|
61
|
+
|
|
62
|
+
### Analysis Steps
|
|
63
|
+
|
|
64
|
+
1. **Code Review** (`src/bin/cli.js:48-60`):
|
|
65
|
+
- Examined argument parsing logic
|
|
66
|
+
- Identified that only empty arguments triggered usage display
|
|
67
|
+
- No special handling for `--version` flag
|
|
68
|
+
|
|
69
|
+
2. **Argument Parser Review** (`src/lib/args-parser.js`):
|
|
70
|
+
- Confirmed that wrapper options didn't include `--version`
|
|
71
|
+
- Parser passed unknown flags to command execution
|
|
72
|
+
|
|
73
|
+
3. **Test Coverage Review**:
|
|
74
|
+
- Found no existing tests for version display
|
|
75
|
+
- Identified gap in CLI behavior testing
|
|
76
|
+
|
|
77
|
+
4. **User Expectation Analysis**:
|
|
78
|
+
- Standard CLI tools support `--version` and `-v`
|
|
79
|
+
- Users expect version information for debugging
|
|
80
|
+
- Version info should include dependencies
|
|
81
|
+
|
|
82
|
+
## Solution Design
|
|
83
|
+
|
|
84
|
+
### Requirements
|
|
85
|
+
|
|
86
|
+
Based on the issue description, the solution needed to:
|
|
87
|
+
|
|
88
|
+
1. Support both `--version` and `-v` flags
|
|
89
|
+
2. Display start-command version from package.json
|
|
90
|
+
3. Show OS and system information:
|
|
91
|
+
- OS platform
|
|
92
|
+
- OS release
|
|
93
|
+
- Node.js version
|
|
94
|
+
- Architecture
|
|
95
|
+
4. Display versions of isolation tools:
|
|
96
|
+
- screen
|
|
97
|
+
- tmux
|
|
98
|
+
- docker
|
|
99
|
+
5. Indicate when tools are not installed
|
|
100
|
+
6. Include comprehensive CI tests
|
|
101
|
+
|
|
102
|
+
### Implementation Strategy
|
|
103
|
+
|
|
104
|
+
1. **Version Detection** (`src/bin/cli.js:51-55`):
|
|
105
|
+
- Check for `--version` or `-v` as sole argument
|
|
106
|
+
- Call dedicated `printVersion()` function
|
|
107
|
+
- Exit with code 0
|
|
108
|
+
|
|
109
|
+
2. **Version Information Display** (`src/bin/cli.js:62-106`):
|
|
110
|
+
- Read version from `package.json`
|
|
111
|
+
- Use Node.js `os` module for system info
|
|
112
|
+
- Execute version commands for each tool
|
|
113
|
+
- Handle missing tools gracefully
|
|
114
|
+
|
|
115
|
+
3. **Tool Version Helper** (`src/bin/cli.js:108-129`):
|
|
116
|
+
- Generic function to check tool versions
|
|
117
|
+
- Timeout protection (5 seconds)
|
|
118
|
+
- Error handling for missing tools
|
|
119
|
+
- Return first line of version output
|
|
120
|
+
|
|
121
|
+
4. **Test Coverage** (`test/cli.test.js`):
|
|
122
|
+
- Test `--version` flag
|
|
123
|
+
- Test `-v` shorthand
|
|
124
|
+
- Verify correct package version
|
|
125
|
+
- Test basic CLI behavior
|
|
126
|
+
- Ensure usage text includes `--version`
|
|
127
|
+
|
|
128
|
+
## Implementation Details
|
|
129
|
+
|
|
130
|
+
### Code Changes
|
|
131
|
+
|
|
132
|
+
#### 1. CLI Version Handler
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
// Handle --version flag
|
|
136
|
+
if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) {
|
|
137
|
+
printVersion();
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
#### 2. Version Display Function
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
function printVersion() {
|
|
146
|
+
// Get package version
|
|
147
|
+
const packageJson = require('../../package.json');
|
|
148
|
+
const startCommandVersion = packageJson.version;
|
|
149
|
+
|
|
150
|
+
console.log(`start-command version: ${startCommandVersion}`);
|
|
151
|
+
console.log('');
|
|
152
|
+
|
|
153
|
+
// Get OS information
|
|
154
|
+
console.log(`OS: ${process.platform}`);
|
|
155
|
+
console.log(`OS Release: ${os.release()}`);
|
|
156
|
+
console.log(`Node Version: ${process.version}`);
|
|
157
|
+
console.log(`Architecture: ${process.arch}`);
|
|
158
|
+
console.log('');
|
|
159
|
+
|
|
160
|
+
// Check for installed isolation tools
|
|
161
|
+
console.log('Isolation tools:');
|
|
162
|
+
|
|
163
|
+
const screenVersion = getToolVersion('screen', '--version');
|
|
164
|
+
if (screenVersion) {
|
|
165
|
+
console.log(` screen: ${screenVersion}`);
|
|
166
|
+
} else {
|
|
167
|
+
console.log(' screen: not installed');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Similar for tmux and docker...
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### 3. Tool Version Helper
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
function getToolVersion(toolName, versionFlag) {
|
|
178
|
+
try {
|
|
179
|
+
const result = execSync(`${toolName} ${versionFlag}`, {
|
|
180
|
+
encoding: 'utf8',
|
|
181
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
182
|
+
timeout: 5000,
|
|
183
|
+
}).trim();
|
|
184
|
+
|
|
185
|
+
const firstLine = result.split('\n')[0];
|
|
186
|
+
return firstLine;
|
|
187
|
+
} catch {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### 4. Updated Usage Text
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
console.log(' --version, -v Show version information');
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Test Implementation
|
|
200
|
+
|
|
201
|
+
Created `test/cli.test.js` with comprehensive test coverage:
|
|
202
|
+
|
|
203
|
+
- Version flag tests (both `--version` and `-v`)
|
|
204
|
+
- Package version verification
|
|
205
|
+
- Basic CLI behavior tests
|
|
206
|
+
- Usage text verification
|
|
207
|
+
|
|
208
|
+
## Verification and Testing
|
|
209
|
+
|
|
210
|
+
### Test Results
|
|
211
|
+
|
|
212
|
+
All tests passed successfully:
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
✓ CLI version flag
|
|
216
|
+
✓ should display version with --version
|
|
217
|
+
✓ should display version with -v
|
|
218
|
+
✓ should show correct package version
|
|
219
|
+
✓ CLI basic behavior
|
|
220
|
+
✓ should show usage when no arguments provided
|
|
221
|
+
✓ should show usage when no command provided after --
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Total: 71 tests passed across all test suites.
|
|
225
|
+
|
|
226
|
+
### Manual Testing
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
$ bun src/bin/cli.js --version
|
|
230
|
+
start-command version: 0.6.0
|
|
231
|
+
|
|
232
|
+
OS: linux
|
|
233
|
+
OS Release: 6.8.0-90-generic
|
|
234
|
+
Node Version: v24.3.0
|
|
235
|
+
Architecture: x64
|
|
236
|
+
|
|
237
|
+
Isolation tools:
|
|
238
|
+
screen: Screen version 4.09.01 (GNU) 20-Aug-23
|
|
239
|
+
tmux: tmux 3.4
|
|
240
|
+
docker: not installed
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Lessons Learned
|
|
244
|
+
|
|
245
|
+
### What Went Well
|
|
246
|
+
|
|
247
|
+
1. **Clear Requirements**: Issue description provided specific requirements
|
|
248
|
+
2. **Comprehensive Solution**: Implementation exceeded basic requirements by including dependency versions
|
|
249
|
+
3. **Good Test Coverage**: Tests ensure the feature won't regress
|
|
250
|
+
4. **Defensive Programming**: Tool version detection handles missing tools gracefully
|
|
251
|
+
|
|
252
|
+
### Areas for Improvement
|
|
253
|
+
|
|
254
|
+
1. **Earlier Detection**: This fundamental feature should have been included from the start
|
|
255
|
+
2. **Pre-commit Checklist**: Could have caught this during initial development
|
|
256
|
+
3. **User Feedback**: Faster response to user needs
|
|
257
|
+
|
|
258
|
+
### Best Practices Applied
|
|
259
|
+
|
|
260
|
+
1. **Version Information Sources**: Used package.json as single source of truth
|
|
261
|
+
2. **Error Handling**: Gracefully handle missing tools with timeout protection
|
|
262
|
+
3. **User Experience**: Clear, well-formatted output
|
|
263
|
+
4. **Testing**: Comprehensive test coverage for new feature
|
|
264
|
+
5. **Documentation**: Updated usage text to include new flag
|
|
265
|
+
|
|
266
|
+
## Recommendations
|
|
267
|
+
|
|
268
|
+
### Immediate Actions
|
|
269
|
+
|
|
270
|
+
1. ✅ Implement `--version` flag support
|
|
271
|
+
2. ✅ Add comprehensive tests
|
|
272
|
+
3. ✅ Update documentation/usage text
|
|
273
|
+
4. ✅ Verify all existing tests pass
|
|
274
|
+
|
|
275
|
+
### Future Enhancements
|
|
276
|
+
|
|
277
|
+
1. **Version Comparison**: Add ability to check for updates
|
|
278
|
+
2. **JSON Output**: Support `--version --json` for machine-readable output
|
|
279
|
+
3. **Detailed Mode**: Add `--version --verbose` for more detailed information
|
|
280
|
+
4. **Config Info**: Include configuration file locations and settings
|
|
281
|
+
|
|
282
|
+
### Process Improvements
|
|
283
|
+
|
|
284
|
+
1. **Feature Checklist**: Ensure standard CLI features are in initial release:
|
|
285
|
+
- `--help` / `-h`
|
|
286
|
+
- `--version` / `-v`
|
|
287
|
+
- `--verbose` / `-v` (if not conflicting)
|
|
288
|
+
- Exit codes documentation
|
|
289
|
+
2. **User Testing**: Early beta testing to catch missing features
|
|
290
|
+
3. **CLI Standards**: Follow established CLI conventions
|
|
291
|
+
|
|
292
|
+
## Conclusion
|
|
293
|
+
|
|
294
|
+
Issue #18 highlighted the importance of implementing standard CLI features that users expect. The solution not only added the missing `--version` flag but enhanced it to provide comprehensive diagnostic information including OS details and dependency versions.
|
|
295
|
+
|
|
296
|
+
This case study demonstrates the value of:
|
|
297
|
+
|
|
298
|
+
- Clear issue reporting with examples
|
|
299
|
+
- Thorough root cause analysis
|
|
300
|
+
- Comprehensive implementation
|
|
301
|
+
- Strong test coverage
|
|
302
|
+
- Documentation of the investigation process
|
|
303
|
+
|
|
304
|
+
The implementation is now complete and ready for production use, providing users with essential version and diagnostic information for troubleshooting.
|
|
305
|
+
|
|
306
|
+
## References
|
|
307
|
+
|
|
308
|
+
- **Issue**: [#18 - We need to ensure `start-command --version` option is supported](https://github.com/link-foundation/start/issues/18)
|
|
309
|
+
- **Pull Request**: [#21 - Implementation of --version flag](https://github.com/link-foundation/start/pull/21)
|
|
310
|
+
- **Related Files**:
|
|
311
|
+
- `src/bin/cli.js` - Main implementation
|
|
312
|
+
- `test/cli.test.js` - Test coverage
|
|
313
|
+
- `package.json` - Version source
|
|
314
|
+
|
|
315
|
+
## Appendix
|
|
316
|
+
|
|
317
|
+
### A. Example Output
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
$ $ --version
|
|
321
|
+
start-command version: 0.6.0
|
|
322
|
+
|
|
323
|
+
OS: linux
|
|
324
|
+
OS Release: 6.8.0-90-generic
|
|
325
|
+
Node Version: v24.3.0
|
|
326
|
+
Architecture: x64
|
|
327
|
+
|
|
328
|
+
Isolation tools:
|
|
329
|
+
screen: Screen version 4.09.01 (GNU) 20-Aug-23
|
|
330
|
+
tmux: tmux 3.4
|
|
331
|
+
docker: not installed
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### B. Test Coverage Summary
|
|
335
|
+
|
|
336
|
+
- **Total Tests**: 71
|
|
337
|
+
- **New Tests Added**: 5
|
|
338
|
+
- **Pass Rate**: 100%
|
|
339
|
+
- **Coverage Areas**:
|
|
340
|
+
- Version flag handling
|
|
341
|
+
- Package version accuracy
|
|
342
|
+
- CLI basic behavior
|
|
343
|
+
- Usage text verification
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "konard",
|
|
3
|
+
"body": "```\nonard@MacBook-Pro-Konstantin ~ % --version \nzsh: command not found: --version\nkonard@MacBook-Pro-Konstantin ~ % $ --version\n[2025-12-23 12:51:15.314] Starting: --version\n\nzsh 5.9 (arm64-apple-darwin24.0)\n\n[2025-12-23 12:51:15.322] Finished\nExit code: 0\nLog saved: /var/folders/cl/831lqjgd58v5mb_m74cfdfcw0000gn/T/start-command-1766494275314-ws2i7w.log\nkonard@MacBook-Pro-Konstantin ~ % $ --version --\nError: No command provided\nUsage: $ [options] [--] \u003ccommand\u003e [args...]\n $ \u003ccommand\u003e [args...]\n\nOptions:\n --isolated, -i \u003cenvironment\u003e Run in isolated environment (screen, tmux, docker, zellij)\n --attached, -a Run in attached mode (foreground)\n --detached, -d Run in detached mode (background)\n --session, -s \u003cname\u003e Session name for isolation\n --image \u003cimage\u003e Docker image (required for docker isolation)\n\nExamples:\n $ echo \"Hello World\"\n $ npm test\n $ --isolated tmux -- npm start\n $ -i screen -d npm start\n $ --isolated docker --image node:20 -- npm install\n\nFeatures:\n - Logs all output to temporary directory\n - Displays timestamps and exit codes\n - Auto-reports failures for NPM packages (when gh is available)\n - Natural language command aliases (via substitutions.lino)\n - Process isolation via screen, tmux, zellij, or docker\n\nAlias examples:\n $ install lodash npm package -\u003e npm install lodash\n $ install 4.17.21 version of lodash npm package -\u003e npm install lodash@4.17.21\n $ clone https://github.com/user/repo repository -\u003e git clone https://github.com/user/repo\n```\n\nThat should be the root source of debug information.\n\nIt should display version of start-command itself, version of OS, version of screen and docker and tmux (all if installed).\n\nAlso it should be added to CI tests, so never again we will have the problem.\n\nPlease download all logs and data related about the issue to this repository, make sure we compile that data to `./docs/case-studies/issue-{id}` folder, and use it to do deep case study analysis (also make sure to search online for additional facts and data), in which we will reconstruct timeline/sequence of events, find root causes of the problem, and propose possible solutions.",
|
|
4
|
+
"createdAt": "2025-12-23T12:53:10Z",
|
|
5
|
+
"title": "We need to ensure `start-command --version` option is supported",
|
|
6
|
+
"updatedAt": "2025-12-23T15:59:11Z"
|
|
7
|
+
}
|
package/package.json
CHANGED
package/src/bin/cli.js
CHANGED
|
@@ -48,11 +48,86 @@ const config = {
|
|
|
48
48
|
// Get all arguments passed after the command
|
|
49
49
|
const args = process.argv.slice(2);
|
|
50
50
|
|
|
51
|
+
// Handle --version flag
|
|
52
|
+
if (args.length === 1 && (args[0] === '--version' || args[0] === '-v')) {
|
|
53
|
+
printVersion();
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
if (args.length === 0) {
|
|
52
58
|
printUsage();
|
|
53
59
|
process.exit(0);
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Print version information
|
|
64
|
+
*/
|
|
65
|
+
function printVersion() {
|
|
66
|
+
// Get package version
|
|
67
|
+
const packageJson = require('../../package.json');
|
|
68
|
+
const startCommandVersion = packageJson.version;
|
|
69
|
+
|
|
70
|
+
console.log(`start-command version: ${startCommandVersion}`);
|
|
71
|
+
console.log('');
|
|
72
|
+
|
|
73
|
+
// Get OS information
|
|
74
|
+
console.log(`OS: ${process.platform}`);
|
|
75
|
+
console.log(`OS Release: ${os.release()}`);
|
|
76
|
+
console.log(`Node Version: ${process.version}`);
|
|
77
|
+
console.log(`Architecture: ${process.arch}`);
|
|
78
|
+
console.log('');
|
|
79
|
+
|
|
80
|
+
// Check for installed isolation tools
|
|
81
|
+
console.log('Isolation tools:');
|
|
82
|
+
|
|
83
|
+
// Check screen
|
|
84
|
+
const screenVersion = getToolVersion('screen', '--version');
|
|
85
|
+
if (screenVersion) {
|
|
86
|
+
console.log(` screen: ${screenVersion}`);
|
|
87
|
+
} else {
|
|
88
|
+
console.log(' screen: not installed');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Check tmux
|
|
92
|
+
const tmuxVersion = getToolVersion('tmux', '-V');
|
|
93
|
+
if (tmuxVersion) {
|
|
94
|
+
console.log(` tmux: ${tmuxVersion}`);
|
|
95
|
+
} else {
|
|
96
|
+
console.log(' tmux: not installed');
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Check docker
|
|
100
|
+
const dockerVersion = getToolVersion('docker', '--version');
|
|
101
|
+
if (dockerVersion) {
|
|
102
|
+
console.log(` docker: ${dockerVersion}`);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(' docker: not installed');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get version of an installed tool
|
|
110
|
+
* @param {string} toolName - Name of the tool
|
|
111
|
+
* @param {string} versionFlag - Flag to get version (e.g., '--version', '-V')
|
|
112
|
+
* @returns {string|null} Version string or null if not installed
|
|
113
|
+
*/
|
|
114
|
+
function getToolVersion(toolName, versionFlag) {
|
|
115
|
+
try {
|
|
116
|
+
const result = execSync(`${toolName} ${versionFlag}`, {
|
|
117
|
+
encoding: 'utf8',
|
|
118
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
119
|
+
timeout: 5000,
|
|
120
|
+
}).trim();
|
|
121
|
+
|
|
122
|
+
// Extract version number from output
|
|
123
|
+
// Most tools output version in various formats, so we'll return the first line
|
|
124
|
+
const firstLine = result.split('\n')[0];
|
|
125
|
+
return firstLine;
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
56
131
|
/**
|
|
57
132
|
* Print usage information
|
|
58
133
|
*/
|
|
@@ -70,6 +145,7 @@ function printUsage() {
|
|
|
70
145
|
console.log(
|
|
71
146
|
' --image <image> Docker image (required for docker isolation)'
|
|
72
147
|
);
|
|
148
|
+
console.log(' --version, -v Show version information');
|
|
73
149
|
console.log('');
|
|
74
150
|
console.log('Examples:');
|
|
75
151
|
console.log(' $ echo "Hello World"');
|
package/test/cli.test.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for the CLI
|
|
4
|
+
* Tests version flag and basic CLI behavior
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const { describe, it } = require('node:test');
|
|
8
|
+
const assert = require('assert');
|
|
9
|
+
const { spawnSync } = require('child_process');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
|
|
13
|
+
// Path to the CLI script
|
|
14
|
+
const CLI_PATH = path.join(__dirname, '../src/bin/cli.js');
|
|
15
|
+
|
|
16
|
+
// Helper to run CLI
|
|
17
|
+
function runCLI(args = []) {
|
|
18
|
+
return spawnSync('bun', [CLI_PATH, ...args], {
|
|
19
|
+
encoding: 'utf8',
|
|
20
|
+
env: {
|
|
21
|
+
...process.env,
|
|
22
|
+
START_DISABLE_AUTO_ISSUE: '1',
|
|
23
|
+
START_DISABLE_LOG_UPLOAD: '1',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('CLI version flag', () => {
|
|
29
|
+
it('should display version with --version', () => {
|
|
30
|
+
const result = runCLI(['--version']);
|
|
31
|
+
|
|
32
|
+
assert.strictEqual(result.status, 0, 'Exit code should be 0');
|
|
33
|
+
|
|
34
|
+
// Check for key elements in version output
|
|
35
|
+
assert.ok(
|
|
36
|
+
result.stdout.includes('start-command version:'),
|
|
37
|
+
'Should display start-command version'
|
|
38
|
+
);
|
|
39
|
+
assert.ok(result.stdout.includes('OS:'), 'Should display OS');
|
|
40
|
+
assert.ok(
|
|
41
|
+
result.stdout.includes('OS Release:'),
|
|
42
|
+
'Should display OS Release'
|
|
43
|
+
);
|
|
44
|
+
assert.ok(
|
|
45
|
+
result.stdout.includes('Node Version:'),
|
|
46
|
+
'Should display Node Version'
|
|
47
|
+
);
|
|
48
|
+
assert.ok(
|
|
49
|
+
result.stdout.includes('Architecture:'),
|
|
50
|
+
'Should display Architecture'
|
|
51
|
+
);
|
|
52
|
+
assert.ok(
|
|
53
|
+
result.stdout.includes('Isolation tools:'),
|
|
54
|
+
'Should display Isolation tools section'
|
|
55
|
+
);
|
|
56
|
+
assert.ok(
|
|
57
|
+
result.stdout.includes('screen:'),
|
|
58
|
+
'Should check for screen installation'
|
|
59
|
+
);
|
|
60
|
+
assert.ok(
|
|
61
|
+
result.stdout.includes('tmux:'),
|
|
62
|
+
'Should check for tmux installation'
|
|
63
|
+
);
|
|
64
|
+
assert.ok(
|
|
65
|
+
result.stdout.includes('docker:'),
|
|
66
|
+
'Should check for docker installation'
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should display version with -v', () => {
|
|
71
|
+
const result = runCLI(['-v']);
|
|
72
|
+
|
|
73
|
+
assert.strictEqual(result.status, 0, 'Exit code should be 0');
|
|
74
|
+
assert.ok(
|
|
75
|
+
result.stdout.includes('start-command version:'),
|
|
76
|
+
'Should display start-command version'
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should show correct package version', () => {
|
|
81
|
+
const result = runCLI(['--version']);
|
|
82
|
+
const packageJson = JSON.parse(
|
|
83
|
+
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8')
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
assert.ok(
|
|
87
|
+
result.stdout.includes(`start-command version: ${packageJson.version}`),
|
|
88
|
+
`Should display version ${packageJson.version}`
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe('CLI basic behavior', () => {
|
|
94
|
+
it('should show usage when no arguments provided', () => {
|
|
95
|
+
const result = runCLI([]);
|
|
96
|
+
|
|
97
|
+
assert.strictEqual(result.status, 0, 'Exit code should be 0');
|
|
98
|
+
assert.ok(result.stdout.includes('Usage:'), 'Should display usage');
|
|
99
|
+
assert.ok(
|
|
100
|
+
result.stdout.includes('--version'),
|
|
101
|
+
'Usage should mention --version flag'
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should show usage when no command provided after --', () => {
|
|
106
|
+
const result = runCLI(['--']);
|
|
107
|
+
|
|
108
|
+
assert.strictEqual(result.status, 0, 'Exit code should be 0');
|
|
109
|
+
assert.ok(result.stdout.includes('Usage:'), 'Should display usage');
|
|
110
|
+
});
|
|
111
|
+
});
|