Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2023

Conversation

johnstcn
Copy link
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
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.

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
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
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.

@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