Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: bryans-go <[email protected]>
  • Loading branch information
bryans-go committed Oct 15, 2024
2 parents daa9f3e + 2d67fac commit 5258778
Show file tree
Hide file tree
Showing 52 changed files with 957 additions and 860 deletions.
13 changes: 6 additions & 7 deletions cmd/daytona/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ type GitProvider struct {
Name string
}

const configDoesntExistError = "config does not exist. Run `daytona serve` to create a default profile or `daytona profile add` to connect to a remote server."

func IsNotExist(err error) bool {
return err.Error() == configDoesntExistError
}

func GetConfig() (*Config, error) {
configFilePath, err := getConfigPath()
if err != nil {
Expand All @@ -58,7 +52,12 @@ func GetConfig() (*Config, error) {

_, err = os.Stat(configFilePath)
if os.IsNotExist(err) {
return nil, errors.New(configDoesntExistError)
config := &Config{
Id: uuid.NewString(),
DefaultIdeId: DefaultIdeId,
TelemetryEnabled: true,
}
return config, config.Save()
}

if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions docs/daytona_prebuild_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
Add a prebuild configuration

```
daytona prebuild add [flags]
daytona prebuild add [PROJECT_CONFIG] [flags]
```

### Options

```
--run Run the prebuild once after adding it
-b, --branch string Git branch for the prebuild
-c, --commit-interval int Commit interval for running a prebuild - leave blank to ignore push events
-r, --retention int Maximum number of resulting builds stored at a time
--run Run the prebuild once after adding it
-t, --trigger-files strings Full paths of files whose changes should explicitly trigger a prebuild
```

### Options inherited from parent commands
Expand Down
8 changes: 6 additions & 2 deletions docs/daytona_prebuild_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
Update a prebuild configuration

```
daytona prebuild update [flags]
daytona prebuild update [PROJECT_CONFIG] [PREBUILD_ID] [flags]
```

### Options

```
--run Run the prebuild once after updating it
-b, --branch string Git branch for the prebuild
-c, --commit-interval int Commit interval for running a prebuild - leave blank to ignore push events
-r, --retention int Maximum number of resulting builds stored at a time
--run Run the prebuild once after updating it
-t, --trigger-files strings Full paths of files whose changes should explicitly trigger a prebuild
```

### Options inherited from parent commands
Expand Down
19 changes: 18 additions & 1 deletion hack/docs/daytona_prebuild_add.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
name: daytona prebuild add
synopsis: Add a prebuild configuration
usage: daytona prebuild add [flags]
usage: daytona prebuild add [PROJECT_CONFIG] [flags]
options:
- name: branch
shorthand: b
usage: Git branch for the prebuild
- name: commit-interval
shorthand: c
default_value: "0"
usage: |
Commit interval for running a prebuild - leave blank to ignore push events
- name: retention
shorthand: r
default_value: "0"
usage: Maximum number of resulting builds stored at a time
- name: run
default_value: "false"
usage: Run the prebuild once after adding it
- name: trigger-files
shorthand: t
default_value: '[]'
usage: |
Full paths of files whose changes should explicitly trigger a prebuild
inherited_options:
- name: help
default_value: "false"
Expand Down
19 changes: 18 additions & 1 deletion hack/docs/daytona_prebuild_update.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
name: daytona prebuild update
synopsis: Update a prebuild configuration
usage: daytona prebuild update [flags]
usage: daytona prebuild update [PROJECT_CONFIG] [PREBUILD_ID] [flags]
options:
- name: branch
shorthand: b
usage: Git branch for the prebuild
- name: commit-interval
shorthand: c
default_value: "0"
usage: |
Commit interval for running a prebuild - leave blank to ignore push events
- name: retention
shorthand: r
default_value: "0"
usage: Maximum number of resulting builds stored at a time
- name: run
default_value: "false"
usage: Run the prebuild once after updating it
- name: trigger-files
shorthand: t
default_value: '[]'
usage: |
Full paths of files whose changes should explicitly trigger a prebuild
inherited_options:
- name: help
default_value: "false"
Expand Down
45 changes: 20 additions & 25 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (a *Agent) Start() error {
}

func (a *Agent) startProjectMode() error {
err := a.setDefaultConfig()
err := a.ensureDefaultProfile()
if err != nil {
return err
}
Expand Down Expand Up @@ -195,38 +195,33 @@ func (a *Agent) getGitUser(gitProviderId string) (*apiclient.GitUser, error) {
return userData, nil
}

func (a *Agent) setDefaultConfig() error {
func (a *Agent) ensureDefaultProfile() error {
existingConfig, err := config.GetConfig()
if err != nil && !config.IsNotExist(err) {
if err != nil {
return err
}

if existingConfig != nil {
for _, profile := range existingConfig.Profiles {
if profile.Id == "default" {
return nil
}
}
if existingConfig == nil {
return errors.New("config does not exist")
}

config := &config.Config{
Id: a.Config.ClientId,
ActiveProfileId: "default",
DefaultIdeId: "vscode",
Profiles: []config.Profile{
{
Id: "default",
Name: "default",
Api: config.ServerApi{
Url: a.Config.Server.ApiUrl,
Key: a.Config.Server.ApiKey,
},
},
},
TelemetryEnabled: a.TelemetryEnabled,
for _, profile := range existingConfig.Profiles {
if profile.Id == "default" {
return nil
}
}

return config.Save()
existingConfig.Id = a.Config.ClientId
existingConfig.TelemetryEnabled = a.TelemetryEnabled

return existingConfig.AddProfile(config.Profile{
Id: "default",
Name: "default",
Api: config.ServerApi{
Url: a.Config.Server.ApiUrl,
Key: a.Config.Server.ApiKey,
},
})
}

// Agent uptime in seconds
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/controllers/provider/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func InstallProvider(ctx *gin.Context) {
}
}

downloadPath, err := server.ProviderManager.DownloadProvider(req.DownloadUrls, req.Name, true)
downloadPath, err := server.ProviderManager.DownloadProvider(ctx.Request.Context(), req.DownloadUrls, req.Name, true)
if err != nil {
ctx.AbortWithError(http.StatusInternalServerError, fmt.Errorf("failed to download provider: %w", err))
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/apikey/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/daytonaio/daytona/internal/util"
apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/apiclient"
"github.com/daytonaio/daytona/pkg/views/server/apikey"
view "github.com/daytonaio/daytona/pkg/views/server/apikey"
"github.com/daytonaio/daytona/pkg/views/apikey"
view "github.com/daytonaio/daytona/pkg/views/apikey"
)

var GenerateCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/apikey/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/cmd/format"
"github.com/daytonaio/daytona/pkg/views/server/apikey"
"github.com/daytonaio/daytona/pkg/views/apikey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/apikey/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/daytonaio/daytona/pkg/apiclient"
"github.com/daytonaio/daytona/pkg/common"
"github.com/daytonaio/daytona/pkg/views"
"github.com/daytonaio/daytona/pkg/views/server/apikey"
"github.com/daytonaio/daytona/pkg/views/apikey"
)

var yesFlag bool
Expand Down
45 changes: 41 additions & 4 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/signal"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -92,6 +94,11 @@ func Execute() error {
return cmd.Help()
}

err = ensureProfiles(cmd)
if err != nil {
return err
}

err = rootCmd.Execute()

endTime := time.Now()
Expand Down Expand Up @@ -141,6 +148,36 @@ func validateCommands(rootCmd *cobra.Command, args []string) (cmd *cobra.Command
return currentCmd, flags, nil
}

func ensureProfiles(cmd *cobra.Command) error {
exemptions := []string{
"daytona",
"daytona help",
"daytona docs",
"daytona version",
"daytona profile add",
"daytona serve",
"daytona server",
"daytona ide",
"daytona telemetry enable",
"daytona telemetry disable",
}

if slices.Contains(exemptions, cmd.CommandPath()) {
return nil
}

c, err := config.GetConfig()
if err != nil {
return err
}

if len(c.Profiles) == 0 {
return errors.New("no profiles found. Run `daytona serve` to create a default profile or `daytona profile add` to connect to a remote server.")
}

return nil
}

func SetupRootCommand(cmd *cobra.Command) {
// Common commands
cmd.AddCommand(AutoCompleteCmd)
Expand Down Expand Up @@ -240,7 +277,7 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client
props["called_as"] = os.Args[1]
err := telemetryService.TrackCliEvent(telemetry.CliEventInvalidCmd, clientId, props)
if err != nil {
log.Error(err)
log.Trace(err)
}
telemetryService.Close()
}
Expand All @@ -251,7 +288,7 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client
if telemetryEnabled {
err := telemetryService.TrackCliEvent(telemetry.CliEventCmdStart, clientId, GetCmdTelemetryData(cmd, flags))
if err != nil {
log.Error(err)
log.Trace(err)
}

go func() {
Expand All @@ -267,7 +304,7 @@ func PreRun(rootCmd *cobra.Command, args []string, telemetryEnabled bool, client

err := telemetryService.TrackCliEvent(telemetry.CliEventCmdEnd, clientId, props)
if err != nil {
log.Error(err)
log.Trace(err)
}
telemetryService.Close()
os.Exit(0)
Expand All @@ -289,7 +326,7 @@ func PostRun(cmd *cobra.Command, cmdErr error, telemetryService telemetry.Teleme

err := telemetryService.TrackCliEvent(telemetry.CliEventCmdEnd, clientId, props)
if err != nil {
log.Error(err)
log.Trace(err)
}
telemetryService.Close()
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/cmd/gitprovider/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/pkg/views"
gitprovider_view "github.com/daytonaio/daytona/pkg/views/gitprovider"
"github.com/daytonaio/daytona/pkg/views/workspace/selection"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -46,10 +46,7 @@ var gitProviderDeleteCmd = &cobra.Command{
return nil
}

selectedGitProvider, err := gitprovider_view.GetGitProviderFromPrompt(ctx, gitProviders, apiClient)
if err != nil {
return err
}
selectedGitProvider := selection.GetGitProviderConfigFromPrompt(gitProviders, false, "Remove")

if selectedGitProvider == nil {
return nil
Expand Down
Loading

0 comments on commit 5258778

Please sign in to comment.