Skip to content

Commit

Permalink
Allow defaults in initial prompt (#1343)
Browse files Browse the repository at this point in the history
Per discussion in #1335.
  • Loading branch information
72636c authored Dec 13, 2023
1 parent 347b0bc commit 5750ab3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-moles-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'skuba': minor
---

init: Default to `arm64` platform and `main` branch
7 changes: 4 additions & 3 deletions docs/cli/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ and answering a few starter questions:

```shell
? For starters, some project details:
⊙ Owner : SEEK-Jobs/my-team
⊙ Repo : my-repo
⊙ Platform : amd64 | arm64
⊙ Owner : SEEK-Jobs/my-team
⊙ Repo : my-repo
⊙ Platform : arm64
⊙ Default Branch : main

# ...
```
Expand Down
9 changes: 7 additions & 2 deletions src/cli/init/getConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { downloadGitHubTemplate } from './git';
import {
BASE_PROMPT_PROPS,
type BaseFields,
type Choice,
GIT_PATH_PROMPT,
SHOULD_CONTINUE_PROMPT,
TEMPLATE_PROMPT,
Expand All @@ -27,7 +28,7 @@ import { type InitConfig, initConfigInputSchema } from './types';
import { Form, type FormChoice } from 'enquirer';

export const runForm = <T = Record<string, string>>(props: {
choices: Readonly<FormChoice[]>;
choices: Readonly<Choice[]>;
message: string;
name: string;
}) => {
Expand All @@ -36,7 +37,11 @@ export const runForm = <T = Record<string, string>>(props: {
const choices = props.choices.map((choice) => ({
...choice,
validate: (value: string | undefined) => {
if (!value || value === '' || value === choice.initial) {
if (
!value ||
value === '' ||
(value === choice.initial && !choice.allowInitial)
) {
return 'Form is not complete';
}

Expand Down
17 changes: 14 additions & 3 deletions src/cli/init/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ import {
isPlatform,
} from './validation';

import { Input, Select } from 'enquirer';
import { type FormChoice, Input, Select } from 'enquirer';

export type Choice = FormChoice & {
/**
* Whether the user is allowed to skip field entry and use the initial value.
*
* Defaults to `false`.
*/
allowInitial?: boolean;
};

export type BaseFields = Record<
(typeof BASE_CHOICES)[number]['name'],
Expand Down Expand Up @@ -62,14 +71,16 @@ const BASE_CHOICES = [
{
name: 'platformName',
message: 'Platform',
initial: PLATFORM_OPTIONS,
initial: 'arm64',
allowInitial: true,
validate: (value: unknown) =>
isPlatform(value) || `must be ${PLATFORM_OPTIONS}`,
},
{
name: 'defaultBranch',
message: 'Default Branch',
initial: 'master | main',
initial: 'main',
allowInitial: true,
validate: (value: unknown) =>
typeof value === 'string' && value.length > 0 ? true : 'required',
},
Expand Down

0 comments on commit 5750ab3

Please sign in to comment.