Skip to content

Commit 8eb78c8

Browse files
committed
chore(workflow-cli): format go code
1 parent 0795727 commit 8eb78c8

95 files changed

Lines changed: 806 additions & 724 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/root.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package cmd provides the root command for the Drycc CLI.
12
/*
23
Copyright © 2025 NAME HERE <EMAIL ADDRESS>
34
*/
@@ -13,6 +14,7 @@ import (
1314
"github.com/spf13/cobra"
1415
)
1516

17+
// NewDryccCommand creates the root command for the Drycc CLI.
1618
func NewDryccCommand() *cobra.Command {
1719
var flags struct {
1820
config string
@@ -29,8 +31,11 @@ func NewDryccCommand() *cobra.Command {
2931
cmdr = commands.DryccCmd{ConfigFile: flags.config, WOut: os.Stdout, WErr: os.Stderr, WIn: os.Stdin, Location: time.Local}
3032
},
3133
}
32-
33-
rootCmd.PersistentFlags().StringVarP(&flags.config, "config", "c", "~/.drycc/client.json", i18n.T("Path to configuration file"))
34+
config := "~/.drycc/client.json"
35+
if v, ok := os.LookupEnv("DRYCC_PROFILE"); ok {
36+
config = v
37+
}
38+
rootCmd.PersistentFlags().StringVarP(&flags.config, "config", "c", config, i18n.T("Path to configuration file"))
3439
rootCmd.PersistentFlags().BoolVarP(&flags.help, "help", "h", false, i18n.T("Display help information"))
3540

3641
rootCmd.AddCommand(parser.NewAppsCommand(&cmdr))

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.25
55
require (
66
github.com/chai2010/gettext-go v1.0.3
77
github.com/containerd/console v1.0.4
8-
github.com/drycc/controller-sdk-go v0.0.0-20250625050826-8be5432737be
9-
github.com/drycc/pkg v0.0.0-20241223062248-04810c5faa4b
8+
github.com/drycc/controller-sdk-go v0.0.0-20250917070349-910603c54927
9+
github.com/drycc/pkg v0.0.0-20250917064731-345368da3dbf
1010
github.com/minio/selfupdate v0.6.0
1111
github.com/olekukonko/tablewriter v0.0.5
1212
github.com/schollz/progressbar/v3 v3.18.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6N
1111
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1212
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1313
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14-
github.com/drycc/controller-sdk-go v0.0.0-20250625050826-8be5432737be h1:aIdgIpvYa6SuPQIV3C3UKNItMaTK3YDxP0sRlfrYSUE=
15-
github.com/drycc/controller-sdk-go v0.0.0-20250625050826-8be5432737be/go.mod h1:MbFxGlgRQUaVlThbn3DmB06EJsf+e3/O+qgbWmdvtoE=
16-
github.com/drycc/pkg v0.0.0-20241223062248-04810c5faa4b h1:wSIZheOVyeakCpI1i6xDta9e5YLZgNCqw7JfxC6R5MA=
17-
github.com/drycc/pkg v0.0.0-20241223062248-04810c5faa4b/go.mod h1:upGcZF/RCEqidGjSnWHh/txRC1I4GPsRGvF8/+bDfwU=
14+
github.com/drycc/controller-sdk-go v0.0.0-20250917070349-910603c54927 h1:c1n5N5urQztpcBy93U+oBEWyRXXaa0k3PwCg9pzXqe0=
15+
github.com/drycc/controller-sdk-go v0.0.0-20250917070349-910603c54927/go.mod h1:eHcmYwg81ASlP55/U587xnBZnZoeZnPHXGeQ8nYWnsg=
16+
github.com/drycc/pkg v0.0.0-20250917064731-345368da3dbf h1:CYy3NoPhfFhkGAbEppTOQfY/HC2s0FJDcBgbtRKeweg=
17+
github.com/drycc/pkg v0.0.0-20250917064731-345368da3dbf/go.mod h1:BrrNrNskHKm+nJYhXfGuI114w8nupi0AMo8QZHID7CM=
1818
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
1919
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
2020
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=

internal/commands/apps.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package commands provides implementations for Drycc CLI commands.
12
package commands
23

34
import (
@@ -10,7 +11,7 @@ import (
1011
"github.com/drycc/controller-sdk-go/appsettings"
1112
"github.com/drycc/controller-sdk-go/domains"
1213
"github.com/drycc/controller-sdk-go/ps"
13-
"github.com/drycc/workflow-cli/internal/utils"
14+
"github.com/drycc/workflow-cli/internal/loader"
1415
"github.com/drycc/workflow-cli/pkg/git"
1516
"github.com/drycc/workflow-cli/pkg/settings"
1617
"github.com/drycc/workflow-cli/pkg/webbrowser"
@@ -59,7 +60,6 @@ func (d *DryccCmd) AppCreate(id, remote string, noRemote bool) error {
5960
// AppsList lists apps on the Drycc controller.
6061
func (d *DryccCmd) AppsList(results int) error {
6162
s, err := settings.Load(d.ConfigFile)
62-
6363
if err != nil {
6464
return err
6565
}
@@ -91,8 +91,7 @@ func (d *DryccCmd) AppsList(results int) error {
9191

9292
// AppInfo prints info about app.
9393
func (d *DryccCmd) AppInfo(appID string) error {
94-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
95-
94+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
9695
if err != nil {
9796
return err
9897
}
@@ -177,8 +176,7 @@ func (d *DryccCmd) AppInfo(appID string) error {
177176

178177
// AppOpen opens an app in the default webbrowser.
179178
func (d *DryccCmd) AppOpen(appID string) error {
180-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
181-
179+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
182180
if err != nil {
183181
return err
184182
}
@@ -192,7 +190,7 @@ func (d *DryccCmd) AppOpen(appID string) error {
192190
return fmt.Errorf(noDomainAssignedMsg, appID)
193191
}
194192

195-
if !(strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://")) {
193+
if !strings.HasPrefix(u, "http://") && !strings.HasPrefix(u, "https://") {
196194
u = "http://" + u
197195
}
198196

@@ -201,8 +199,7 @@ func (d *DryccCmd) AppOpen(appID string) error {
201199

202200
// AppRun runs a one time command in the app.
203201
func (d *DryccCmd) AppRun(appID, command string, volumeVars []string, timeout, expires uint32) error {
204-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
205-
202+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
206203
if err != nil {
207204
return err
208205
}
@@ -219,8 +216,8 @@ func (d *DryccCmd) AppRun(appID, command string, volumeVars []string, timeout, e
219216
return nil
220217
}
221218

222-
func parseMount(volumeVars []string) (map[string]interface{}, error) {
223-
volumeMap := make(map[string]interface{})
219+
func parseMount(volumeVars []string) (map[string]any, error) {
220+
volumeMap := make(map[string]any)
224221

225222
regex := regexp.MustCompile(`^([A-z_]+[A-z0-9_]*):([\s\S]*)$`)
226223
for _, volume := range volumeVars {
@@ -239,14 +236,12 @@ func (d *DryccCmd) AppDestroy(appID, confirm string) error {
239236
gitSession := false
240237

241238
s, err := settings.Load(d.ConfigFile)
242-
243239
if err != nil {
244240
return err
245241
}
246242

247243
if appID == "" {
248244
appID, err = git.DetectAppName(git.DefaultCmd, s.Client.ControllerURL.Host)
249-
250245
if err != nil {
251246
return err
252247
}
@@ -286,8 +281,7 @@ func (d *DryccCmd) AppDestroy(appID, confirm string) error {
286281

287282
// AppTransfer transfers app ownership to another user.
288283
func (d *DryccCmd) AppTransfer(appID, username string) error {
289-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
290-
284+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
291285
if err != nil {
292286
return err
293287
}

internal/commands/apps_test.go

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
"os"
88
"testing"
99

10-
"github.com/stretchr/testify/assert"
11-
1210
"github.com/drycc/workflow-cli/pkg/git"
1311
"github.com/drycc/workflow-cli/pkg/settings"
1412
"github.com/drycc/workflow-cli/pkg/testutil"
13+
"github.com/stretchr/testify/assert"
1514
)
1615

1716
type expandURLCases struct {
@@ -62,10 +61,10 @@ func TestAppsList(t *testing.T) {
6261

6362
err = cmdr.AppsList(-1)
6463
assert.NoError(t, err)
65-
assert.Equal(t, b.String(), `ID OWNER CREATED UPDATED
66-
lorem-ipsum dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
67-
consectetur adipiscing 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
68-
`, "output")
64+
testutil.AssertOutput(t, b.String(), `ID OWNER CREATED UPDATED
65+
lorem-ipsum dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
66+
consectetur adipiscing 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
67+
`)
6968
}
7069

7170
func TestAppsListLimit(t *testing.T) {
@@ -101,9 +100,9 @@ func TestAppsListLimit(t *testing.T) {
101100

102101
err = cmdr.AppsList(1)
103102
assert.NoError(t, err)
104-
assert.Equal(t, b.String(), `ID OWNER CREATED UPDATED
105-
lorem-ipsum dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
106-
`, "output")
103+
testutil.AssertOutput(t, b.String(), `ID OWNER CREATED UPDATED
104+
lorem-ipsum dolar-sit-amet 2016-08-22T17:40:16Z 2016-08-22T17:40:16Z
105+
`)
107106
}
108107

109108
func TestAppsInfo(t *testing.T) {
@@ -187,26 +186,26 @@ func TestAppsInfo(t *testing.T) {
187186
}
188187
err = cmdr.AppInfo("lorem-ipsum")
189188
assert.NoError(t, err)
190-
assert.Equal(t, b.String(), `App: lorem-ipsum
191-
URL: `+url+`
192-
UUID: c4aed81c-d1ca-4ff1-ab89-d2151264e1a3
193-
Owner: dolar-sit-amet
194-
Created: 2016-08-22T17:40:16Z
195-
Updated: 2016-08-22T17:40:16Z
196-
Processes:
197-
Name: lorem-ipsum-cmd-1911796442-48b58
198-
Release: v2
199-
State: up
200-
Ptype: cmd
201-
Started: 2016-08-22T17:42:16Z
202-
Domains:
203-
Domain: lorem-ipsum
204-
Created: 2016-08-22T17:40:16Z
205-
Updated: 2016-08-22T17:40:16Z
206-
Labels:
207-
Key: team
208-
Value: frontend
209-
`, "output")
189+
testutil.AssertOutput(t, b.String(), `App: lorem-ipsum
190+
URL: `+url+`
191+
UUID: c4aed81c-d1ca-4ff1-ab89-d2151264e1a3
192+
Owner: dolar-sit-amet
193+
Created: 2016-08-22T17:40:16Z
194+
Updated: 2016-08-22T17:40:16Z
195+
Processes:
196+
Name: lorem-ipsum-cmd-1911796442-48b58
197+
Release: v2
198+
State: up
199+
Ptype: cmd
200+
Started: 2016-08-22T17:42:16Z
201+
Domains:
202+
Domain: lorem-ipsum
203+
Created: 2016-08-22T17:40:16Z
204+
Updated: 2016-08-22T17:40:16Z
205+
Labels:
206+
Key: team
207+
Value: frontend
208+
`)
210209
}
211210

212211
func TestAppDestroy(t *testing.T) {
@@ -237,7 +236,7 @@ func TestAppDestroy(t *testing.T) {
237236

238237
err = cmdr.AppDestroy("lorem-ipsum", "lorem-ipsum")
239238
assert.NoError(t, err)
240-
assert.Equal(t, testutil.StripProgress(b.String()), `Destroying lorem-ipsum...
239+
assert.Equal(t, b.String(), `Destroying lorem-ipsum...
241240
done in 0s
242241
`, "output")
243242
}
@@ -268,7 +267,7 @@ func TestAppTransfer(t *testing.T) {
268267

269268
err = cmdr.AppTransfer("lorem-ipsum", "test-user")
270269
assert.NoError(t, err)
271-
assert.Equal(t, testutil.StripProgress(b.String()), `Transferring lorem-ipsum to test-user... done
270+
assert.Equal(t, b.String(), `Transferring lorem-ipsum to test-user... done
272271
`, "output")
273272
}
274273

internal/commands/auth.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
// Login to a Drycc controller.
1010
func (d *DryccCmd) Login(controller string, sslVerify bool, username, password string) error {
1111
c, err := drycc.New(sslVerify, controller, "")
12-
1312
if err != nil {
1413
return err
1514
}
@@ -52,7 +51,6 @@ func (d *DryccCmd) Logout() error {
5251
// more about the user.
5352
func (d *DryccCmd) Whoami(all bool) error {
5453
s, err := settings.Load(d.ConfigFile)
55-
5654
if err != nil {
5755
return err
5856
}

internal/commands/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestLogin(t *testing.T) {
4343
w.WriteHeader(http.StatusOK)
4444
w.Write(nil)
4545
} else {
46-
w.Write([]byte(fmt.Sprintf(`{"key": "%s"}`, keyFixture)))
46+
fmt.Fprintf(w, `{"key": "%s"}`, keyFixture)
4747
}
4848
})
4949

internal/commands/autodeploy.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package commands
33
import (
44
"github.com/drycc/controller-sdk-go/api"
55
"github.com/drycc/controller-sdk-go/appsettings"
6-
"github.com/drycc/workflow-cli/internal/utils"
6+
"github.com/drycc/workflow-cli/internal/loader"
77
)
88

99
// AutodeployInfo provides information about the status of app autodeploy.
1010
func (d *DryccCmd) AutodeployInfo(appID string) error {
11-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
12-
11+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
1312
if err != nil {
1413
return err
1514
}
@@ -29,8 +28,7 @@ func (d *DryccCmd) AutodeployInfo(appID string) error {
2928

3029
// AutodeployEnable enables an app when deploy failed
3130
func (d *DryccCmd) AutodeployEnable(appID string) error {
32-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
33-
31+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
3432
if err != nil {
3533
return err
3634
}
@@ -53,8 +51,7 @@ func (d *DryccCmd) AutodeployEnable(appID string) error {
5351

5452
// AutodeployDisable disables an app when deploy failed
5553
func (d *DryccCmd) AutodeployDisable(appID string) error {
56-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
57-
54+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
5855
if err != nil {
5956
return err
6057
}

internal/commands/autodeploy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestAutodeployEnable(t *testing.T) {
9292

9393
err = cmdr.AutodeployEnable("lothlorien")
9494
assert.NoError(t, err)
95-
assert.Equal(t, testutil.StripProgress(b.String()), "Enabling autodeploy for lothlorien... done\n", "output")
95+
testutil.AssertOutput(t, testutil.StripProgress(b.String()), "Enabling autodeploy for lothlorien... done\n")
9696
}
9797

9898
func TestAutodeployDisable(t *testing.T) {
@@ -114,5 +114,5 @@ func TestAutodeployDisable(t *testing.T) {
114114

115115
err = cmdr.AutodeployDisable("bree")
116116
assert.NoError(t, err)
117-
assert.Equal(t, testutil.StripProgress(b.String()), "Disabling autodeploy for bree... done\n", "output")
117+
testutil.AssertOutput(t, testutil.StripProgress(b.String()), "Disabling autodeploy for bree... done\n")
118118
}

internal/commands/autorollback.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ package commands
33
import (
44
"github.com/drycc/controller-sdk-go/api"
55
"github.com/drycc/controller-sdk-go/appsettings"
6-
"github.com/drycc/workflow-cli/internal/utils"
6+
"github.com/drycc/workflow-cli/internal/loader"
77
)
88

99
// AutorollbackInfo provides information about the status of app autorollback.
1010
func (d *DryccCmd) AutorollbackInfo(appID string) error {
11-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
12-
11+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
1312
if err != nil {
1413
return err
1514
}
@@ -29,8 +28,7 @@ func (d *DryccCmd) AutorollbackInfo(appID string) error {
2928

3029
// AutorollbackEnable enables an app when deploy failed
3130
func (d *DryccCmd) AutorollbackEnable(appID string) error {
32-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
33-
31+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
3432
if err != nil {
3533
return err
3634
}
@@ -53,8 +51,7 @@ func (d *DryccCmd) AutorollbackEnable(appID string) error {
5351

5452
// AutorollbackDisable disables an app when deploy failed
5553
func (d *DryccCmd) AutorollbackDisable(appID string) error {
56-
appID, s, err := utils.LoadAppSettings(d.ConfigFile, appID)
57-
54+
appID, s, err := loader.LoadAppSettings(d.ConfigFile, appID)
5855
if err != nil {
5956
return err
6057
}

0 commit comments

Comments
 (0)