Skip to content

feat(cli): add --id parameter to templates init command#7116

Merged
johnstcn merged 2 commits into
mainfrom
cj/cli-template-init-id-arg
Apr 13, 2023
Merged

feat(cli): add --id parameter to templates init command#7116
johnstcn merged 2 commits into
mainfrom
cj/cli-template-init-id-arg

Conversation

@johnstcn
Copy link
Copy Markdown
Member

#6849 broke develop.sh in a hard-to-debug manner.
To automatically import a working template, we used to run echo $TEMPLATE_NAME | coder templates init $TEMP_DIR. The assumption was that the code-server template would stay around. Unfortunately, the echo name | coder templates init is hard to troubleshoot as it has side-effects such as clearing terminal output.

This PR makes the following changes:

  1. Adds an --id parameter to coder templates init so that you can non-interactively initialize a specific example template by ID (e.g. folder name)
  2. Updates develop.sh and lima/coder.yaml to use this parameter to select the docker example template.

@johnstcn johnstcn self-assigned this Apr 13, 2023
@johnstcn johnstcn marked this pull request as ready for review April 13, 2023 10:34
@johnstcn johnstcn requested review from mafredri and mtojek April 13, 2023 10:34
Copy link
Copy Markdown
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, pointed out a few small things but nothing critical.

Comment thread cli/templateinit.go Outdated
Comment thread cli/templateinit.go Outdated
Comment thread cli/templateinit.go Outdated
Comment thread cli/templateinit.go Outdated
if !ok {
ids := values(optsToID)
sort.Strings(ids)
return xerrors.Errorf("Template ID %q does not exist!\nValid options are: %q", templateIDArg, ids)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a biggie, but this was a bit of a brain twister for me since the name/id stored in the map seemed unintuitive. 😅 To me it would make sense to have opts[id] = name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our goal is to have an example template ID that we can pass to examples.Archive. The choices passed to cliui.Select are just literally what gets displayed, so we have to map that back to ID. I'd honestly prefer if cliui.Select took a map[string]string so you could differentiate what gets displayed to what gets returned, but that's a bigger change than I want to make here.

Comment thread cli/templateinit.go Outdated
@johnstcn johnstcn merged commit 87fe16c into main Apr 13, 2023
@johnstcn johnstcn deleted the cj/cli-template-init-id-arg branch April 13, 2023 14:02
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants