@little-nebulae/clack 0.2.0 → 0.3.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/dist/index.d.ts +34 -18
- package/dist/index.js +78 -45
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
isCancelled: true;
|
|
5
|
-
message: string;
|
|
6
|
-
};
|
|
7
|
-
type ClackNotCancelledWrapper<T> = {
|
|
8
|
-
isCancelled: false;
|
|
9
|
-
value: T;
|
|
10
|
-
};
|
|
11
|
-
type ClackReturnWrapper<T> = ClackIsCancelledWrapper | ClackNotCancelledWrapper<T>;
|
|
1
|
+
import { BaseError, UnexpectedError } from "@little-nebulae/error";
|
|
2
|
+
import { ConfirmOptions, MultiLineOptions, PathOptions, SelectOptions, TextOptions } from "@clack/prompts";
|
|
3
|
+
import { AsyncResult } from "@little-nebulae/result";
|
|
12
4
|
export declare const DEFAULT_CANCEL_MESSAGE = "Operation cancelled.";
|
|
13
|
-
export declare
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export declare
|
|
19
|
-
|
|
5
|
+
export declare class ClackNonInteractiveError extends BaseError<"CLACK_NON_INTERACTIVE_ERROR", null> {
|
|
6
|
+
readonly name = "ClackNonInteractiveError";
|
|
7
|
+
readonly code = "CLACK_NON_INTERACTIVE_ERROR";
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class ClackIsCancelledError extends BaseError<"CLACK_IS_CANCELLED_ERROR", string> {
|
|
11
|
+
readonly name = "ClackIsCancelledError";
|
|
12
|
+
readonly code = "CLACK_IS_CANCELLED_ERROR";
|
|
13
|
+
constructor(message?: string);
|
|
14
|
+
}
|
|
15
|
+
interface ClackTextParams extends TextOptions {
|
|
16
|
+
isTTY: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function clackText({ isTTY, ...opts }: ClackTextParams): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
19
|
+
interface ClackMultilineParams extends MultiLineOptions {
|
|
20
|
+
isTTY: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare function clackMultiline({ isTTY, ...opts }: ClackMultilineParams): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
23
|
+
interface ClackSelectParams<Value> extends SelectOptions<Value> {
|
|
24
|
+
isTTY: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function clackSelect<Value>({ isTTY, ...opts }: ClackSelectParams<Value>): AsyncResult<Value, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
27
|
+
interface ClackPathParams extends PathOptions {
|
|
28
|
+
isTTY: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare function clackPath({ isTTY, ...opts }: ClackPathParams): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
31
|
+
interface ClackConfirmParams extends ConfirmOptions {
|
|
32
|
+
isTTY: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare function clackConfirm({ isTTY, ...opts }: ClackConfirmParams): AsyncResult<boolean, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
35
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,72 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { BaseError, UnexpectedError, composeErrorMessage } from "@little-nebulae/error";
|
|
2
|
+
import { CANCEL_SYMBOL, confirm, isCancel, multiline, path, select, text } from "@clack/prompts";
|
|
3
|
+
import { fail, succeed } from "@little-nebulae/result";
|
|
4
4
|
// src/constants.ts
|
|
5
5
|
const DEFAULT_CANCEL_MESSAGE = "Operation cancelled.";
|
|
6
|
-
// src/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
6
|
+
// src/errors/non-interactive.ts
|
|
7
|
+
var ClackNonInteractiveError = class extends BaseError {
|
|
8
|
+
name = "ClackNonInteractiveError";
|
|
9
|
+
code = "CLACK_NON_INTERACTIVE_ERROR";
|
|
10
|
+
constructor(message = "A Clack prompt can only run in an interactive terminal context.") {
|
|
11
|
+
super({
|
|
12
|
+
message,
|
|
13
|
+
cause: null,
|
|
14
|
+
meta: null
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
// src/errors/is-cancelled.ts
|
|
19
|
+
var ClackIsCancelledError = class extends BaseError {
|
|
20
|
+
name = "ClackIsCancelledError";
|
|
21
|
+
code = "CLACK_IS_CANCELLED_ERROR";
|
|
22
|
+
constructor(message = DEFAULT_CANCEL_MESSAGE) {
|
|
23
|
+
super({
|
|
24
|
+
message,
|
|
25
|
+
cause: CANCEL_SYMBOL.toString(),
|
|
26
|
+
meta: null
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
17
30
|
// src/prompts/text.ts
|
|
18
|
-
async function clackText(opts) {
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
async function clackText({ isTTY, ...opts }) {
|
|
32
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
33
|
+
try {
|
|
34
|
+
const answer = await text(opts);
|
|
35
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
36
|
+
return succeed(answer);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return fail(new UnexpectedError({
|
|
22
39
|
message: composeErrorMessage({ operation: "prompt for text input" }),
|
|
23
40
|
cause: error,
|
|
24
41
|
meta: null
|
|
25
|
-
})
|
|
26
|
-
}
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
27
44
|
}
|
|
28
45
|
// src/prompts/multiline.ts
|
|
29
|
-
async function clackMultiline(opts) {
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
46
|
+
async function clackMultiline({ isTTY, ...opts }) {
|
|
47
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
48
|
+
try {
|
|
49
|
+
const answer = await multiline(opts);
|
|
50
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
51
|
+
return succeed(answer);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return fail(new UnexpectedError({
|
|
33
54
|
message: composeErrorMessage({ operation: "prompt for multi-line text input" }),
|
|
34
55
|
cause: error,
|
|
35
56
|
meta: null
|
|
36
|
-
})
|
|
37
|
-
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
38
59
|
}
|
|
39
60
|
// src/prompts/select.ts
|
|
40
|
-
async function clackSelect(opts) {
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
async function clackSelect({ isTTY, ...opts }) {
|
|
62
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
63
|
+
try {
|
|
64
|
+
const answer = await select(opts);
|
|
65
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
66
|
+
return succeed(answer);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return fail(new UnexpectedError({
|
|
44
69
|
message: composeErrorMessage({ operation: "prompt for a selection" }),
|
|
45
70
|
cause: error,
|
|
46
71
|
meta: null
|
|
47
|
-
})
|
|
48
|
-
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
49
74
|
}
|
|
50
75
|
// src/prompts/path.ts
|
|
51
|
-
async function clackPath(opts) {
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
76
|
+
async function clackPath({ isTTY, ...opts }) {
|
|
77
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
78
|
+
try {
|
|
79
|
+
const answer = await path(opts);
|
|
80
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
81
|
+
return succeed(answer);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return fail(new UnexpectedError({
|
|
55
84
|
message: composeErrorMessage({ operation: "prompt for path selection" }),
|
|
56
85
|
cause: error,
|
|
57
86
|
meta: null
|
|
58
|
-
})
|
|
59
|
-
}
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
60
89
|
}
|
|
61
90
|
// src/prompts/confirm.ts
|
|
62
|
-
async function clackConfirm(opts) {
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
|
|
91
|
+
async function clackConfirm({ isTTY, ...opts }) {
|
|
92
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
93
|
+
try {
|
|
94
|
+
const answer = await confirm(opts);
|
|
95
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
96
|
+
return succeed(answer);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
return fail(new UnexpectedError({
|
|
66
99
|
message: composeErrorMessage({ operation: "prompt for confirmation" }),
|
|
67
100
|
cause: error,
|
|
68
101
|
meta: null
|
|
69
|
-
})
|
|
70
|
-
}
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
71
104
|
}
|
|
72
|
-
export { DEFAULT_CANCEL_MESSAGE, clackConfirm, clackMultiline, clackPath, clackSelect, clackText
|
|
105
|
+
export { ClackIsCancelledError, ClackNonInteractiveError, DEFAULT_CANCEL_MESSAGE, clackConfirm, clackMultiline, clackPath, clackSelect, clackText };
|