Skip to content

Commit

Permalink
feat: combine interactive and non-interactive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jakim929 committed Nov 21, 2024
1 parent 20d4ac3 commit 457ee12
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion packages/cli/src/commands/deploy/create2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
} from '@/actions/deployCreateXCreate2';
import {useQuery} from '@tanstack/react-query';
import {useMappingChainById} from '@/queries/chainById';
import {z} from 'zod';
import {option} from 'pastel';
import {DeployCreate2Wizard} from '@/deploy-create2-wizard/DeployCreate2Wizard';

const statusBadge = {
pending: <Spinner />,
Expand All @@ -25,6 +28,31 @@ const statusBadge = {
),
};

const zodModeParams = z.discriminatedUnion('interactive', [
z
.object({
interactive: z.literal(true).describe(
option({
description: 'Interactive mode',
alias: 'i',
}),
),
})
.merge(zodDeployCreateXCreate2Params),
z
.object({
interactive: z.literal(false).describe(
option({
description: 'Interactive mode',
alias: 'i',
}),
),
})
.merge(zodDeployCreateXCreate2Params.partial()),
]);

type ModeParams = z.infer<typeof zodModeParams>;

const useDeterministicAddress = (params: DeployCreateXCreate2Params) => {
return useQuery({
// TODO check this query key is consistent
Expand All @@ -35,7 +63,15 @@ const useDeterministicAddress = (params: DeployCreateXCreate2Params) => {
});
};

const DeployCreate2Command = ({
const DeployCreate2Command = ({options}: {options: ModeParams}) => {
if (options.interactive === false) {
return <DeployCreate2Wizard />;
}

return <DeployCreate2CommandNonInteractive options={options} />;
};

const DeployCreate2CommandNonInteractive = ({
options,
}: {
options: DeployCreateXCreate2Params;
Expand Down

0 comments on commit 457ee12

Please sign in to comment.