@flowscripter/example-cli 1.4.0 → 1.5.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 +4 -2
- package/functional_tests/features/executable.feature +13 -0
- package/functional_tests/features/plugin.feature +10 -3
- package/functional_tests/features/steps/executable.py +52 -0
- package/functional_tests/features/support/subprocess_wrapper.py +25 -0
- package/package.json +2 -2
- package/src/assets.d.ts +4 -0
- package/src/commands/image.ts +2 -9
- package/src/commands/printing.ts +4 -0
package/bun.lock
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"": {
|
|
6
6
|
"name": "@flowscripter/example-cli",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@flowscripter/dynamic-cli-framework": "1.7.
|
|
8
|
+
"@flowscripter/dynamic-cli-framework": "1.7.3",
|
|
9
9
|
"@flowscripter/dynamic-plugin-framework": "1.10.0",
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
},
|
|
22
22
|
"packages": {
|
|
23
|
-
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@1.7.
|
|
23
|
+
"@flowscripter/dynamic-cli-framework": ["@flowscripter/dynamic-cli-framework@1.7.3", "", { "dependencies": { "@flowscripter/dynamic-plugin-framework": "1.10.1", "emphasize": "^7.0.0", "fastest-levenshtein": "^1.0.16", "figlet": "^1.11.0", "highlight.js": "^11.11.1", "prettier": "^3.9.4", "supports-color": "^10.2.2", "supports-terminal-graphics": "^0.1.0" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-odf0w9VoghMvFLO3TKVUYUB8FFVfPVF1MH3a38S91cs/vhve6/d57+Lf8iWaCNSCqUswnxGtdTbUMa7OXvz03A=="],
|
|
24
24
|
|
|
25
25
|
"@flowscripter/dynamic-plugin-framework": ["@flowscripter/dynamic-plugin-framework@1.10.0", "", { "dependencies": { "semver": "^7.8.5" }, "peerDependencies": { "typescript": "^6.0.3" } }, "sha512-WC0PKxQsk4KJSP/fstL2+Po5/2OB1hSgwM3HGLGwoHyH5qV7pNF/aZct6mDnLIi0aECVWM1sm7LXg75cb9FWLQ=="],
|
|
26
26
|
|
|
@@ -146,6 +146,8 @@
|
|
|
146
146
|
|
|
147
147
|
"undici-types": ["undici-types@8.3.0", "", {}, "sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ=="],
|
|
148
148
|
|
|
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
|
+
|
|
149
151
|
"bun-types/@types/node": ["@types/node@22.13.9", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-acBjXdRJ3A6Pb3tqnw9HZmyR3Fiol3aGxRCK1x3d+6CDAMjl7I649wpSd+yNURCjbOUGu9tqtLKnTGxmK6CyGw=="],
|
|
150
152
|
|
|
151
153
|
"emphasize/highlight.js": ["highlight.js@11.9.0", "", {}, "sha512-fJ7cW7fQGCYAkgv4CPfwFHrfd/cLS4Hau96JuJ+ZTOWhjnhoeN1ub1tFmALm/+lW5z4WCAuAV9bm05AP0mS6Gw=="],
|
|
@@ -30,6 +30,10 @@ Feature: Executable
|
|
|
30
30
|
And the executable should have output "Chisel Font ASCII Banner Demo"
|
|
31
31
|
And the executable should have output "ASCII Banner Subtitle Demo"
|
|
32
32
|
|
|
33
|
+
Scenario: Image demo
|
|
34
|
+
When the executable is launched with "demo:image"
|
|
35
|
+
Then the executable should complete with exit code 0
|
|
36
|
+
|
|
33
37
|
Scenario: Completion demo
|
|
34
38
|
When the executable is launched with "demo:completion"
|
|
35
39
|
Then the executable should complete with exit code 0
|
|
@@ -40,3 +44,12 @@ Feature: Executable
|
|
|
40
44
|
Then the executable should complete with exit code 0
|
|
41
45
|
And the executable should have output "Key-Value Storage"
|
|
42
46
|
And the executable should have output "Secret Storage"
|
|
47
|
+
|
|
48
|
+
Scenario: Completion stdout contains only completion values without banner
|
|
49
|
+
When bash completions are requested for "example-cli --h" at cursor 15
|
|
50
|
+
Then the stdout should contain "--help"
|
|
51
|
+
And the stdout should not contain "EXAMPLE-CLI"
|
|
52
|
+
|
|
53
|
+
Scenario: No completions after global command with trailing space
|
|
54
|
+
When bash completions are requested for "example-cli --help " at cursor 19
|
|
55
|
+
Then the stdout should be empty
|
|
@@ -14,9 +14,11 @@ 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 is
|
|
18
|
-
Then the
|
|
19
|
-
And the
|
|
17
|
+
When the executable stdout is captured for "--no-prompt plugin:add @flowscripter/example-cli-plugin"
|
|
18
|
+
Then the captured process should complete with exit code 0
|
|
19
|
+
And the stdout should contain "installed"
|
|
20
|
+
And the stderr should contain "Searching for plugin: @flowscripter/example-cli-plugin\n"
|
|
21
|
+
And the stderr should contain "Installing @flowscripter/example-cli-plugin...\n"
|
|
20
22
|
|
|
21
23
|
Scenario: List installed plugins after install
|
|
22
24
|
When the executable is launched with "plugin:list"
|
|
@@ -28,6 +30,11 @@ Feature: Plugin management
|
|
|
28
30
|
Then the executable should complete with exit code 0
|
|
29
31
|
And the executable should have output "Hello"
|
|
30
32
|
|
|
33
|
+
Scenario: Use hello_rust command from installed plugin
|
|
34
|
+
When the executable is launched with "hello_rust"
|
|
35
|
+
Then the executable should complete with exit code 0
|
|
36
|
+
And the executable should have output "World 4"
|
|
37
|
+
|
|
31
38
|
Scenario: Remove example-cli-plugin
|
|
32
39
|
When the executable is launched with "plugin:remove @flowscripter/example-cli-plugin"
|
|
33
40
|
Then the executable should complete with exit code 0
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
4
|
+
|
|
1
5
|
from behave import when, then
|
|
6
|
+
from support.subprocess_wrapper import SubprocessWrapper
|
|
2
7
|
|
|
3
8
|
|
|
4
9
|
@when('the executable is launched')
|
|
@@ -21,3 +26,50 @@ def step_impl(context, code):
|
|
|
21
26
|
@then('the executable should have output "{message}"')
|
|
22
27
|
def step_impl(context, message):
|
|
23
28
|
context.pexpect_wrapper.expect(message)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@when('the executable stdout is captured for "{args}"')
|
|
32
|
+
def step_impl(context, args):
|
|
33
|
+
wrapper = SubprocessWrapper(os.environ.get('EXECUTABLE'))
|
|
34
|
+
wrapper.run(args)
|
|
35
|
+
context.subprocess_wrapper = wrapper
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@when('bash completions are requested for "{line}" at cursor {cursor:d}')
|
|
39
|
+
def step_impl(context, line, cursor):
|
|
40
|
+
wrapper = SubprocessWrapper(os.environ.get('EXECUTABLE'))
|
|
41
|
+
wrapper.run('completions:complete bash "{}" {}'.format(line, cursor))
|
|
42
|
+
context.subprocess_wrapper = wrapper
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@then('the captured process should complete with exit code {code:d}')
|
|
46
|
+
def step_impl(context, code):
|
|
47
|
+
status = context.subprocess_wrapper.returncode
|
|
48
|
+
assert status == code, 'unexpected exit status: {} (expected {})'.format(status, code)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@then('the stdout should contain "{text}"')
|
|
52
|
+
def step_impl(context, text):
|
|
53
|
+
text = text.replace('\\n', '\n')
|
|
54
|
+
assert text in context.subprocess_wrapper.stdout, \
|
|
55
|
+
'expected {!r} in stdout {!r}'.format(text, context.subprocess_wrapper.stdout)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@then('the stdout should not contain "{text}"')
|
|
59
|
+
def step_impl(context, text):
|
|
60
|
+
text = text.replace('\\n', '\n')
|
|
61
|
+
assert text not in context.subprocess_wrapper.stdout, \
|
|
62
|
+
'expected {!r} not in stdout {!r}'.format(text, context.subprocess_wrapper.stdout)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@then('the stderr should contain "{text}"')
|
|
66
|
+
def step_impl(context, text):
|
|
67
|
+
text = text.replace('\\n', '\n')
|
|
68
|
+
assert text in context.subprocess_wrapper.stderr, \
|
|
69
|
+
'expected {!r} in stderr {!r}'.format(text, context.subprocess_wrapper.stderr)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@then('the stdout should be empty')
|
|
73
|
+
def step_impl(context):
|
|
74
|
+
assert context.subprocess_wrapper.stdout.strip() == '', \
|
|
75
|
+
'expected empty stdout but got {!r}'.format(context.subprocess_wrapper.stdout)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import shlex
|
|
2
|
+
import subprocess
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
log = logging.getLogger("subprocess_wrapper")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SubprocessWrapper:
|
|
9
|
+
|
|
10
|
+
def __init__(self, executable):
|
|
11
|
+
self.executable = executable
|
|
12
|
+
self.stdout = None
|
|
13
|
+
self.stderr = None
|
|
14
|
+
self.returncode = None
|
|
15
|
+
|
|
16
|
+
def run(self, args=''):
|
|
17
|
+
cmd = [self.executable] + (shlex.split(args) if args else [])
|
|
18
|
+
log.debug('running: {}'.format(cmd))
|
|
19
|
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
|
|
20
|
+
self.stdout = result.stdout
|
|
21
|
+
self.stderr = result.stderr
|
|
22
|
+
self.returncode = result.returncode
|
|
23
|
+
log.debug('stdout: {!r}'.format(self.stdout))
|
|
24
|
+
log.debug('stderr: {!r}'.format(self.stderr))
|
|
25
|
+
log.debug('returncode: {}'.format(self.returncode))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowscripter/example-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Simple example CLI using https://github.com/flowscripter/dynamic-cli-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@flowscripter/dynamic-cli-framework": "1.7.
|
|
27
|
+
"@flowscripter/dynamic-cli-framework": "1.7.3",
|
|
28
28
|
"@flowscripter/dynamic-plugin-framework": "1.10.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
package/src/assets.d.ts
ADDED
package/src/commands/image.ts
CHANGED
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
type PrinterService,
|
|
8
8
|
type SubCommand,
|
|
9
9
|
} from "@flowscripter/dynamic-cli-framework";
|
|
10
|
-
import
|
|
11
|
-
import process from "node:process";
|
|
10
|
+
import logoAsset from "../../assets/logo.png" with { type: "file" };
|
|
12
11
|
|
|
13
12
|
const image: SubCommand = {
|
|
14
13
|
name: "image",
|
|
@@ -21,13 +20,7 @@ const image: SubCommand = {
|
|
|
21
20
|
IMAGE_PRINTER_SERVICE_ID,
|
|
22
21
|
) as ImagePrinterService;
|
|
23
22
|
|
|
24
|
-
const
|
|
25
|
-
let imagePath = path.join(baseDir, "assets", "logo.png");
|
|
26
|
-
const logoFile = Bun.file(imagePath);
|
|
27
|
-
if (!(await logoFile.exists())) {
|
|
28
|
-
imagePath = path.join(import.meta.dir, "..", "..", "assets", "logo.png");
|
|
29
|
-
}
|
|
30
|
-
const imageBuffer = await Bun.file(imagePath).bytes();
|
|
23
|
+
const imageBuffer = await Bun.file(logoAsset).bytes();
|
|
31
24
|
const imageOutput = await imagePrinterService.image(imageBuffer, 25, "#FFFFFF");
|
|
32
25
|
await printerService.print(imageOutput + "\n");
|
|
33
26
|
},
|
package/src/commands/printing.ts
CHANGED
|
@@ -117,6 +117,10 @@ const printing: SubCommand = {
|
|
|
117
117
|
printerService.backgroundColor("Custom Hex Background", "#FF6600") + "\n",
|
|
118
118
|
);
|
|
119
119
|
|
|
120
|
+
// --- Italic ---
|
|
121
|
+
await printerService.print("--- Italic ---\n");
|
|
122
|
+
await printerService.print(printerService.italic("Italic text") + "\n");
|
|
123
|
+
|
|
120
124
|
// --- Hyperlink ---
|
|
121
125
|
await printerService.print("--- Hyperlink ---\n");
|
|
122
126
|
await printerService.print(
|