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

Skip to content

feat: Add "coder" CLI #221

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 8 commits into from
Feb 10, 2022
Merged

feat: Add "coder" CLI #221

merged 8 commits into from
Feb 10, 2022

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Feb 9, 2022

Scaffolds the base of the CLI, and establishes a basic design for the IO.

image

@kylecarbs kylecarbs self-assigned this Feb 9, 2022
@codecov
Copy link

codecov bot commented Feb 9, 2022

Codecov Report

Merging #221 (6aec3a1) into main (277318b) will decrease coverage by 1.28%.
The diff coverage is 52.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #221      +/-   ##
==========================================
- Coverage   68.43%   67.14%   -1.29%     
==========================================
  Files         111      120       +9     
  Lines        6003     6484     +481     
  Branches       67       67              
==========================================
+ Hits         4108     4354     +246     
- Misses       1507     1711     +204     
- Partials      388      419      +31     
Flag Coverage Δ
unittest-go-macos-latest 65.02% <52.69%> (-1.42%) ⬇️
unittest-go-ubuntu-latest 66.35% <52.69%> (-1.28%) ⬇️
unittest-go-windows-latest 66.07% <67.32%> (+0.09%) ⬆️
unittest-js 64.76% <ø> (ø)
Impacted Files Coverage Δ
cli/projectcreate.go 3.60% <3.60%> (ø)
codersdk/users.go 68.96% <53.84%> (-2.66%) ⬇️
cli/login.go 54.90% <54.90%> (ø)
cli/config/file.go 61.76% <61.76%> (ø)
cli/projectplan.go 62.50% <62.50%> (ø)
cli/projectupdate.go 62.50% <62.50%> (ø)
coderd/users.go 59.68% <64.70%> (+0.36%) ⬆️
cli/root.go 69.74% <69.74%> (ø)
coderd/cmd/root.go 81.69% <77.77%> (-4.43%) ⬇️
cli/projects.go 100.00% <100.00%> (ø)
... and 6 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 277318b...6aec3a1. Read the comment docs.

require.NoError(t, err)
data, err := root.Session().Read()
require.NoError(t, err)
require.Equal(t, "test", string(data))
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realize GH actions could push failures inline - that's kind of cool (re: lint errors on this line)

Comment on lines +27 to +32
Long: ` ▄█▀ ▀█▄
▄▄ ▀▀▀ █▌ ██▀▀█▄ ▐█
▄▄██▀▀█▄▄▄ ██ ██ █▀▀█ ▐█▀▀██ ▄█▀▀█ █▀▀
█▌ ▄▌ ▐█ █▌ ▀█▄▄▄█▌ █ █ ▐█ ██ ██▀▀ █
██████▀▄█ ▀▀▀▀ ▀▀▀▀ ▀▀▀▀▀ ▀▀▀▀ ▀
` + color.New(color.Underline).Sprint("Self-hosted developer workspaces on your infra") + `
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 😎

return coderd.Organization{}, nil
}
// For now, we won't use the config to set this.
// Eventually, we will support changing using "coder switch <org>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

}

client := codersdk.New(serverURL)
hasInitialUser, err := client.HasInitialUser(cmd.Context())
Copy link
Contributor

Choose a reason for hiding this comment

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

That's cool that it guides you through set-up the first time you login, if there isn't a user available yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed! I wanted the full flow to be available. I added tests now too!

}

func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
root := createConfig(cmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we're sticking with the write-token-to-file approach - do you think it's worth logging an issue to use platform-specific tools like Keychain, wincred, SecretStore, etc to persist the credentials? For example, using the credential helpers here: https://github.com/docker/docker-credential-helpers ?

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 it's wise to use something else, yeah. I was going to do this post-black triangle. I'll make an issue!


func login() *cobra.Command {
return &cobra.Command{
Use: "login <url>",
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have tests in place that run the CLI on Windows / Linux / Mac - maybe that would be a good-first-issue for getting someone on-boarded in the repo?

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 actually just made some! I wasn't sure how to scaffold it, but I think it's OK for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess having support for a fake db should make these tests easier now!

Copy link
Contributor

@bryphe-coder bryphe-coder left a comment

Choose a reason for hiding this comment

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

Just a few questions, but overall this looks great. Looking forward to being able to create projects so that we can run through the full flow!

fmt.Fprintf(cmd.OutOrStdout(), "%s %s\n", color.HiGreenString("[parse]"), log.Output)
}

fmt.Printf("Projects %+v %+v\n", projects, organization)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, GH actions is able to inline the test failures too. It looks like there are some failures here that are caught in CI.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where projects is getting populated here. Do we need to make an extra call w/ the job ID from ImportProvisionerJob to get it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I adjusted this a bit to make more sense for the state it's in. It's kinda in a mergeable state, but not really.

@@ -0,0 +1,161 @@
package cli
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be added to our Makefile? Like make bin/coder?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! I'll add.


func login() *cobra.Command {
return &cobra.Command{
Use: "login <url>",
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess having support for a fake db should make these tests easier now!

@kylecarbs
Copy link
Member Author

I already know I'll have to abstract the terminal console out for Windows, but I really don't want to 😢

@kylecarbs kylecarbs merged commit 07fe5ce into main Feb 10, 2022
@kylecarbs kylecarbs deleted the cli branch February 10, 2022 14:33
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.

3 participants