Skip to content

Commit

Permalink
feat: auto-copy api key to clipboard (#1137)
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak authored Sep 23, 2024
1 parent ac17040 commit f66dc4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/atotto/clipboard v0.1.4
github.com/aws/aws-sdk-go v1.54.19
github.com/aws/aws-sdk-go-v2/service/codecommit v1.24.3
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
Expand Down
30 changes: 9 additions & 21 deletions pkg/views/server/apikey/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,29 @@ package apikey

import (
"fmt"
"os"

"github.com/atotto/clipboard"
"github.com/charmbracelet/lipgloss"
"github.com/daytonaio/daytona/pkg/views"
"golang.org/x/term"
)

var minimumLayoutWidth = 80

func Render(key, apiUrl string) {
var output string

terminalWidth, _, err := term.GetSize(int(os.Stdout.Fd()))
if err != nil {
fmt.Println("error: Unable to get terminal size")
return
}

output += fmt.Sprintf("%s %s", views.GetPropertyKey("Generated API key: "), key) + "\n\n"

output += "Make sure to copy it as you will not be able to see it again." + "\n\n"

output += views.SeparatorString + "\n\n"

output += "You can connect to the Daytona Server from a client machine by running:"

formattedCommand := lipgloss.NewStyle().Foreground(views.Green).Render(fmt.Sprintf("daytona profile add -a \\\n%s \\\n-k %s", apiUrl, key))
command := lipgloss.NewStyle().Foreground(views.Green).Render(fmt.Sprintf("daytona profile add -a %s -k %s", apiUrl, key))
views.RenderContainerLayout(views.GetInfoMessage(output))

command := fmt.Sprintf("daytona profile add -a %s -k %s", apiUrl, key)
fmt.Println(lipgloss.NewStyle().Padding(0).Foreground(views.Green).Render(command))

if terminalWidth >= minimumLayoutWidth {
output += "\n\n" + formattedCommand
views.RenderContainerLayout(views.GetInfoMessage(output))
if err := clipboard.WriteAll(command); err == nil {
output = "The command has been copied to your clipboard."
} else {
views.RenderContainerLayout(views.GetInfoMessage(output))
fmt.Println(command + "\n\n")
output = "Make sure to copy it as you will not be able to see it again."
}

views.RenderContainerLayout(views.GetInfoMessage(output))
}

0 comments on commit f66dc4a

Please sign in to comment.