runspec-node 0.16.0 → 0.17.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/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -68
- package/dist/cli.js.map +1 -1
- package/dist/jump.d.ts +5 -5
- package/dist/jump.d.ts.map +1 -1
- package/dist/jump.js +17 -33
- package/dist/jump.js.map +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +0 -17
- package/dist/loader.js.map +1 -1
- package/dist/models.d.ts +0 -10
- package/dist/models.d.ts.map +1 -1
- package/dist/parser.d.ts +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +49 -17
- package/dist/parser.js.map +1 -1
- package/dist/runspec.toml +10 -10
- package/package.json +1 -1
- package/src/cli.ts +18 -78
- package/src/jump.ts +16 -38
- package/src/loader.ts +1 -19
- package/src/models.ts +0 -11
- package/src/parser.ts +50 -17
- package/src/runspec.toml +10 -10
- package/tests/test_cli_init.test.ts +2 -2
- package/tests/test_parser.test.ts +92 -0
|
@@ -65,3 +65,95 @@ describe('env resolution', () => {
|
|
|
65
65
|
expect(args['quality']).toBe(85);
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
// ── help display ──────────────────────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
describe('help display', () => {
|
|
72
|
+
let logSpy: jest.SpyInstance;
|
|
73
|
+
let exitSpy: jest.SpyInstance;
|
|
74
|
+
let output: string[];
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
output = [];
|
|
78
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation((...args) => {
|
|
79
|
+
output.push(args.join(' '));
|
|
80
|
+
});
|
|
81
|
+
exitSpy = jest.spyOn(process, 'exit').mockImplementation((() => {
|
|
82
|
+
throw new Error('__exit__');
|
|
83
|
+
}) as never);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
afterEach(() => {
|
|
87
|
+
logSpy.mockRestore();
|
|
88
|
+
exitSpy.mockRestore();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const runHelp = (toml: string, name: string, argv: string[]): string => {
|
|
92
|
+
const configPath = makeTmpConfig(toml);
|
|
93
|
+
try {
|
|
94
|
+
parse({ scriptName: name, argv, configPath });
|
|
95
|
+
} catch (e) {
|
|
96
|
+
if ((e as Error).message !== '__exit__') throw e;
|
|
97
|
+
}
|
|
98
|
+
return output.join('\n');
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
test('usage line renders <command> after parent args', () => {
|
|
102
|
+
const toml = `
|
|
103
|
+
[pipeline]
|
|
104
|
+
description = "Run a pipeline"
|
|
105
|
+
[pipeline.args]
|
|
106
|
+
verbose = {type = "flag"}
|
|
107
|
+
config = {type = "path"}
|
|
108
|
+
[pipeline.commands.run]
|
|
109
|
+
description = "Run it"
|
|
110
|
+
`;
|
|
111
|
+
const out = runHelp(toml, 'pipeline', ['--help']);
|
|
112
|
+
const usage = out.split('\n').find((l) => l.startsWith('Usage:'))!;
|
|
113
|
+
expect(usage.indexOf('--verbose')).toBeLessThan(usage.indexOf('<command>'));
|
|
114
|
+
expect(usage.indexOf('--config')).toBeLessThan(usage.indexOf('<command>'));
|
|
115
|
+
expect(usage.trimEnd().endsWith('<command>')).toBe(true);
|
|
116
|
+
expect(out).toContain('Commands:');
|
|
117
|
+
expect(out).toContain('run');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('nested subcommands resolve to full path in usage', () => {
|
|
121
|
+
const toml = `
|
|
122
|
+
[outer]
|
|
123
|
+
[outer.commands.inner]
|
|
124
|
+
[outer.commands.inner.commands.deep]
|
|
125
|
+
description = "Deepest"
|
|
126
|
+
[outer.commands.inner.commands.deep.args]
|
|
127
|
+
bar = {type = "str", required = true}
|
|
128
|
+
`;
|
|
129
|
+
const out = runHelp(toml, 'outer', ['inner', 'deep', '--help']);
|
|
130
|
+
expect(out).toContain('Usage: outer inner deep');
|
|
131
|
+
expect(out).toContain('--bar');
|
|
132
|
+
expect(out).toContain('Deepest');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('choice options render inline in usage', () => {
|
|
136
|
+
const toml = `
|
|
137
|
+
[greet]
|
|
138
|
+
[greet.args]
|
|
139
|
+
fmt = {type = "choice", options = ["text", "json", "xml"], default = "text"}
|
|
140
|
+
`;
|
|
141
|
+
const out = runHelp(toml, 'greet', ['--help']);
|
|
142
|
+
expect(out).toContain('[--fmt <text|json|xml>]');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('usage places <command> before -- <rest>', () => {
|
|
146
|
+
const toml = `
|
|
147
|
+
[multi]
|
|
148
|
+
[multi.args]
|
|
149
|
+
host = {type = "str", position = 1}
|
|
150
|
+
extra = {type = "rest"}
|
|
151
|
+
[multi.commands.run]
|
|
152
|
+
description = "Run it"
|
|
153
|
+
`;
|
|
154
|
+
const out = runHelp(toml, 'multi', ['--help']);
|
|
155
|
+
const usage = out.split('\n').find((l) => l.startsWith('Usage:'))!;
|
|
156
|
+
expect(usage.indexOf('<host>')).toBeLessThan(usage.indexOf('<command>'));
|
|
157
|
+
expect(usage.indexOf('<command>')).toBeLessThan(usage.indexOf('-- <extra>'));
|
|
158
|
+
});
|
|
159
|
+
});
|