@jakubmazanec/cli 0.1.0-265acad → 0.1.0-2f12db0
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/program/Command.d.ts +2 -2
- package/dist/program/Command.js +3 -3
- package/dist/program/Command.js.map +1 -1
- package/dist/program/CommandOptions.d.ts +1 -1
- package/dist/program/CommandOptions.js.map +1 -1
- package/dist/program/Program.d.ts +8 -3
- package/dist/program/Program.js +27 -7
- package/dist/program/Program.js.map +1 -1
- package/dist/program/ProgramOptions.d.ts +5 -1
- package/dist/program/ProgramOptions.js +1 -3
- package/dist/program/ProgramOptions.js.map +1 -1
- package/dist/program/ProgramStreams.d.ts +1 -1
- package/dist/program/ProgramStreams.js +1 -1
- package/dist/program/ProgramStreams.js.map +1 -1
- package/dist/ui/Failure.d.ts +2 -2
- package/dist/ui/Failure.js.map +1 -1
- package/dist/ui/Header.d.ts +1 -1
- package/dist/ui/Header.js.map +1 -1
- package/dist/ui/Help.d.ts +2 -2
- package/dist/ui/Help.js.map +1 -1
- package/dist/ui/form/SelectInput.d.ts +3 -3
- package/dist/ui/form/SelectInput.js +20 -29
- package/dist/ui/form/SelectInput.js.map +1 -1
- package/dist/ui/form/TextInput.d.ts +1 -1
- package/dist/ui/form/TextInput.js +4 -7
- package/dist/ui/form/TextInput.js.map +1 -1
- package/dist/ui/getErrorDetail.js +9 -0
- package/dist/ui/getErrorDetail.js.map +1 -1
- package/dist/ui/internals/Wrapper.d.ts +2 -2
- package/dist/ui/internals/Wrapper.js +1 -1
- package/dist/ui/internals/Wrapper.js.map +1 -1
- package/dist/ui/internals/programContext.d.ts +1 -1
- package/dist/ui/internals/programContext.js +1 -1
- package/dist/ui/internals/programContext.js.map +1 -1
- package/dist/ui/useProgram.d.ts +1 -1
- package/dist/ui/useProgram.js +1 -1
- package/dist/ui/useProgram.js.map +1 -1
- package/package.json +8 -7
- package/src/program/Command.ts +2 -3
- package/src/program/CommandOptions.ts +1 -1
- package/src/program/Program.ts +38 -5
- package/src/program/ProgramOptions.ts +7 -1
- package/src/program/ProgramStreams.ts +1 -1
- package/src/ui/Failure.tsx +2 -2
- package/src/ui/Header.tsx +1 -1
- package/src/ui/Help.tsx +2 -2
- package/src/ui/form/SelectInput.tsx +23 -28
- package/src/ui/form/TextInput.tsx +5 -10
- package/src/ui/getErrorDetail.ts +11 -0
- package/src/ui/internals/Wrapper.tsx +2 -2
- package/src/ui/internals/programContext.ts +1 -1
- package/src/ui/useProgram.ts +1 -1
package/src/ui/getErrorDetail.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {ValidationError, ParsingError} from '@jakubmazanec/args';
|
|
2
|
+
import {zodIssuesToStrings} from '@jakubmazanec/zod-utils';
|
|
3
|
+
import {ZodError} from 'zod';
|
|
2
4
|
|
|
3
5
|
import {type ErrorDetail} from './ErrorDetail.js';
|
|
4
6
|
|
|
@@ -44,6 +46,15 @@ export function getErrorDetail(error: unknown): ErrorDetail {
|
|
|
44
46
|
return errorDetail;
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
if (error instanceof ZodError) {
|
|
50
|
+
let errorDetail: ErrorDetail = {
|
|
51
|
+
label: 'Error',
|
|
52
|
+
description: zodIssuesToStrings(error.issues).join('\n'),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return errorDetail;
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
if (error instanceof Error) {
|
|
48
59
|
let errorDetail: ErrorDetail = {
|
|
49
60
|
label: 'Error',
|
|
@@ -7,14 +7,14 @@ import {type Program} from '../../program.js';
|
|
|
7
7
|
import {Failure} from '../Failure.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* {@
|
|
10
|
+
* {@link Wrapper} component props.
|
|
11
11
|
*/
|
|
12
12
|
export type WrapperProps = {
|
|
13
13
|
program: Program;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* A component that wraps anything {@
|
|
17
|
+
* A component that wraps anything {@link Program} tries to render with an error boundary and all neccessary providers.
|
|
18
18
|
*/
|
|
19
19
|
export const Wrapper: FC<PropsWithChildren<WrapperProps>> = ({program, children}) => {
|
|
20
20
|
let programContextValue = useMemo(
|
package/src/ui/useProgram.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {useErrorBoundary} from 'react-error-boundary';
|
|
|
5
5
|
import {programContext} from './internals.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* A React hook for accessing {@
|
|
8
|
+
* A React hook for accessing {@link Program} instance and `exit` function that is used for showing an error (via an error boundary) and exiting.
|
|
9
9
|
*/
|
|
10
10
|
export function useProgram() {
|
|
11
11
|
let {showBoundary} = useErrorBoundary();
|