Skip to content

Commit 2b29f85

Browse files
committed
[runtime] Implement interactive mode
1 parent 6a2e711 commit 2b29f85

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

README.tpl

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ cat file.json | jaml
3434

3535
### Available options
3636

37+
**`-i, --interactive`**
38+
39+
*Run in interactive mode*
40+
3741
**`-h, --help`**
3842

3943
*Display help message*

composer-lock.yaml

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ _readme:
66
- 'This file locks the dependencies of your project to a known state'
77
- 'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies'
88
- 'This file is @generated automatically'
9-
content-hash: f80b0731ecef396c7b65a1031699c461
9+
content-hash: 036d300de3e91a19210d0572331caccb
1010
packages:
1111
-
1212
name: symfony/polyfill-ctype
@@ -120,15 +120,15 @@ packages:
120120
time: '2020-10-24T10:57:07+00:00'
121121
-
122122
name: yannoff/console
123-
version: 1.5.0
123+
version: 1.6.0
124124
source:
125125
type: git
126126
url: 'https://github.com/yannoff/console.git'
127-
reference: b0b94ee07097f7d49236b5a07438f6336ff76037
127+
reference: e7ef08975e6ffdf95b70f2cb4c0e5d03ccd11243
128128
dist:
129129
type: zip
130-
url: 'https://api.github.com/repos/yannoff/console/zipball/b0b94ee07097f7d49236b5a07438f6336ff76037'
131-
reference: b0b94ee07097f7d49236b5a07438f6336ff76037
130+
url: 'https://api.github.com/repos/yannoff/console/zipball/e7ef08975e6ffdf95b70f2cb4c0e5d03ccd11243'
131+
reference: e7ef08975e6ffdf95b70f2cb4c0e5d03ccd11243
132132
shasum: ''
133133
type: library
134134
autoload:
@@ -145,8 +145,8 @@ packages:
145145
homepage: 'https://github.com/yannoff/console'
146146
support:
147147
issues: 'https://github.com/yannoff/console/issues'
148-
source: 'https://github.com/yannoff/console/tree/1.5.0'
149-
time: '2023-09-16T12:36:27+00:00'
148+
source: 'https://github.com/yannoff/console/tree/1.6.0'
149+
time: '2023-09-24T18:14:50+00:00'
150150
-
151151
name: yannoff/y-a-m-l
152152
version: 1.1.5
@@ -226,4 +226,4 @@ prefer-stable: false
226226
prefer-lowest: false
227227
platform: []
228228
platform-dev: []
229-
plugin-api-version: 2.1.0
229+
plugin-api-version: 2.2.0

composer.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ autoload:
1414
psr-4:
1515
Yannoff\Jaml\: src/
1616
require:
17-
yannoff/console: ^1.5.0
17+
yannoff/console: ^1.6
1818
yannoff/yamltools: ^1.4

man/man1/jaml.1.gz

35 Bytes
Binary file not shown.

md/jaml/1.md

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Convert YAML => JSON or JSON => YAML
2323

2424
## OPTIONS
2525

26+
`-i, --interactive`
27+
28+
Enable interactive mode, will listen to user input
29+
2630
`-h, --help`
2731

2832
Display help message

src/Command/JamlCommand.php

+16-4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public function configure()
6969
Option::FLAG,
7070
'Turn on verbose mode (debug messages on STDERR)'
7171
)
72+
->addOption(
73+
'interactive',
74+
'i',
75+
Option::FLAG,
76+
'Run JAML in interactive mode'
77+
)
7278
->addArgument(
7379
'infile',
7480
Argument::OPTIONAL,
@@ -90,8 +96,13 @@ public function execute()
9096
try {
9197

9298
$infile = $this->getArgument('infile');
99+
$interactive = $this->getOption('interactive');
100+
101+
if ($interactive) {
102+
$this->errorln("Welcome to JAML interactive mode ! \nType your contents here and press CTRL+D to trigger conversion");
103+
}
93104

94-
$contents = $this->getContents($infile);
105+
$contents = $this->getContents($interactive, $infile);
95106

96107
if ($this->isJson($contents)) {
97108
$this->debug('Detected input looks like a JSON formatted contents...');
@@ -153,14 +164,15 @@ protected function debug($message)
153164
/**
154165
* Get contents from input file or stdin if file is null or "-"
155166
*
156-
* @param string|null $filename Relative or absolute path to the input file
167+
* @param bool $interactive Enable/disable listening on user input
168+
* @param string|null $filename Relative or absolute path to the input file
157169
*
158170
* @return false|string
159171
*/
160-
protected function getContents($filename = null)
172+
protected function getContents($interactive, $filename = null)
161173
{
162174
if (null === $filename || '-' === $filename) {
163-
return $this->ioread();
175+
return $this->ioread($interactive);
164176
}
165177

166178
return \file_get_contents($filename);

0 commit comments

Comments
 (0)