Skip to content

Commit 06f0afe

Browse files
authored
Merge pull request #67 from RecuencoJones/master
feat: add inquirer-ordinal-prompt and --ordered option
2 parents 003ab64 + c2f7fdd commit 06f0afe

File tree

7 files changed

+92
-3
lines changed

7 files changed

+92
-3
lines changed

man/man1/ipt.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Allows the selection of multiple items [boolean]
3232
\fB\-M\fR, \fB\-\-message\fR
3333
Replaces interface message [string]
3434
.TP
35+
\fB\-o\fR, \fB\-\-ordered\fR
36+
Selects multiple items in order [boolean]
37+
.TP
3538
\fB\-p\fR, \fB\-\-extract\-path\fR
3639
Returns only a valid path for each item [boolean]
3740
.TP

package-lock.json

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"get-stdin": "^7.0.0",
4444
"inquirer": "^7.1.0",
4545
"inquirer-autocomplete-prompt-ipt": "^2.0.0",
46+
"inquirer-ordinal-prompt": "^1.0.0",
4647
"reopen-tty": "^1.1.2",
4748
"string-width": "~4.2.0",
4849
"yargs": "^15.3.0"

src/cli.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const { argv } = yargs
4242
.describe("h", "Shows this help message")
4343
.alias("m", "multiple")
4444
.describe("m", "Allows the selection of multiple items")
45+
.alias("o", "ordered")
46+
.describe("o", "Selects multiple items in order")
4547
.alias("M", "message")
4648
.describe("M", "Replaces interface message")
4749
.alias("0", "null")
@@ -57,7 +59,7 @@ const { argv } = yargs
5759
.alias("u", "unquoted")
5860
.describe("u", "Force the output to be unquoted")
5961
.alias("v", "version")
60-
.boolean(["0", "a", "c", "d", "h", "m", "0", "t", "p", "u", "v"])
62+
.boolean(["0", "a", "c", "d", "h", "m", "o", "0", "t", "p", "u", "v"])
6163
.string(["e", "M", "s", "D", "P"])
6264
.number(["S"])
6365
.epilog("Visit https://github.com/ruyadorno/ipt for more info");

src/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function iPipeTo(
5050
return options.default;
5151
}
5252

53-
if (promptType.type === "checkbox") {
53+
if (promptType.type === "checkbox" || promptType.type === "ordinal") {
5454
return options.default.split(
5555
options["default-separator"] || options.separator
5656
);
@@ -90,6 +90,13 @@ function iPipeTo(
9090
);
9191
}
9292

93+
if (options.ordered) {
94+
prompt.registerPrompt(
95+
"ordinal",
96+
require("inquirer-ordinal-prompt").default
97+
);
98+
}
99+
93100
const promptTypes = {
94101
base: {
95102
...opts,
@@ -100,6 +107,11 @@ function iPipeTo(
100107
type: "checkbox",
101108
message: options.message || "Select multiple items:"
102109
},
110+
ordered: {
111+
...opts,
112+
type: "ordinal",
113+
message: options.message || "Select multiple items in order:"
114+
},
103115
autocomplete: {
104116
...opts,
105117
type: "autocomplete",
@@ -116,6 +128,7 @@ function iPipeTo(
116128
};
117129

118130
const promptType =
131+
(options.ordered && promptTypes.ordered) ||
119132
(options.multiple && promptTypes.multiple) ||
120133
(options.autocomplete && promptTypes.autocomplete) ||
121134
promptTypes.base;

test/fixtures/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Options:
1111
-e, --file-encoding Encoding for file <path>, defaults to utf8 [string]
1212
-h, --help Shows this help message [boolean]
1313
-m, --multiple Allows the selection of multiple items [boolean]
14+
-o, --ordered Selects multiple items in order [boolean]
1415
-M, --message Replaces interface message [string]
1516
-p, --extract-path Returns only a valid path for each item [boolean]
1617
-s, --separator Separator to to split input into items [string]
@@ -26,4 +27,3 @@ Examples:
2627
ls | ipt | sed Builds an interactive interface and pipe stdout result
2728

2829
Visit https://github.com/ruyadorno/ipt for more info
29-

test/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ test.afterEach(t => {
5454
});
5555

5656
const key = {
57+
up: [null, { name: "up" }],
5758
down: [null, { name: "down" }],
5859
space: [null, { name: "space" }],
5960
l: ["l"],
@@ -144,6 +145,18 @@ test(
144145
})
145146
);
146147

148+
test(
149+
"should be able to use multiple ordered items mode and select many",
150+
unit({
151+
input: ["foo", "bar", "lorem", "ipsum"],
152+
output: ["lorem", "foo"],
153+
actions: [key.down, key.down, key.space, key.up, key.up, key.space],
154+
opts: {
155+
ordered: true
156+
}
157+
})
158+
);
159+
147160
test(
148161
"should be able to use autocomplete interface",
149162
unit({

0 commit comments

Comments
 (0)