@little-nebulae/clack 0.3.0 → 0.4.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 +33 -17
- package/dist/index.js +17 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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";
|
|
2
|
+
import { ConfirmOptions, MultiLineOptions, PasswordOptions, PathOptions, SelectOptions, TextOptions } from "@clack/prompts";
|
|
3
|
+
import { AsyncResult, Failure } from "@little-nebulae/result";
|
|
4
4
|
export declare const DEFAULT_CANCEL_MESSAGE = "Operation cancelled.";
|
|
5
5
|
export declare class ClackNonInteractiveError extends BaseError<"CLACK_NON_INTERACTIVE_ERROR", null> {
|
|
6
6
|
readonly name = "ClackNonInteractiveError";
|
|
@@ -12,24 +12,40 @@ export declare class ClackIsCancelledError extends BaseError<"CLACK_IS_CANCELLED
|
|
|
12
12
|
readonly code = "CLACK_IS_CANCELLED_ERROR";
|
|
13
13
|
constructor(message?: string);
|
|
14
14
|
}
|
|
15
|
-
interface ClackTextParams extends TextOptions {
|
|
16
|
-
isTTY:
|
|
15
|
+
interface ClackTextParams<IsTTY extends boolean> extends TextOptions {
|
|
16
|
+
isTTY: IsTTY;
|
|
17
17
|
}
|
|
18
|
-
export declare function clackText(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
export declare function clackText(params: ClackTextParams<true>): AsyncResult<string, ClackIsCancelledError | UnexpectedError>;
|
|
19
|
+
export declare function clackText(params: ClackTextParams<false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
20
|
+
export declare function clackText(params: ClackTextParams<boolean>): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
21
|
+
interface ClackPasswordParams<IsTTY extends boolean> extends PasswordOptions {
|
|
22
|
+
isTTY: IsTTY;
|
|
21
23
|
}
|
|
22
|
-
export declare function
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
export declare function clackPassword(params: ClackPasswordParams<true>): AsyncResult<string, ClackIsCancelledError | UnexpectedError>;
|
|
25
|
+
export declare function clackPassword(params: ClackPasswordParams<false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
26
|
+
export declare function clackPassword(params: ClackPasswordParams<boolean>): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
27
|
+
interface ClackMultilineParams<IsTTY extends boolean> extends MultiLineOptions {
|
|
28
|
+
isTTY: IsTTY;
|
|
25
29
|
}
|
|
26
|
-
export declare function
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
export declare function clackMultiline(params: ClackMultilineParams<true>): AsyncResult<string, ClackIsCancelledError | UnexpectedError>;
|
|
31
|
+
export declare function clackMultiline(params: ClackMultilineParams<false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
32
|
+
export declare function clackMultiline(params: ClackMultilineParams<boolean>): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
33
|
+
interface ClackSelectParams<Value, IsTTY extends boolean> extends SelectOptions<Value> {
|
|
34
|
+
isTTY: IsTTY;
|
|
29
35
|
}
|
|
30
|
-
export declare function
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
export declare function clackSelect<Value>(params: ClackSelectParams<Value, true>): AsyncResult<Value, ClackIsCancelledError | UnexpectedError>;
|
|
37
|
+
export declare function clackSelect<Value>(params: ClackSelectParams<Value, false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
38
|
+
export declare function clackSelect<Value>(params: ClackSelectParams<Value, boolean>): AsyncResult<Value, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
39
|
+
interface ClackPathParams<IsTTY extends boolean> extends PathOptions {
|
|
40
|
+
isTTY: IsTTY;
|
|
33
41
|
}
|
|
34
|
-
export declare function
|
|
42
|
+
export declare function clackPath(params: ClackPathParams<true>): AsyncResult<string, ClackIsCancelledError | UnexpectedError>;
|
|
43
|
+
export declare function clackPath(params: ClackPathParams<false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
44
|
+
export declare function clackPath(params: ClackPathParams<boolean>): AsyncResult<string, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
45
|
+
interface ClackConfirmParams<IsTTY extends boolean> extends ConfirmOptions {
|
|
46
|
+
isTTY: IsTTY;
|
|
47
|
+
}
|
|
48
|
+
export declare function clackConfirm(params: ClackConfirmParams<true>): AsyncResult<boolean, ClackIsCancelledError | UnexpectedError>;
|
|
49
|
+
export declare function clackConfirm(params: ClackConfirmParams<false>): Promise<Failure<ClackNonInteractiveError>>;
|
|
50
|
+
export declare function clackConfirm(params: ClackConfirmParams<boolean>): AsyncResult<boolean, ClackNonInteractiveError | ClackIsCancelledError | UnexpectedError>;
|
|
35
51
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseError, UnexpectedError, composeErrorMessage } from "@little-nebulae/error";
|
|
2
|
-
import { CANCEL_SYMBOL, confirm, isCancel, multiline, path, select, text } from "@clack/prompts";
|
|
2
|
+
import { CANCEL_SYMBOL, confirm, isCancel, multiline, password, path, select, text } from "@clack/prompts";
|
|
3
3
|
import { fail, succeed } from "@little-nebulae/result";
|
|
4
4
|
// src/constants.ts
|
|
5
5
|
const DEFAULT_CANCEL_MESSAGE = "Operation cancelled.";
|
|
@@ -42,6 +42,21 @@ async function clackText({ isTTY, ...opts }) {
|
|
|
42
42
|
}));
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
+
// src/prompts/password.ts
|
|
46
|
+
async function clackPassword({ isTTY, ...opts }) {
|
|
47
|
+
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
48
|
+
try {
|
|
49
|
+
const answer = await password(opts);
|
|
50
|
+
if (isCancel(answer)) return fail(new ClackIsCancelledError());
|
|
51
|
+
return succeed(answer);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
return fail(new UnexpectedError({
|
|
54
|
+
message: composeErrorMessage({ operation: "prompt for a password" }),
|
|
55
|
+
cause: error,
|
|
56
|
+
meta: null
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
45
60
|
// src/prompts/multiline.ts
|
|
46
61
|
async function clackMultiline({ isTTY, ...opts }) {
|
|
47
62
|
if (!isTTY) return fail(new ClackNonInteractiveError());
|
|
@@ -102,4 +117,4 @@ async function clackConfirm({ isTTY, ...opts }) {
|
|
|
102
117
|
}));
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
|
-
export { ClackIsCancelledError, ClackNonInteractiveError, DEFAULT_CANCEL_MESSAGE, clackConfirm, clackMultiline, clackPath, clackSelect, clackText };
|
|
120
|
+
export { ClackIsCancelledError, ClackNonInteractiveError, DEFAULT_CANCEL_MESSAGE, clackConfirm, clackMultiline, clackPassword, clackPath, clackSelect, clackText };
|