Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ linters:
- gosec
- copyloopvar
- errorlint
settings:
errcheck:
check-type-assertions: true
check-blank: true
govet:
enable-all: true
disable:
- fieldalignment
revive:
rules:
- name: exported
disabled: false
- name: error-return
disabled: false
- name: error-strings
disabled: false
- name: indent-error-flow
disabled: false
gosec:
excludes:
- G304
exclusions:
rules:
- path: _test\.go
linters:
- errcheck
- gocritic

formatters:
enable:
Expand All @@ -29,34 +56,7 @@ formatters:
local-prefixes:
- github.com/NodeOps-app/createos-cli

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
govet:
enable-all: true
disable:
- fieldalignment
revive:
rules:
- name: exported
disabled: false
- name: error-return
disabled: false
- name: error-strings
disabled: false
- name: indent-error-flow
disabled: false
gosec:
excludes:
- G304

issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
- gocritic
max-issues-per-linter: 0
max-same-issues: 0

Expand Down
7 changes: 5 additions & 2 deletions cmd/ask/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ func NewAskCommand() *cli.Command {
pterm.Info.Println("The 'ask' command uses OpenCode (https://opencode.ai), an open-source AI coding\nassistant, to power the CreateOS AI agent. It lets you manage your infrastructure\nusing natural language right from the terminal.")
fmt.Println()

install, _ := pterm.DefaultInteractiveConfirm.
install, err := pterm.DefaultInteractiveConfirm.
WithDefaultText("opencode is not installed. Install it now?").
WithDefaultValue(true).
Show()
if err != nil {
return err
}
if !install {
return fmt.Errorf("opencode is required for the ask command\n\n Install it manually:\n curl -fsSL https://opencode.ai/install | bash")
}
Expand All @@ -77,7 +80,7 @@ func NewAskCommand() *cli.Command {
installCmd.Stdin = os.Stdin
installCmd.Stdout = os.Stdout
installCmd.Stderr = os.Stderr
if err := installCmd.Run(); err != nil {
if err = installCmd.Run(); err != nil {
return fmt.Errorf("failed to install opencode: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func loginWithBrowser() error {
pterm.Println(pterm.Gray(" " + authURL))
fmt.Println()

if err := internaloauth.OpenBrowser(authURL); err != nil {
if err = internaloauth.OpenBrowser(authURL); err != nil {
pterm.Warning.Println("Could not open browser automatically. Please open the URL above.")
} else {
pterm.Info.Println("Waiting for you to complete login in your browser...")
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjobs/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newCronjobsActivitiesCommand() *cli.Command {
log,
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjobs/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newCronjobsListCommand() *cli.Command {
cj.CreatedAt.Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/cronjobs/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Examples:
// Decode existing settings for defaults in both TTY and non-TTY.
var currentSettings api.HTTPCronjobSettings
if existing.Settings != nil {
if err := json.Unmarshal(*existing.Settings, &currentSettings); err != nil {
if err = json.Unmarshal(*existing.Settings, &currentSettings); err != nil {
return fmt.Errorf("could not parse existing cron job settings: %w", err)
}
}
Expand Down
42 changes: 26 additions & 16 deletions cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ func NewDeployCommand() *cli.Command {
}

// Try to auto-detect from git remote
dir, _ := os.Getwd()
dir, err := os.Getwd()
if err != nil {
return fmt.Errorf("couldn't determine your current directory — please try again from a valid working directory")
}
repoFullName := git.GetRemoteFullName(dir)
if repoFullName != "" {
for _, p := range activeProjects {
Expand All @@ -160,10 +163,10 @@ func NewDeployCommand() *cli.Command {
}
if src.VCSFullName == repoFullName {
pterm.Info.Printf("Detected project %s from git remote (%s)\n", p.DisplayName, repoFullName)
useDetected, _ := pterm.DefaultInteractiveConfirm.
confirm := pterm.DefaultInteractiveConfirm.
WithDefaultText(fmt.Sprintf("Deploy %s?", p.DisplayName)).
WithDefaultValue(true).
Show()
WithDefaultValue(true)
useDetected, _ := confirm.Show() //nolint:errcheck
if useDetected {
projectID = p.ID
}
Expand Down Expand Up @@ -281,23 +284,23 @@ func UploadDir(client *api.APIClient, projectID, displayName, dir string) error
defer os.Remove(zipFile.Name()) //nolint:errcheck
defer zipFile.Close() //nolint:errcheck

spinner, _ := pterm.DefaultSpinner.Start("Packaging files...")
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...") //nolint:errcheck

if err := createZip(zipFile, absDir); err != nil {
if err = createZip(zipFile, absDir); err != nil {
spinner.Fail("Packaging failed")
return err
}

stat, _ := zipFile.Stat()
if stat != nil && stat.Size() > maxZipSize {
stat, statErr := zipFile.Stat()
if statErr == nil && stat.Size() > maxZipSize {
spinner.Fail("Package too large")
return fmt.Errorf("deployment package is %d MB (max %d MB)\n\n Tip: check that node_modules, .git, and build artifacts are excluded",
stat.Size()/(1024*1024), maxZipSize/(1024*1024))
}

spinner.UpdateText("Uploading...")

if err := zipFile.Close(); err != nil { //nolint:govet
if err = zipFile.Close(); err != nil {
return fmt.Errorf("could not flush deployment package: %w", err)
}

Expand Down Expand Up @@ -335,15 +338,15 @@ func deployUpload(c *cli.Context, client *api.APIClient, project *api.Project) e
defer os.Remove(zipFile.Name()) //nolint:errcheck
defer zipFile.Close() //nolint:errcheck

spinner, _ := pterm.DefaultSpinner.Start("Packaging files...")
spinner, _ := pterm.DefaultSpinner.Start("Packaging files...") //nolint:errcheck

if err := createZip(zipFile, absDir); err != nil {
if err = createZip(zipFile, absDir); err != nil {
spinner.Fail("Packaging failed")
return err
}

stat, _ := zipFile.Stat()
if stat != nil && stat.Size() > maxZipSize {
stat, statErr := zipFile.Stat()
if statErr == nil && stat.Size() > maxZipSize {
spinner.Fail("Package too large")
return fmt.Errorf("deployment package is %d MB (max %d MB)\n\n Tip: check that node_modules, .git, and build artifacts are excluded",
stat.Size()/(1024*1024), maxZipSize/(1024*1024))
Expand All @@ -352,7 +355,7 @@ func deployUpload(c *cli.Context, client *api.APIClient, project *api.Project) e
spinner.UpdateText("Uploading...")

// Close before uploading so the file is flushed
if err := zipFile.Close(); err != nil { //nolint:govet
if err = zipFile.Close(); err != nil {
return fmt.Errorf("could not flush deployment package: %w", err)
}

Expand Down Expand Up @@ -523,8 +526,15 @@ func createZip(w io.Writer, srcDir string) error {
// Check ignore patterns against basename and full relative path
baseName := filepath.Base(relPath)
for _, pattern := range ignorePatterns {
matchedBase, _ := filepath.Match(pattern, baseName)
matchedRel, _ := filepath.Match(pattern, filepath.ToSlash(relPath))
var matchedBase, matchedRel bool
matchedBase, err = filepath.Match(pattern, baseName)
if err != nil {
return fmt.Errorf("invalid ignore pattern %q: %w", pattern, err)
}
matchedRel, err = filepath.Match(pattern, filepath.ToSlash(relPath))
if err != nil {
return fmt.Errorf("invalid ignore pattern %q: %w", pattern, err)
}
if matchedBase || matchedRel {
if info.IsDir() {
return filepath.SkipDir
Expand Down
4 changes: 3 additions & 1 deletion cmd/deployments/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func pickDeployment(client *api.APIClient, projectID string, statusFilter []stri
})
}
fmt.Println()
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
if err = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
pterm.Error.Println(err)
}
fmt.Println()

options := make([]string, len(deployments))
Expand Down
4 changes: 3 additions & 1 deletion cmd/deployments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func newDeploymentsListCommand() *cli.Command {
d.CreatedAt.Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
pterm.Error.Println(err)
}
})
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/domains/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ func printDNSRecords(d api.Domain) {
tableData = append(tableData, []string{"TXT", txt.Name + "." + d.Name, txt.Value})
}

_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
fmt.Println()
}
2 changes: 1 addition & 1 deletion cmd/domains/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func newDomainsListCommand() *cli.Command {
}
tableData = append(tableData, []string{d.ID, d.Name, env, icon + " " + d.Status, msg})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render() //nolint:errcheck
fmt.Println()
})
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/domains/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newDomainsVerifyCommand() *cli.Command {
return err
}

_ = client.RefreshDomain(projectID, domainID)
_ = client.RefreshDomain(projectID, domainID) //nolint:errcheck

domain, err := findDomain(client, projectID, domainID)
if err != nil {
Expand Down Expand Up @@ -78,7 +78,7 @@ func newDomainsVerifyCommand() *cli.Command {
return nil
}

_ = client.RefreshDomain(projectID, domainID)
_ = client.RefreshDomain(projectID, domainID) //nolint:errcheck
domains, err := client.ListDomains(projectID)
if err != nil {
continue
Expand Down
4 changes: 2 additions & 2 deletions cmd/env/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func ensureEnvGitignored() {
if err != nil {
return
}
defer f.Close() //nolint:errcheck
_, _ = f.WriteString(content)
defer f.Close() //nolint:errcheck
_, _ = f.WriteString(content) //nolint:errcheck

pterm.Println(pterm.Gray(" Added .env.* to .gitignore"))
}
8 changes: 4 additions & 4 deletions cmd/env/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ func newEnvPullCommand() *cli.Command {

// Check if file exists
if !c.Bool("force") {
if _, err := os.Stat(filePath); err == nil {
if _, err = os.Stat(filePath); err == nil {
if !terminal.IsInteractive() {
return fmt.Errorf("%s already exists — use --force to overwrite", filePath)
}
result, _ := pterm.DefaultInteractiveConfirm.
prompt := pterm.DefaultInteractiveConfirm.
WithDefaultText(fmt.Sprintf("%s already exists. Overwrite?", filePath)).
WithDefaultValue(false).
Show()
WithDefaultValue(false)
result, _ := prompt.Show() //nolint:errcheck //nolint:errcheck
if !result {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/env/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func newEnvPushCommand() *cli.Command {
fmt.Printf(" %s\n", k)
}
fmt.Println()
result, _ := pterm.DefaultInteractiveConfirm.
prompt := pterm.DefaultInteractiveConfirm.
WithDefaultText("Continue?").
WithDefaultValue(true).
Show()
WithDefaultValue(true)
result, _ := prompt.Show() //nolint:errcheck //nolint:errcheck
if !result {
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/environments/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ func newEnvironmentsListCommand() *cli.Command {
env.CreatedAt.Format("2006-01-02 15:04:05"),
})
}
_ = pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil {
pterm.Error.Println(err)
}
fmt.Println()
})
return nil
Expand Down
Loading