Skip to content

feat: Unify cli behavior for templates create and update #1385

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 3 commits into from
May 12, 2022

Conversation

mafredri
Copy link
Member

This PR changes the templates update command to be more in line with templates create.

Changes:

  • The directory is either cwd or provided via the -d flag, same as create
  • A confirmation prompt is now shown to confirm the update directory, same as create
  • For both create and update the --provider flag is now called --test.provider and has no shorthand to improve clarity
  • A test was added for update

Other considerations:

  • I considered turning dir into a mandatory arg and name into an optional flag as it would be quite low effor to do templates create ., tempaltes update . and by default infer the name from the provided directory. Ultimately decided to keep the behavior as-is but am open to make the change if it seems like a good idea

Fixes #565


Observations:

  • While trying to get the spinner to show, I tried dumping a few MB of data into the folder, only to notice there's a 1MB limit. This does seem a bit conservative?

@mafredri mafredri self-assigned this May 11, 2022
@mafredri mafredri requested review from bpmct, johnstcn and a team May 11, 2022 13:23
@codecov
Copy link

codecov bot commented May 11, 2022

Codecov Report

Merging #1385 (6bfed73) into main (9d94f4f) will increase coverage by 0.38%.
The diff coverage is 82.00%.

@@            Coverage Diff             @@
##             main    #1385      +/-   ##
==========================================
+ Coverage   66.93%   67.32%   +0.38%     
==========================================
  Files         288      288              
  Lines       18856    19105     +249     
  Branches      241      241              
==========================================
+ Hits        12622    12862     +240     
+ Misses       4944     4931      -13     
- Partials     1290     1312      +22     
Flag Coverage Δ
unittest-go-macos-latest 54.60% <82.00%> (+0.52%) ⬆️
unittest-go-postgres- 65.73% <82.00%> (+0.30%) ⬆️
unittest-go-ubuntu-latest 56.72% <82.00%> (+0.33%) ⬆️
unittest-go-windows-2022 52.92% <82.00%> (+0.54%) ⬆️
unittest-js 74.24% <ø> (ø)
Impacted Files Coverage Δ
cli/templatecreate.go 48.36% <63.15%> (+1.44%) ⬆️
cli/templateupdate.go 60.67% <93.54%> (+53.42%) ⬆️
provisionersdk/serve.go 35.13% <0.00%> (-8.11%) ⬇️
coderd/turnconn/turnconn.go 81.91% <0.00%> (-3.20%) ⬇️
codersdk/workspaceagents.go 51.52% <0.00%> (-1.36%) ⬇️
coderd/organizations.go 56.23% <0.00%> (-1.01%) ⬇️
coderd/provisionerdaemons.go 63.81% <0.00%> (-0.17%) ⬇️
coderd/database/queries.sql.go 77.78% <0.00%> (-0.13%) ⬇️
cli/templates.go 100.00% <0.00%> (ø)
provisionersdk/agent.go 100.00% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d94f4f...6bfed73. Read the comment docs.


currentDirectory, _ := os.Getwd()
cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from")
cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend")
Copy link
Member

Choose a reason for hiding this comment

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

I really like this!

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is provisioner -> test.provisioner a good idea?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, is it possible / advisable to allow people to switch from one provisioner to another for a template that already exists?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because this is not a flag that should be exposed to users (which is why it's hidden on the lines below). Naming it test. is a convention we could use throughout the cli when we need to modify functionality for test purposes, it also makes it very clear that these are not ordinary flags.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, I get that terraform is the only "real" provisioner at the moment, but that may not be true long term, and so you'd use that flag outside of testing purposes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think at that point we'd figure out how to officially support it, and not re-use this flag.

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

@johnstcn left a great review, and LGTM too! 🥳

The change of provisioner to test.provisioner is really nice!

@mafredri mafredri merged commit 56076a0 into main May 12, 2022
@mafredri mafredri deleted the mafredri/feat-common-cli-params-for-templates branch May 12, 2022 11:55
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use common directory params for templates create and templates update
5 participants