@flowscripter/example-cli 1.4.1 → 1.6.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/bun.lock +6 -6
- package/functional_tests/features/environment.py +8 -0
- package/functional_tests/features/executable.feature +2 -0
- package/functional_tests/features/non_tty.feature +18 -0
- package/functional_tests/features/plugin.feature +19 -1
- package/functional_tests/features/steps/executable.py +43 -1
- package/functional_tests/features/steps/plugin.py +21 -0
- package/functional_tests/features/support/subprocess_wrapper.py +5 -2
- package/package.json +3 -3
- package/src/cli.ts +1 -0
package/bun.lock
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "
|
|
9
|
-
"@flowscripter/dynamic-plugin-framework": "1.
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "2.3.1",
|
|
9
|
+
"@flowscripter/dynamic-plugin-framework": "1.11.1",
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@types/bun": "^1.3.14",
|
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
"packages": {
|
|
23
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@
|
|
23
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@2.3.1", "", { "dependencies": { "@flowscripter/dynamic-cli-framework-api": "^1.2.0", "@flowscripter/dynamic-plugin-framework": "1.11.1", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.9.4", "semver": "^7.7.3", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-Fbj+GvAy4p4+bpuWvm/jfyeOyhcO7WAs9QWDc4HdHN4A/zyKpRSGaOEA5CH9LIcllR0che2UPFJvFqAuqb40qg=="],
|
|
24
24
|
|
|
25
|
-
"@flowscripter/dynamic-
|
|
25
|
+
"@flowscripter/dynamic-cli-framework-api": ["@flowscripter/dynamic-cli-framework-api@1.2.0", "", { "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-ajR6PwQQwsQN96OH3OwO0SH5h3TGY3lLPM5lIYNUCpUXrOZ9MYJtsXvDcDKz8U/heWe0FBJeRY0nsNDJV4p9Vw=="],
|
|
26
|
+
|
|
27
|
+
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@1.11.1", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^7.0.2" } }, "sha512-m8bioReoQzzm7uj3sxXLH7Haclyj1UWnPCSxy2QXvGQ2yp24H1GnzqohVnXo3JfBpJzmCUAaHT+lAhYu9Gh6Aw=="],
|
|
26
28
|
|
|
27
29
|
"@oxfmt/binding-android-arm-eabi": ["@oxfmt/binding-android-arm-eabi@0.56.0", "", { "os": "android", "cpu": "arm" }, "sha512-CSCxi7ovYojgfdPOdUb9T508HKeAdDIKeRGg7x8IZwVJrWz9gVgX7MbUnFqtQAE4QvoNo07mj2JlwnOzJw4qqA=="],
|
|
28
30
|
|
|
@@ -146,8 +148,6 @@
|
|
|
146
148
|
|
|
147
149
|
"undici-types": ["undici-types@8.3.0", "", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="],
|
|
148
150
|
|
|
149
|
-
"@flowscripter/dynamic-cli-framework/@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@1.10.1", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-9yUz64tj1R2RRuUAtHEqJf4hZYF4cIbUGHOOM32q4jDsdd4g5BQKa1gPhh7UPqHggs890XJxgE6R12opKKudAA=="],
|
|
150
|
-
|
|
151
151
|
"bun-types/@types/node": ["@types/node@22.13.9", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw=="],
|
|
152
152
|
|
|
153
153
|
"emphasize/highlight.js": ["highlight.js@11.9.0", "", {}, "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw=="],
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import platform
|
|
2
3
|
|
|
3
4
|
from support.pexpect_wrapper import PExpectWrapper
|
|
4
5
|
|
|
6
|
+
IS_WINDOWS = platform.system() == 'Windows'
|
|
7
|
+
|
|
5
8
|
|
|
6
9
|
def before_scenario(context, scenario):
|
|
7
10
|
|
|
11
|
+
if IS_WINDOWS and 'requires_tty' in scenario.effective_tags:
|
|
12
|
+
scenario.skip('pexpect on Windows uses PopenSpawn (pipes), which cannot provide '
|
|
13
|
+
'the real TTY this scenario depends on')
|
|
14
|
+
return
|
|
15
|
+
|
|
8
16
|
context.config.setup_logging()
|
|
9
17
|
context.pexpect_wrapper = PExpectWrapper(os.environ.get('EXECUTABLE'))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Feature: Executable
|
|
2
2
|
|
|
3
|
+
@requires_tty
|
|
3
4
|
Scenario: No command specified
|
|
4
5
|
When the executable is launched
|
|
5
6
|
Then the executable should complete with exit code 2
|
|
@@ -30,6 +31,7 @@ Feature: Executable
|
|
|
30
31
|
And the executable should have output "Chisel Font ASCII Banner Demo"
|
|
31
32
|
And the executable should have output "ASCII Banner Subtitle Demo"
|
|
32
33
|
|
|
34
|
+
@requires_tty
|
|
33
35
|
Scenario: Image demo
|
|
34
36
|
When the executable is launched with "demo:image"
|
|
35
37
|
Then the executable should complete with exit code 0
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Feature: Non-TTY (piped/non-interactive) mode
|
|
2
|
+
|
|
3
|
+
Scenario: Printing demo runs non-interactively without ANSI escape codes
|
|
4
|
+
When the executable stdout is captured for "demo:printing"
|
|
5
|
+
Then the captured process should complete with exit code 0
|
|
6
|
+
And the stdout should contain "Hello, World!"
|
|
7
|
+
And the stdout should not contain ANSI escape codes
|
|
8
|
+
And the stderr should not contain ANSI escape codes
|
|
9
|
+
|
|
10
|
+
Scenario: Printing demo runs non-interactively with piped stdin
|
|
11
|
+
When the executable stdout is captured for "demo:printing" with piped stdin
|
|
12
|
+
Then the captured process should complete with exit code 0
|
|
13
|
+
And the stdout should contain "Hello, World!"
|
|
14
|
+
|
|
15
|
+
Scenario: Prompting demo fails cleanly instead of hanging when run non-interactively
|
|
16
|
+
When the executable stdout is captured for "demo:prompting Alice"
|
|
17
|
+
Then the captured process should complete with exit code 3
|
|
18
|
+
And the stderr should contain "Execution error"
|
|
@@ -14,22 +14,34 @@ Feature: Plugin management
|
|
|
14
14
|
Then the executable should complete with exit code 0
|
|
15
15
|
|
|
16
16
|
Scenario: Install example-cli-plugin
|
|
17
|
-
When the executable stdout is captured for "--no-prompt plugin:add @flowscripter/example-cli-plugin"
|
|
17
|
+
When the executable stdout is captured for "--no-prompt plugin:add @flowscripter/example-cli-plugin" with timeout 60s
|
|
18
18
|
Then the captured process should complete with exit code 0
|
|
19
19
|
And the stdout should contain "installed"
|
|
20
20
|
And the stderr should contain "Searching for plugin: @flowscripter/example-cli-plugin\n"
|
|
21
21
|
And the stderr should contain "Installing @flowscripter/example-cli-plugin...\n"
|
|
22
22
|
|
|
23
|
+
Scenario: Installing example-cli-plugin does not pull in the full dynamic-cli-framework
|
|
24
|
+
Then the installed plugin dependencies should not include "figlet, emphasize, highlight.js, prettier, supports-color, supports-terminal-graphics"
|
|
25
|
+
|
|
23
26
|
Scenario: List installed plugins after install
|
|
24
27
|
When the executable is launched with "plugin:list"
|
|
25
28
|
Then the executable should complete with exit code 0
|
|
26
29
|
And the executable should have output "example-cli-plugin"
|
|
27
30
|
|
|
31
|
+
Scenario: Plugin dependencies are installed
|
|
32
|
+
Then the plugin node_modules directory should contain "cowsay"
|
|
33
|
+
And the plugin node_modules directory should contain "@flowscripter/dynamic-cli-framework-api"
|
|
34
|
+
|
|
28
35
|
Scenario: Use hello command from installed plugin
|
|
29
36
|
When the executable is launched with "hello"
|
|
30
37
|
Then the executable should complete with exit code 0
|
|
31
38
|
And the executable should have output "Hello"
|
|
32
39
|
|
|
40
|
+
Scenario: Use hello_rust command from installed plugin
|
|
41
|
+
When the executable is launched with "hello_rust"
|
|
42
|
+
Then the executable should complete with exit code 0
|
|
43
|
+
And the executable should have output "World 4"
|
|
44
|
+
|
|
33
45
|
Scenario: Remove example-cli-plugin
|
|
34
46
|
When the executable is launched with "plugin:remove @flowscripter/example-cli-plugin"
|
|
35
47
|
Then the executable should complete with exit code 0
|
|
@@ -37,3 +49,9 @@ Feature: Plugin management
|
|
|
37
49
|
Scenario: Plugin no longer listed after removal
|
|
38
50
|
When the executable is launched with "plugin:list"
|
|
39
51
|
Then the executable should complete with exit code 0
|
|
52
|
+
|
|
53
|
+
Scenario: No orphaned transitive dependencies remain after removal
|
|
54
|
+
Then the plugin node_modules directory should not contain "@flowscripter/example-cli-plugin"
|
|
55
|
+
And the plugin node_modules directory should not contain "cowsay"
|
|
56
|
+
And the plugin node_modules directory should not contain "@flowscripter/template-bun-rust-library"
|
|
57
|
+
And the plugin node_modules directory should not contain "@flowscripter/dynamic-cli-framework"
|
|
@@ -35,10 +35,24 @@ def step_impl(context, args):
|
|
|
35
35
|
context.subprocess_wrapper = wrapper
|
|
36
36
|
|
|
37
37
|
|
|
38
|
+
@when('the executable stdout is captured for "{args}" with timeout {timeout:d}s')
|
|
39
|
+
def step_impl(context, args, timeout):
|
|
40
|
+
wrapper = SubprocessWrapper(os.environ.get('EXECUTABLE'))
|
|
41
|
+
wrapper.run(args, timeout=timeout)
|
|
42
|
+
context.subprocess_wrapper = wrapper
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@when('the executable stdout is captured for "{args}" with piped stdin')
|
|
46
|
+
def step_impl(context, args):
|
|
47
|
+
wrapper = SubprocessWrapper(os.environ.get('EXECUTABLE'))
|
|
48
|
+
wrapper.run(args, stdin_text='')
|
|
49
|
+
context.subprocess_wrapper = wrapper
|
|
50
|
+
|
|
51
|
+
|
|
38
52
|
@when('bash completions are requested for "{line}" at cursor {cursor:d}')
|
|
39
53
|
def step_impl(context, line, cursor):
|
|
40
54
|
wrapper = SubprocessWrapper(os.environ.get('EXECUTABLE'))
|
|
41
|
-
wrapper.run('
|
|
55
|
+
wrapper.run('completion:complete bash "{}" {}'.format(line, cursor))
|
|
42
56
|
context.subprocess_wrapper = wrapper
|
|
43
57
|
|
|
44
58
|
|
|
@@ -73,3 +87,31 @@ def step_impl(context, text):
|
|
|
73
87
|
def step_impl(context):
|
|
74
88
|
assert context.subprocess_wrapper.stdout.strip() == '', \
|
|
75
89
|
'expected empty stdout but got {!r}'.format(context.subprocess_wrapper.stdout)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@then('the stdout should not contain ANSI escape codes')
|
|
93
|
+
def step_impl(context):
|
|
94
|
+
assert '\x1b[' not in context.subprocess_wrapper.stdout, \
|
|
95
|
+
'expected no ANSI escape codes in stdout but got {!r}'.format(
|
|
96
|
+
context.subprocess_wrapper.stdout)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@then('the stderr should not contain ANSI escape codes')
|
|
100
|
+
def step_impl(context):
|
|
101
|
+
assert '\x1b[' not in context.subprocess_wrapper.stderr, \
|
|
102
|
+
'expected no ANSI escape codes in stderr but got {!r}'.format(
|
|
103
|
+
context.subprocess_wrapper.stderr)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@then('the installed plugin dependencies should not include "{packages}"')
|
|
107
|
+
def step_impl(context, packages):
|
|
108
|
+
plugins_node_modules = os.path.expanduser('~/.example-cli/plugins/node_modules')
|
|
109
|
+
found = []
|
|
110
|
+
for package in packages.split(','):
|
|
111
|
+
package = package.strip()
|
|
112
|
+
for root, dirs, _ in os.walk(plugins_node_modules):
|
|
113
|
+
if package in dirs:
|
|
114
|
+
found.append(os.path.join(root, package))
|
|
115
|
+
assert not found, \
|
|
116
|
+
'expected none of the heavy framework dependencies to be installed alongside ' \
|
|
117
|
+
'the plugin, but found: {!r}'.format(found)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from behave import then
|
|
4
|
+
|
|
5
|
+
PLUGINS_NODE_MODULES = os.path.expanduser(
|
|
6
|
+
os.path.join('~', '.example-cli', 'plugins', 'node_modules')
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@then('the plugin node_modules directory should contain "{name}"')
|
|
11
|
+
def step_impl(context, name):
|
|
12
|
+
path = os.path.join(PLUGINS_NODE_MODULES, name)
|
|
13
|
+
assert os.path.exists(path), \
|
|
14
|
+
'expected {!r} to exist under {!r}'.format(name, PLUGINS_NODE_MODULES)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@then('the plugin node_modules directory should not contain "{name}"')
|
|
18
|
+
def step_impl(context, name):
|
|
19
|
+
path = os.path.join(PLUGINS_NODE_MODULES, name)
|
|
20
|
+
assert not os.path.exists(path), \
|
|
21
|
+
'expected {!r} not to exist under {!r}'.format(name, PLUGINS_NODE_MODULES)
|
|
@@ -13,10 +13,13 @@ class SubprocessWrapper:
|
|
|
13
13
|
self.stderr = None
|
|
14
14
|
self.returncode = None
|
|
15
15
|
|
|
16
|
-
def run(self, args=''):
|
|
16
|
+
def run(self, args='', stdin_text=None, timeout=30):
|
|
17
17
|
cmd = [self.executable] + (shlex.split(args) if args else [])
|
|
18
18
|
log.debug('running: {}'.format(cmd))
|
|
19
|
-
result = subprocess.run(
|
|
19
|
+
result = subprocess.run(
|
|
20
|
+
cmd, capture_output=True, text=True, timeout=timeout, input=stdin_text,
|
|
21
|
+
encoding='utf-8', errors='replace'
|
|
22
|
+
)
|
|
20
23
|
self.stdout = result.stdout
|
|
21
24
|
self.stderr = result.stderr
|
|
22
25
|
self.returncode = result.returncode
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@flowscripter/dynamic-cli-framework": "
|
|
28
|
-
"@flowscripter/dynamic-plugin-framework": "1.
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "2.3.1",
|
|
28
|
+
"@flowscripter/dynamic-plugin-framework": "1.11.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/bun": "^1.3.14",
|